// JavaScript Document

function getVideoPlayer( src, w, h, configSrc, autoPlay, givenRate )
{
	var rel = src;
	
	if ( rel.lastIndexOf("/") >= 0 )
		rel = rel.substr(0, rel.lastIndexOf("/") + 1);
	else
		rel = "./";

	var cookieName = "autoplayFirst";
	var cookieExpiryDays = 90;

	if ( autoPlay == "first" )
	{
		if( getVideoCookie(cookieName) == "" )
		{
			setVideoCookie(cookieName, "valid", cookieExpiryDays );
			autoPlay = "no";
		}
		else
			autoPlay = "no";
	}
	else if ( autoPlay == false || autoPlay == "false" )
		autoPlay = "no";
	else
		autoPlay = "no";
	
	var FlashVars = "w=" + w + "&h=" + h + "&xmlSrc=" + configSrc + "&rel=" + rel + "&autoplay=" + autoPlay + ( ( givenRate !== undefined && givenRate != "" ) ? "&givenRate=" + givenRate : "" );

	// add to the height of the video the height of the controls skin and player header
	//h += 45 + 40;
	//h += 45 + 0;
	h += 37 + 0;

	return AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','bgcolor','#666666','width',w,'height',h,'src',src,'quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie',src.substr(0, src.lastIndexOf("." ) ),'FlashVars',FlashVars);
}

function insertVideoPlayer( src, w, h, configSrc, autoPlay, givenRate )
{
	document.write( getVideoPlayer( src, w, h, configSrc, autoPlay, givenRate ) );
}


function getVideoCookie(c_name)
{
	if (document.cookie.length>0)
  	{
 		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start != -1)
    	{ 
    		c_start=c_start + c_name.length+1 ;
    		c_end=document.cookie.indexOf(";",c_start);
    		if (c_end == -1) 
				c_end = document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
    	} 
  	}
	return ""
}

function setVideoCookie(c_name,value,expiredays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name + "=" + escape(value) + ( (expiredays==null) ? "" : "; expires=" + exdate.toGMTString());
}
