// JavaScript Document//Global initialization function
window.onload = init;

function init(){
	if(typeof(loadPageMedia) == "function"){
		loadPageMedia();
	}
}

function objFlash(obj){
	var flashVersion = '7,0,0,0';
	if(obj.flashversion){flashVersion = obj.flashversion;}
	this.attrObject = {
		classid : "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
		, codebase : "https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + flashVersion
		, width : "150"
		, height : "150"
	}
	this.attrEmbed = {
		src : ""
		, width : "100%"
		, height : "780"
		, quality : "high"
		, bgcolor : "#FFFFFF"
		, type : "application/x-shockwave-flash"
		, pluginspage : "http://www.macromedia.com/go/getflashplayer"
		, autoplay : "true"
		, allowScriptAccess : "sameDomain"
	}
	this.params = {
		movie : ""
		, quality : this.attrEmbed.quality
		, bgcolor : this.attrEmbed.bgcolor
		, target : "quicktimeplayer"
		, autoplay : "true"
		, vspace : "0"
		, hspace : "0"
		, align : "top"
		, allowScriptAccess : "sameDomain"
	}
	setProperties(this, obj);
}

function objQT(obj){
	this.attrObject = {
		id : ""
		, classid : "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
		, codebase : "https://www.apple.com/qtactivex/qtplugin.cab"
		, width : "880"
		, height : "680"
	}

	this.attrEmbed = {
		target : "quicktimeplayer"
		, width : "100%"
		, height : "780"
		, pluginspage :"http://www.apple.com/quicktime/"
		, autoplay : "true"
		, src : ""
		, loop : "false"
		, controller : "true"
		, playeveryframe : "false"
		, cache : "false"
		, kioskmode : "true"
		, targetcache : "false"
		, align : "top"
		, vspace : "0"
		, hspace : "0"
	}
	this.params = {
		target : "quicktimeplayer"
		, src : ""
		, autoplay : "true"
		, vspace : "0"
		, hspace : "0"
		, align : "top"
		, loop : "false"
		, controller : "true"
		, cache : "false"
		, kioskmode : "true"
		, playeveryframe : "false"
		, starttime : "00:00:00:00"
	}
	setProperties(this, obj);
}
function setProperties(obj, props){
	//Create an array to store matched items.
	var matchedItems = new Array();
	for(i in obj){
		//loop through root object propertis (attrObject, params, attrEmbed)
		//Now we need to loop through each of the properties inside each of the above "objects"
		for(x in obj[i]){
			//Now we're looking through attrObject, for example. x = classid, codebase, then pluginspage
			//Now we need to loop through each of the passed properties in obj
			for(y in props){
				if(y == x){
					//The user passed in a property that matches a property in the current object "group"
					//Set the object property to the passed property and break out
					obj[i][x] = props[y];
					//Add the matched item to the array
					matchedItems[x] = x;
					break;
				}
			}
		}
	}
	//Now that the root loops are finished, add any passed values that were not part of the three groups
	//into the params
	for(z in props){
		if(indexInArray(matchedItems, z) == -1){
			//We have a value that hasn't been matched to a group, add it to the params
			obj.params[z] = props[z];
		}
	}

	return obj;
	
}

//------------------------------------------------------------------------------------
// AUTHOR: Danilo Celic
// FUNCTION(S): indexInArray
//
// LICENSE: NONE
//
// DESCRIPTION: Used to check an array for a specific value.
//
// ARGUMENTS:
//		theArray - ARRAY: Any one dimensional array.
//		theValue - STRING: The value to check for inside the array.
//
// RETURNS:
//		NUMBER - The index in the array if found, -1 if not found.
//------------------------------------------------------------------------------------
function indexInArray(theArray, theValue){
	var arLength = theArray.length;
	for(var i=0; i<arLength; i++){
		if (theArray[i] == theValue){
			return i;
		}
	}
	return -1;
}

function loadMedia(elementID, objMedia){
	var str ="";
	
	//Build the opening object tag
	str += '<object';
	for(attr in objMedia.attrObject){
		str += ' ' + attr + '="'+ objMedia.attrObject[attr] + '"';
	}
	str += '>';

	//Add the params
	for(attr in objMedia.params){
		str += '<param name="' + attr + '" value="' + objMedia.params[attr] + '" />';
	}

	//Add the embed tag
	str += '<embed';
	for(attr in objMedia.attrEmbed){
		str += ' ' + attr + '="'+ objMedia.attrEmbed[attr] + '"';
	}
	str += ' /></object>';
	var divObj = document.getElementById(elementID);
	if(divObj){
		divObj.innerHTML = str;
	}
	else {
		document.write(str);
	}
}