/*############################################################################################
##									Generic UI Functions									##
############################################################################################*/
var currentHighlight = null;

function AddCssClass (o,cn)
{
	if(o.className.indexOf(cn)==-1) o.className=o.className.length==0?cn:o.className+" "+cn;
}

function RemoveCssClass (o,cn)
{
	a = o.className.split(" ");
	for(i=0;i<a.length;i++)
	{
		if(a[i].toLowerCase()==cn.toLowerCase())
		{
			a.splice(i,1);
			break;
		}
	}
	o.className = a.join(" ");
}

function Outline(o)
{
	if(currentHighlight!=null) RemoveCssClass(currentHighlight,"Outline");
	AddCssClass(o,"Outline");
	currentHighlight = o;
}

function ReadCookie (name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function WriteCookie (name,value,date)
{
	document.cookie = name+"="+value+"; expires="+date+"; path=/";
}

//Change the class of the item
var ActiveObject = null;

function SelectFirstItem(panel,activeObjectID)
{
	ActiveObject = document.getElementById(activeObjectID);
	o = document.getElementById(panel);
	if(o.childNodes[0].childNodes[0]!=null)
	{
		if(o.childNodes[0].childNodes[0].click)o.childNodes[0].childNodes[0].click();
	}
}


function ChangeClass(o,classActive,classInactive)
{
	if(ActiveObject!=null) classChangeObj(ActiveObject,classInactive);
	classChangeObj(o,classActive);
	ActiveObject = o;
}


function ChangeClassOver(o,className)
{
	if(o!=ActiveObject) classChangeObj(o,className);
}


//Function to change a class
function classChangeVal(Val,className)
{
	o = document.getElementById(Val);
	classChangeObj(o,className)
}


//Function to change a class
function classChangeObj(obj,className)
{
	obj.className = className;
}

//Function to rollover image
function rollover(imgid,imgsrc)
{
	document.getElementById(imgid).src = imgsrc;
}

//Image loaded to workround the IE bug
var imgIndex = 0;
function LoadImages ()
{
	if(imgIndex<Thumbs.length)
	{
		var img = document.getElementById(Elements[imgIndex]).firstChild.firstChild;
		if(img&&!img.complete)
		{
			img.onload = function(){this.onload=null;LoadImages();};
			img.src=Thumbs[imgIndex];
			++imgIndex;
		} else {
			LoadImages(++imgIndex);
		}
	}	
}

function GetFirstChildElement (o,element)
{
	for(var i=0;i<o.childNodes.length;i++)
	{
		if(o.childNodes[i].nodeName.toLowerCase()==element.toLowerCase()) return o.childNodes[i];
	}
	return null;
}

function GotoTop()
{
	if(document.body.scrollTop)
	{
		document.body.scrollTop=0;
	}else{
		document.body.pageYOffset=0;
	}
}

/*############################################################################################
##									Gallery Functions										##
############################################################################################*/
var GalImgID = 1;

function GalleryChange(id,imgId,imgLarge)
{

	if(id!=GalImgID)
	{

		//Change the class of the old item off
		classChangeVal("imgThumb"+GalImgID,"GalleryThumb ThumbOff")
		
		//Change the class of the new item on
		classChangeVal("imgThumb"+id,"GalleryThumb ThumbOn")
		
		//swop out the image
		rollover("imgHero",imgLarge)
		swopHeroImage(imgLarge)

		//Change the current item id
		GalImgID = id;
	}
}

function swopHeroImage(imgLarge)
{
	document.getElementById('GalleryHero').style.background = "url(" + imgLarge + ")";

}


function GalleryClassRoll(id,cssClass)
{
	if(id!=GalImgID)
	{
		classChangeVal("imgThumb"+id,cssClass)
	}
}


function WriteDropShadowPanel (id,width,height,panelColour,shadowImgUrl,zIndexBase)
{
	document.write("<div id=\""+id+"\" >");
	var ua = navigator.userAgent.toLowerCase();
	if(ua.indexOf("msie")>0)
	{
		document.write("<div id=\""+id+"_Shadow\" style=\"left:12px;top:15px;position:absolute;width:"+width+"px;height:"+height+
		"px;background-color:#666666;filter:progid:DXImageTransform.Microsoft.Blur(pixelradius=10);z-index:"+(zIndexBase+1)+"\"></div>");
	} else {
		document.write("<div id=\""+id+"_Shadow\" style=\"position:absolute;left:8px;top:10px\"><img id=\""+id+"_DSImage\" src=\""+shadowImgUrl+"\"/></div>");
	}
}


/*############################################################################################
##									Image Download Functions								##
############################################################################################*/
function DownloadImage(sURL, sWidth, sHeight)
{
	if(sWidth==0) sWidth = (screen.availWidth-50);
	if(sHeight==0) sHeight = (screen.availHeight-50);
	if(sWidth>screen.availWidth) sWidth = (screen.availWidth-50);
	if(sHeight>screen.availHeight) sHeight = (screen.availHeight-50);
	
	var hwin = window.open(sURL,"DownloadFile","width="+(sWidth+20)+",height="+(sHeight+5)+",top=0,left=0,scrollbars=yes,menubar=yes,toolbar=no,location=no");
	hwin.focus();
}


/*############################################################################################
##									InfoItem Functions										##
############################################################################################*/

function InfoItem (){};

//InfoItem.HTTPRequest	= null;
InfoItem.Initialised	= false;
InfoItem.Layer			= null;
InfoItem.Content		= null;
InfoItem.DropShadow		= null;
InfoItem.ContainerID	= null;
InfoItem.ContentID		= null;

InfoItem.Init = function ()
{
	if(InfoItem.Initialised) return;
	InfoItem.Initialised				= true;
	InfoItem.Layer						= document.getElementById(InfoItem.ContainerID);
	InfoItem.Layer.className			= "GalleryItem";
	InfoItem.Layer.style.display		= "none";
	InfoItem.Content					= document.getElementById(InfoItem.ContentID);
	InfoItem.Content.className			= "GalleryContent";
	InfoItem.Content.style.display		= "none";
}

InfoItem.Show = function(o)
{
	InfoItem.Content.src					= o.url;
	InfoItem.Layer.style.display			= "block";
	InfoItem.Content.style.display			= "block";
	InfoItem.Content.style.visibility		= "visible";
	
	var y = document.body.clientHeight? document.body.scrollTop : pageYOffset;
	document.getElementById("Gallery_Container").style.top = (y+15)+"px";
}

InfoItem.Close = function()
{
	InfoItem.Layer.style.display		= "none";
	InfoItem.Content.style.display		= "none";
	InfoItem.Content.style.visibility	= "hidden";
	InfoItem.Content.src				= "about:blank";
}

InfoItem.Create = function (o,url)
{
	InfoItem.Init();
	o.onmousedown 	= null;
	o.url 			= url;
	o.onmouseup 	= function(e){InfoItem.Show(o);InfoItem.ClearEvent(e)};
	o.onclick		= function(e){InfoItem.ClearEvent(e)};
	o.target 		= "_self";
	o.href			= "javascript:void(0);";
	o.onmouseover	= function(){window.status = o.innerText};
	o.onmouseout	= function(){window.status = ""};
}

InfoItem.ClearEvent = function(e)
{
	if(!e)e=window.event;
	e.cancelBubble = true;
	if(e.stopPropagation) e.stopPropagation();
}

/*############################################################################################
##									Image Rotate Functions									##
############################################################################################*/
function RotateImage ()
{
	var corpHomepageImage = ReadCookie("corpHomepageImage");
	if(corpHomepageImage!="")
	{
		corpHomepageImage = parseInt(corpHomepageImage);
	} else {
		corpHomepageImage = 0;
	}
	var chpi = corpHomepageImage;
	
	if(++corpHomepageImage>=HPImages.length) corpHomepageImage = 0;
	var d = new Date();
	d.setTime(d.getTime()+(365*24*60*60*1000));
	WriteCookie("corpHomepageImage",corpHomepageImage,d.toGMTString());
	
	//RMUInstance.SetMediaSrc(HPImages[chpi],'','');
	document.getElementById(MainMenuUnitID).src = HPImages[chpi];
}

/*############################################################################################
##									Write Flash Functions									##
############################################################################################*/
var swfQueryString = "";
function WriteFlash (tagid)
{
	var nsTag = document.getElementById(tagid);
	var fstring = nsTag.innerHTML;
	if(swfQueryString!="")
	{
		if(fstring.indexOf(".swf?")==-1)
		{
			fstring = fstring.replace(/.swf/,".swf?"+swfQueryString);
		} else {
			fstring = fstring.replace(/.swf\?/,".swf&");
			fstring = fstring.replace(/.swf/,".swf?"+swfQueryString);
		}
	}
	nsTag.outerHTML = fstring;
}


/*############################################################################################
##									Basket Functions										##
############################################################################################*/
function BasketSubmit(inputid,inputvalue)
{
	//alert("inputid:" + inputid);
	//alert("inputvalue:" + inputvalue);
	//alert(document.getElementById(inputid));
	document.getElementById(inputid).value = inputvalue;
	
	document.basket.submit();
}

/*############################################################################################
##									Checkout Functions										##
############################################################################################*/
function CheckoutSubmit(inputid,inputvalue)
{
	document.getElementById(inputid).value = inputvalue;
	document.checkout.submit();
}

