
var searchVideoCookie = "";
var hasReqestedVersion = true;
	try {
		hasReqestedVersion = DetectFlashVer(8, 8, 8);
	}
	catch (err) {
	}
	
volimute = "";
voliset = "";
trakset = "";
function createVar(name, value) 
{
	if (value != "undefined") {
		if (name == "volimute") {
			volimute = value;
		}
		else if (name == "voliset") {
			voliset = value;
		}
		else if (name == "trakset") {
			trakset = value;
		}
	}
}

function playAdvertSlideshow() 
{
	callPlayerOverlay();
	checkVersion('playAdvertSlideshow');
	readVideoCookie();
	slideshowContent()
}

function slideshowContent()
{	
	var sshow = new SWFObject("http://pictures.autotrader.co.uk/video/ss/videoshell_v1.swf", "swf_slideshow" + Math.floor(Math.random() * 100), "350", "292", "8.0.0", "#ffffff");
	sshow.addParam("wmode", "transparent");
	sshow.addParam("quality", "high");
	sshow.addParam("loop", "false");
	sshow.addParam("menu", "false");
	sshow.addParam("AllowScriptAccess", "always");
	sshow.addVariable("id", $("video.advertId").value);
	sshow.addVariable("logo", "y");
	sshow.addVariable("disableBranding", $("video.disableBannersYN").value);
	sshow.addVariable("channel", $("video.channel").value);
	sshow.addVariable("txt", encodeURIComponent($("video.text").value));
	sshow.addVariable("url", encodeURIComponent($("video.imageserverurl").value));
	sshow.addVariable("images", $("video.images").value);
	sshow.addVariable("cookie", searchVideoCookie);
	
	sshow.write("flashcontent");
}

function playAdvertVideo() 
{
	callPlayerOverlay();
	checkVersion('playAdvertVideo');
	readVideoCookie();
	videoContent();
}

function videoContent()
{
	var sshow=new SWFObject("http://www.autotrader.co.uk/video/vp/video_v2.swf","swf_video"+Math.floor(Math.random()*100),"350","292","8.0.0","#ffffff");
	sshow.addParam("wmode", "transparent");
	sshow.addParam("quality", "high");
	sshow.addParam("loop", "false");
	sshow.addParam("menu", "false");
	sshow.addParam("AllowScriptAccess", "always");
	sshow.addParam("allowFullScreen", "true");
	
	sshow.addVariable("url", $("video.baseUrl").value);
	sshow.addVariable("video", $("video.filename").value);
	sshow.addVariable("disable", $("video.disableAudio").value);
	sshow.addVariable("channel", $("video.channel").value);
	sshow.addVariable("disableBranding", $("video.disableBannersYN").value);
	
	sshow.addVariable("autoplay", 'y');
	sshow.addVariable("logo", 'y');
	sshow.addVariable("cookie", searchVideoCookie);
	sshow.addVariable("location", 'live');
		
	sshow.write("flashcontent");
}

var otherPopupFlashIds = new Array('topBannerContainerPopup');

function DoVideo(state)
{
	if (state == '1') 
	{
		playAdvertSlideshow();
	}
	else
	{
		closeAtOverlay(otherPopupFlashIds);
		amendVideoCookie();
	}
}

function callPlayerOverlay()
{
	callOverlay('<div id="flashcontent"></div>', 350, 292, otherPopupFlashIds);
}

function checkVersion(playFunctionName)
{
	if (!hasReqestedVersion) 
	{
		var alternateContent = '<div class="flashRequired"><a href="javascript:DoVideo(0);" name="&lpos=FlashVideoLightBox&lid=NoFlashClose">Close</a><br><br>'
									+ 'The video feature requires Adobe Flash Player version 8.0.0 or higher. You must upgrade your Flash Player to see the requested video. '
									+ 'Please <a target="_blank" href="http://www.adobe.com/go/getflash" name="&lpos=FlashVideoLightBox&lid=GoGetFlash">click here to get the latest Flash player from Adobe</a>.';
		if(isIE){
			alternateContent += '<br><br>When the update is complete <a href="javascript:' + playFunctionName + '();" name="&lpos=FlashVideoLightBox&lid=PlayFlashVideo">click here to show the video</a>.</div>';
		}
		
		var flashDiv = document.getElementById("flashcontent");
		if (flashDiv)
		{
			flashDiv.innerHTML = alternateContent;
		}
	}
}

function readVideoCookie()
{
	var atVideoCookie = readSearchVideoCookie("atvideo");
	
	if (atVideoCookie != null && atVideoCookie != "null" && atVideoCookie.length > 0) 
	{
		searchVideoCookie = atVideoCookie;
	}
}
function amendVideoCookie()
{
	searchVideoCookie = volimute + "|" + voliset + "|" + trakset;
}

function readSearchVideoCookie(check_name) {
	var a_all_cookies = document.cookie.split(";");
	var a_temp_cookie = "";
	var cookie_name = "";
	var cookie_value = "";
	var b_cookie_found = false;
	for (i = 0; i < a_all_cookies.length; i++) {
		a_temp_cookie = a_all_cookies[i].split("=");
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, "");
		if (cookie_name == check_name) {
			b_cookie_found = true;
			if (a_temp_cookie.length > 1) {
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ""));
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = "";
	}
	if (!b_cookie_found) {
		return null;
	}
}

function createSearchVideoCookie(name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + (expires));
	document.cookie = name + "=" + escape(value) + ((expires) ? ";expires=" + expires_date.toGMTString() : "") + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ((secure) ? ";secure" : "");
}
