var DayPortHeaderLinks = new Object();

DayPortHeaderLinks.embed = function(container,rootCategory,categoryID,metaDataCB,domain,imgDomain,width)
{
	this.version = Math.floor(Math.random()*999999);
	
	this.id = Math.floor(Math.random()*999999);
	
	this.imageDomain = imgDomain;
	
	this.tabObject = "http://"+this.imageDomain+"/dayportcore/dpm/DayPortTYPE3Tabs.swf";
	
	this.configSettings = new Object();
	
	
	
	this.configSettings.type="1";
	this.configSettings.navigationLayout = "side"; //side or under
	this.configSettings.navigationView = "list"; //thumbnail or list
	
	this.configSettings.backgroundColor="333333";
	this.configSettings.buttonBackColor="000000";
	this.configSettings.buttonBackHoverColor="666666";
	this.configSettings.graphicHexColor="ffffff";
	this.configSettings.textHexColor="ffffff";
	this.configSettings.backgroundGradientAlpha="50";
	this.configSettings.autoPlay="false";
	this.configSettings.autoHideMenu="false";
	this.configSettings.continuousPlay="true";
	this.configSettings.thumbnailView="true";
	
	this.configSettings.fileTypeID="2";
	this.configSettings.liveStreamFileTypeID = "3";
	this.configSettings.defaultPreviewImage="http://img.dayport.com/img/greenThumbnail.jpg";
	this.configSettings.limit="20";

	this.configSettings.videoWidth=width;
	this.configSettings.videoHeight="210";
	this.configSettings.rootCategory=rootCategory;		
	this.configSettings.categoryID=categoryID;
	this.configSettings.domain=domain;
	this.configSettings.limit = 10;
	
	this.callBack = metaDataCB;
	
	this.defaultVideoWidth = width;
	
	if (navigator.appName.indexOf("Microsoft") != -1) { this.isIE = true; }else{ this.isIE = false; }
	
	this.generateTabObject(container);
}

DayPortHeaderLinks.getSettings = function()
{
	return this.configSettings;
};


DayPortHeaderLinks.registerEvents = function(registerObject)
{
	this.objectsRegistered++;
	
	if(registerObject == "tabControls")
	{
		try{ this.tabControlObject.registerEventListener("DisplayCategory",'DayPortHeaderLinks.DisplayCategoryTB');}catch(e){alert("not working for "+this.tabControlObject);}
	}
	
};


DayPortHeaderLinks.DisplayCategoryTB = function(eventObj)
{
	this.SWFFormFixAuto();
	this.callBack(eventObj);
};



DayPortHeaderLinks.generateTabObject = function(container)
{
	
	var settings_string = new String();
	var id = 'tvPlayerTabControlNavigationHeaderLink_'+this.id;
	
	if(this.isIE || DayPortUtils.system.browser == "Safari")
	{
		var objectTag = id;
		var embedTag = "mx_" + id + "_mz";
	}else{
	
		var objectTag = "mx_" + id + "_mz";
		var embedTag = id; 	
	}
	
	var tabWidth = this.defaultVideoWidth;
	
	var settings_string = new String();
	settings_string += "&onFlashLoad=registerEvents";
	settings_string += '&instanceID=DayPortHeaderLinks';
	settings_string += "&objectWidth="+tabWidth;
	
	settings_string = settings_string.slice(1);

  	var objectStr = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="'+objectTag+'" width="'+tabWidth+'" height="19" align="left">\
                     <param name="allowScriptAccess" value="always" />\
                     <param name="movie" value="' + this.tabObject + '?v='+this.version+'" />\
                     <param name="quality" value="high" />\
                     <param name="wmode" value="transparent" />\
                     <param name="FlashVars" value="'+settings_string+'">\
                     <embed src="' + this.tabObject + '?v='+this.version+'" quality="high" wmode="transparent" width="'+tabWidth+'" height="19" swLiveConnect=true id="'+embedTag+'" align="left" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="'+settings_string+'" />\
                   </object>';
	
	document.getElementById(container).innerHTML = objectStr;
	
	this.tabControlObject = document.getElementById(id); 
};

DayPortHeaderLinks.SWFFormFixAuto = function(){
	//fix for the player in a form tag
	var objects = document.getElementsByTagName("object");
	if(objects.length == 0) return true;
	
	for(i=0;i<objects.length;i++)
	{
		//alert(objects[i].classid.toUpperCase());
		// here's all the objects on the page, now lets find the flash objects
		if(objects[i].classid.toUpperCase() == "CLSID:D27CDB6E-AE6D-11CF-96B8-444553540000"){
			// this is a flash movie, apply the fix
			//alert(objects[i]);
			window[objects[i].id] = objects[i];
			//alert(objects[i]);
		}
	}
	var out = '';
	return true;
}