mapLoadingMsg = null;
if(!document.getElementById)
{
	window.location="/browseradvice/";
}
$(document).ready(function(){
	$("div#banner").randombg({
		directory: "/images/Banner/banner/banner", //directory to image folder
		howmany: 4 //how many images are in this folder
	});
	// Input
	$("ul.gallery li:nth-child(3n)").addClass("last");
	$("ul.generalForm li input").focus(function(){
		$(this).parent().css("background","#668FC7");
		$(this).parent().css("color","#ffffff");
	});
	$("ul.generalForm li input").blur(function(){
		$(this).parent().css("background","none");
		$(this).parent().css("color","#656565");
	});
	// Select
	$("ul.generalForm li select").focus(function(){
		$(this).parent().css("background","#668FC7");
		$(this).parent().css("color","#ffffff");
	});
	$("ul.generalForm li select").blur(function(){
		$(this).parent().css("background","none");
		$(this).parent().css("color","#656565");
	});
	// Textarea
	$("ul.generalForm li textarea").focus(function(){
		$(this).parent().css("background","#668FC7");
		$(this).parent().css("color","#ffffff");
	});
	$("ul.generalForm li textarea").blur(function(){
		$(this).parent().css("background","none");
		$(this).parent().css("color","#656565");
	});
});
function init()
{
	initRolloverImages();
	initRolloverDivs();
	initClickableDivs();
	if(mapLoadingMsg != null )
	{
		mapLoaded = true;
		mapLoadingMsg.style.display="none";
		map.style.display="inline";
	}
}
function HighMap(n)
{
	//alert("test");
	ocImg = document.getElementById("DSOmap");
	ocImg.style.cursor="help";
	ocImg.src = "/images/library/DSO"+n+".gif";
	/*if(ocImg.filters)
	{
		ocImg.filters[0].apply()
		ocImg.style.visibility="visible"
		ocImg.filters[0].play()
	}*/
}
		
function LowMap()
{
	ocImg = document.getElementById("DSOmap");
	ocImg.style.cursor="default";
	ocImg.src="/images/library/DSOMap.gif";
	/*if(ocImg.filters)
	{
		ocImg.filters[0].apply()
		ocImg.style.visibility="visible"
		ocImg.filters[0].play()
	}*/
}
				
function initRolloverImages()
{
	var i;
	rolloverImgTags=document.getElementsByTagName("img");
	for(i=0;i<rolloverImgTags.length;i++)
	{
		preLoadImgs=new Array();
		if( rolloverImgTags[i].className=="rollover")
		{
			src = new String(rolloverImgTags[i].src);
			rolloverImgTags[i].setAttribute("outSrc" , src);
			rolloverImgTags[i].setAttribute("overSrc" , src.replace(/\.gif$/,"")+"_ov.gif");
			preLoadImgs[i] = new Image();
			preLoadImgs[i].src=rolloverImgTags[i].overSrc;
			rolloverImgTags[i].onmouseover = function()
			{
				this.src = this.getAttribute("overSrc");
			}
			rolloverImgTags[i].onmouseout = function()
			{
				this.src = this.getAttribute("outSrc");
			}
		}
	}
}

function initRolloverDivs()
{
	var i;
	rolloverDivTags=document.getElementsByTagName("li");
	for(i=0 ; i<rolloverDivTags.length ; i++)
	{
		if( rolloverDivTags[i].className=="prod_cat" || rolloverDivTags[i].className=="prod_sub_cat")
		{
			rolloverDivTags[i].onmouseover = function()
			{
				this.style.backgroundPosition = 'bottom left';
			}
			rolloverDivTags[i].onmouseout = function()
			{
				this.style.backgroundPosition = 'top left';
			}
		}
	}
}

function initClickableDivs()
{
	var i;
	divTags = document.getElementsByTagName("div");
	for(i=0;i<divTags.length;i++)
	{
		if(divTags[i].className=="relatedProduct" || divTags[i].className=="prodResultBlock" || divTags[i].className=="productcat")
		{
			href = getChildAnchorHref( divTags[i] );
			target = getChildAnchorTarget( divTags[i] );
			divTags[i].setAttribute("href" , href);
			divTags[i].setAttribute("target" , target);
			divTags[i].onclick = function()
			{
				if(this.getAttribute("target")=="blank")
				{
					window.open(this.getAttribute("href"),"blank");
				}
				else
				{
					window.location = this.getAttribute("href");
				}
			}
			if(divTags[i].className=="relatedProduct")
			{
				divTags[i].onmouseover = function()
				{
					this.style.backgroundColor = "#D9E1EF";
				}
				divTags[i].onmouseout = function()
				{
					this.style.backgroundColor = "#ffffff";
				}
			}
		}
	}
}

function getChildAnchorHref(elm)
{
	var i;
	nodes = new Array();
	for(i=0;i<elm.childNodes.length;i++)
	{
		if(elm.childNodes[i].nodeName=="A")
		{
			return elm.childNodes[i].href;
		}
	}
	return false;
}

function getChildAnchorTarget(elm)
{
	var i;
	nodes = new Array();
	for(i=0;i<elm.childNodes.length;i++)
	{
		if(elm.childNodes[i].nodeName=="A")
		{
			return elm.childNodes[i].target;
		}
	}
	return false;
}

function enlargeProduct(id)
{
	url = "/enlarge/?prod_id="+id;
	popUp(460,470,url,"enlargedProduct");
}

function popUp(w,h,url,name)
{
	x = (screen.width/2)-(w/2);
	y = (screen.height/2)-(h/2);
	features = "width=" + w + ",height=" + h + ",left=" + x + ",top=" + y;
	window.open(url,name,features);
}

function popupLink(url)
{
	window.opener.window.location = url;
	window.close();
}

function ddPopUp()
{
	popUp(304,250,"/directdebit/","dd_PopUp");
}

function accountNumberInfo()
{
	popUp(304,250,"/accountnumber/","acountNumberPopup");
}

function accountNumberConfirm()
{
	accountNumberConfirmShown = true;
	msg = "You haven't entered your account number.\n";
	msg+= "It can be found on one of the following and is 9 digits long:\n\n";
	msg+= " * Boxclever Payment Card\n";
	msg+= " * Credit Transfer/Giro Payment Slips\n";
	msg+= " * Direct Debit or Standing Order Reference Number\n";
	msg+= " * Letter from us\n\n";
	msg+= "It would assist us greatly if you are able to supply this number.\n";
	msg+= "Click OK to submit this form or Cancel to enter your account number";
	if(confirm(msg))
	{
		return true;
	}
	else
	{
		document.forms[0].account_number.focus()
		return false;
	}
}

function clearDefault(el)
{
  	if (el.defaultValue==el.value)
  	{
  		el.value = "";
  	}
}

function pop_compare(pid,cid)
{
	var compare;
	if(pid > 0)
	{
		var href="/compare.php?product="+pid;
		if(cid != null)
		{
			if(cid > 0)
			{
				compare = "&compare="+cid;
			}
			else
			if(cid != null && cid.constructor == Array)
			{
				for(var i in cid)
				{
					compare+= "&compare[]="+cid[i];
				}
			}
			href+= compare;
		}
	}
	else
	{
		return false;
	}
	href+= "&keepThis=true&TB_iframe=true&height=600&width=850";
	tb_show("",href,null);
	return false;
}

function initFaq()
{
	/*
	* TOPICS
	*/
	// Hide all Topics
	$("div#questions dl").css("display","none");
	// Each topic-toggle anchor...
	$("div#topics ul li a").each(function(){
		// Remove page-based anchors (fallback scrolling)
		$(this).attr("href","#");
		// Click listener
		$(this).click(function(){
			// Hide the intro text
			$("div#questions p#intro").css("display","none");
			// Hide all other topics
			$("div#questions dl").each(function(){
				$(this).css("display","none");
			});
			// Show this topic
			$("div#questions dl#topic_"+$(this).attr("id")).css("display","block");
			return false;
		});
	});
	// Show intro text
	$("div#questions p#intro").css("display","block");
	/*
	* QUESTIONS
	*/
	// Click listeners
	$('div#questions dl dt').click(function(){
		$(this).next('dd').slideToggle('fast').siblings('dd:visible').slideUp('fast');
		return false;
	});
}
