var isInlineVideo = !(window.isInlineAd === undefined) && isInlineAd;

if (isInlineVideo){
var headID = document.getElementsByTagName("head")[0];         
var cssNode = document.createElement('style');
cssNode.type = 'text/css';
cssNode.value = '.flashRequired {background-color:white;padding:5px 5px 5px 5px;font-size:75%;border:solid 1px #000000;}';
headID.appendChild(cssNode);
}

function detectMacXFF2(){
var userAgent=navigator.userAgent.toLowerCase();
if(/firefox[\/\s](\d+\.\d+)/.test(userAgent)){
var ffversion=new Number(RegExp.$1);
if(ffversion<3&&userAgent.indexOf('mac')!=-1){
return true;
}else if(ffversion<3&&userAgent.indexOf('linux')!=-1){
return true;
}}}

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;
		}
		if (name == "voliset") {
			voliset = value;
		}
		if (name == "trakset") {
			trakset = value;
		}
	}
}
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" : "");
}
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;
	}
}
var SearchVideoCookie = "";
function DoVideo(state) 
{
	if (state == "1") 
	{
		checkVersion();
		setUpVideo();
		additionalSetup();
		
	} 
	else 
	{
		tearDownVideo();
	}
	setVideoCookie();
}

function setUpVideo()
{
		hdefla = "none";
		if (isInlineVideo)
		{
			setInlineVideo();
		}
		scrbar = "hidden";
		litbox = "block";
		try {
			writeShow();
		}
		catch (err) 
		{
		}	
}

function additionalSetup()
{
		if (!isInlineVideo)
		{
			setScrollBar();
			hideOtherFlash();
			setLightBox();
		}
}

function tearDownVideo(flashDiv)
{
		var flashDiv = document.getElementById("flashcontent");
		hdefla = "block";
		scrbar = "scroll";
		litbox = "none";
		
		if (flashDiv.firstChild) 
		{
			flashDiv.removeChild(flashDiv.firstChild);
		}
		if (isInlineVideo)
		{
			removeInlineVideo();
		}
		else
		{			
			setLightBox();
			setScrollBar();
		}
}

function checkVersion()
{
	if (!hasReqestedVersion) 
	{
		var alternateContent = "<div class=\"flashRequired\"><a href=\"javascript:DoVideo(0);\" />close</a><br><br>" + "The video feature requires Adobe Flash Player version 8.0.0 or later. You must upgrade your Flash Player to see the requested video. " + "Please <a target=\"_Page\" href=\"http://www.adobe.com/go/getflash\"/> click here</a> to get the latest Flash player from Adobe.";
		if (isIE) {
			alternateContent += "<br><br>When the update is complete <a href=\"javascript:DoVideo(1);\" />click here</a> to show the video.</div>";
		}
		var flashDiv = document.getElementById("flashcontent");
		if (flashDiv)
		{
			flashDiv.innerHTML = alternateContent;
		}
	}
}

function setVideoCookie()
{
	getSearchVideoCookie = readSearchVideoCookie("atvideo");
	if (trakset.length > 0) 
	{
		SearchVideoCookie = volimute + "|" + voliset + "|" + trakset;
	} 
	else if (getSearchVideoCookie != null && getSearchVideoCookie != "null" && getSearchVideoCookie.length > 0) 
	{
		SearchVideoCookie = getSearchVideoCookie;
	}
}

function setScrollBar()
{		
		var bodyelem = document.getElementsByTagName("body");
		for (var i = 0; i < bodyelem.length; ++i) 
		{
		if(document.all)
			{
				bodyelem[i].style.overflow = scrbar;
			}
			else
			{
				bodyelem[i].style.overflowX = scrbar;
				bodyelem[i].style.overflowY = scrbar;
			}
			bodyelem[i].style.overflowX = "auto";
		}
}

function hideOtherFlash()
{	
	var flashId = document.all ? 'object' : 'embed';
	var flashObjects = document.getElementsByTagName(flashId);
	var flashAttrId = document.all ? 'id' : 'name';

	for (var i = 0; i < flashObjects.length; i++) 
	{			
		var flashAttr = flashObjects[i].getAttribute(flashAttrId);
		if (flashAttr != null && flashAttr.indexOf("slideshow") == -1) 
		{
			flashObjects[i].style.display = hdefla;
		}		
	}
}

function setLightBox()
{
	var light = document.getElementById("light");
	if (light) 
	{
		light.style.display = litbox;
	}
	var fade = document.getElementById("fade");
	if (fade) 
	{var d=detectMacXFF2();
if(d){fade.style.backgroundImage="url(http://www.autotrader.co.uk/SEARCH/images/Generic/opaque_grey.png)";
fade.style.backgroundRepeat="repeat";
}else{fade.style.backgroundColor="black";
fade.style.MozOpacity=.60;
fade.style.opacity=.60;
fade.style.filter="alpha(opacity=60)";
}
		fade.style.display = litbox;
	}
}