// used for flv script in elements/widgets/flv_list

var createFlvLib = function(id, flv_dimensions, flvfile, classhide, autoplay, title) {	
	//see if dimensions not set

	if(!flv_dimensions){
		alert("There is no flv dimensions set for ID: " + id);
		return;
	}
	var divID = $(id);
	var vidLib = $('videolib');

	vidLib.innerHTML = '';

	var attributes = {'id':id}
	var newElement = new Element('div', attributes ).update('');
	Element.insert(vidLib,{'bottom':newElement});
	if (swfobject.hasFlashPlayerVersion("8.0.0")) {
		var flashvars = {};
		var re = '\/local\/';
		flashvars.path =  "../" + flvfile.replace(re,''); // get the relative url
		flashvars.playerSkin = siteroot + "local/flash/SteelExternalAll.swf";
		//flashvars.autoPlay = (autoplay.toString().toLowerCase() == "true" ? true : false);
		flashvars.autoplay = (autoplay.toString().toLowerCase() == "true" ? "true" : "false");
		flv_playerSplit = flv_dimensions.split("x"); // this will split 475x262 
		width = flv_playerSplit[0];
		height = flv_playerSplit[1];			
		
		var params = {wmode: "transparent"}
		//doing this instead of usig == first since this code is used in both video gallery and regular pages
		if (classhide != 'hiddenvid')
			attributes = {"class":"flv videoitem"};
		else
			attributes = {"class":"flv videoitem","style":"display:none;"};
		var swffile = siteroot + "local/flash/BridgePointPlayer_" + flv_dimensions + ".swf";
		swfobject.embedSWF(swffile, id, width, height, "8.0.0",false, flashvars, params, attributes);
		
		//create description and title elements
		attributes = {'id':id+'desc','class':'videoitem'};
		newElement = new Element('div', attributes ).update('<h2>' + title + '</h2><div>' + $('tmptext'+id).innerHTML + '</div>');
		Element.insert(vidLib,{'bottom':newElement});
	}


}


var createFlv = function(id, flv_dimensions, flvfile, classhide, autoplay) {	

	//see if dimensions not set
	if(!flv_dimensions){
		alert("There is no flv dimensions set for ID: " + id);
		return;
	}
	
	if ($(id).tagName.toLowerCase() != 'div') 
		return;


	if ($(id)){
		if (swfobject.hasFlashPlayerVersion("8.0.0")) {
			var flashvars = {};
			var re = '\/local\/';
			flashvars.path =  "../" + flvfile.replace(re,''); // get the relative url
			flashvars.playerSkin = siteroot + "local/flash/SteelExternalAll.swf";
			//flashvars.autoPlay = (autoplay.toString().toLowerCase() == "true" ? true : false);
			flashvars.autoplay = (autoplay.toString().toLowerCase() == "true" ? "true" : "false");
			flv_playerSplit = flv_dimensions.split("x"); // this will split 475x262 
			width = flv_playerSplit[0];
			height = flv_playerSplit[1];			
			
			var params = {wmode: "transparent"}
			//doing this instead of usig == first since this code is used in both video gallery and regular pages
			if (classhide != 'hiddenvid')
				var attributes = {"class":"flv videoitem"};
			else
				var attributes = {"class":"flv videoitem","style":"display:none;"};
			var swffile = siteroot + "local/flash/BridgePointPlayer_" + flv_dimensions + ".swf";
			swfobject.embedSWF(swffile, id, width, height, "8.0.0",false, flashvars, params, attributes);
		}
		else 
		{
			var getflash = confirm ("Your browser currently does not support Flash Player 8.0, Click on OK if you wish to navigate away from this site and install this plug-in or click on Cancel if you wish to proceed without the plug-in. By clicking on Cancel the site may not function correctly.");
			if (getflash) window.open('http://www.adobe.com/products/flashplayer/');
		}
	} 
	else 
	{
		alert("Mismatched ID: " + id);
	}
};

var createVidMenu = function() {
	var vidlib = $$('.maincontent')[0];
	vidlib.removeClassName('nocallouts');
	var attributes = {'class':'calloutmenu vidmenu'};
	var menuWidget = new Element('div', attributes ).update('<h2>Videos</h2><div class="widget vidlibwidget"><div id="vidmenucontent"/></div>');
	Element.insert(vidlib,{'after': menuWidget});
};

var createVidMenuItems = function(id,title,thumb,date,length,dimensions,flashfile) {
	
	var vidmenu = $('vidmenucontent');
	var currVid = id;
	var anchorTag = '<a href="javascript:void(0)" onclick="hideVideos();createFlvLib(\'' + id + '\',\'' + dimensions + '\',\'' + flashfile + '\',\'\',true,\''+ title +'\');$(\'' + currVid + '\').show(); $(\''+ currVid + 'desc\').show();">';
	var menuItem = '<div class="vidmenuitem"><table><tr><td colspan=2>' + anchorTag + '<img src="' + thumb + '" /></a></td></tr><tr><td>' + anchorTag + title + '</a><br />' + date + '</td><td>' + length + '</td></tr></table></div>';
	vidmenu.innerHTML = vidmenu.innerHTML + menuItem;
}

var hideVideos = function() {
	var vidItems = $$('.videoitem');
	vidItems.each(function(arrItem, index){arrItem.hide();});
}