// STORE REQUIRED ACTIONS IN VARIABLE //

var W3CDOM = (document.getElementsByTagName);

function init() {

	windowwidth = window.innerWidth;
	pagewidth = document.getElementById("pagewrapper").offsetWidth;

	if (!windowwidth) {
		windowwidth = document.documentElement.clientWidth;
	}

	if (!windowwidth || windowwidth == 0) {
		windowwidth = document.body.clientWidth;
		pagewidth = document.getElementById("pagewrapper").offsetWidth;
	}

	if(windowwidth > 1250) {


	} else {

	}

	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	}

	if(windowwidth > 900) {

		document.getElementById("leftside2").style.left = "1px";
		document.getElementById("rightside2").style.right = "10px";
		document.getElementById("header").style.marginLeft = "5px";
		document.getElementById("header").style.marginRight = "15px";
		document.getElementById("leftcorner").style.left = "0px";
		document.getElementById("rightcorner").style.right = "9px";
		document.getElementById("bottomleftcorner").style.left = "0px";
		document.getElementById("bottomrightcorner").style.right = "8px";
		if(windowwidth > 1000) {
			document.getElementById("pagewrapper").style.marginRight = "40px";
			document.getElementById("pagewrapper").style.marginLeft = "40px";
		} else {
			document.getElementById("pagewrapper").style.marginRight = "40px";
			document.getElementById("pagewrapper").style.marginLeft = "40px";
		}

		document.getElementById("bottomfade").style.marginRight = "23px";
		document.getElementById("bottomfade").style.marginLeft = "9px";
		document.getElementById("topfade").style.display = "block";
		document.getElementById("bottomleftcorner").style.display = "block";
		document.getElementById("bottomrightcorner").style.display = "block";

	} else {

		document.getElementById("leftcorner").style.left = "0px";
		document.getElementById("rightcorner").style.right = "0px";
		document.getElementById("bottomleftcorner").style.display = "none";
		document.getElementById("bottomrightcorner").style.display = "none";
		document.getElementById("leftside2").style.left = "0px";
		document.getElementById("rightside2").style.right = "0px";
		document.getElementById("header").style.marginLeft = "0px";
		document.getElementById("header").style.marginRight = "0px";
		document.getElementById("pagewrapper").style.marginRight = "0px";
		document.getElementById("pagewrapper").style.marginLeft = "0px";
		document.getElementById("bottomfade").style.marginRight = "0px";
		document.getElementById("bottomfade").style.marginLeft = "0px";
		document.getElementById("topfade").style.display = "none";

	}

	if (ieversion == 6) {

		document.getElementById("rightside2").style.height = document.getElementById("headerwrapper").offsetHeight - 24 + "px";
		document.getElementById("leftside2").style.height = document.getElementById("headerwrapper").offsetHeight - 17 + "px";
			
	} else {

		document.getElementById("rightside2").style.height = document.getElementById("headerwrapper").offsetHeight - 23 + "px";
		document.getElementById("leftside2").style.height = document.getElementById("headerwrapper").offsetHeight - 20 + "px";

	}

	// IF ACTIONS ARE NOT SUPPORTED STOP SCRIPT //
	if (!W3CDOM) return;

	var menu = document.getElementById('menu');

	if(menu) {

		var ptags = menu.getElementsByTagName('li');

		for (var i=0;i<ptags.length;i++) {

//			ptags[i].onmouseover = mousegoesover;
//			ptags[i].onmouseout = mousegoesout;

		}

	}

}

function mousegoesover() {
	this.className = "over";
	this.style.cursor = "pointer";
}

function mousegoesout() {
	this.className = "";
}

function runSpecialShow(item,d,s) {

	if(d == (item.length)) {
		d = 0;
	}
	if(document.getElementById("special_"+s+"_name")) {
		document.getElementById("special_"+s+"_name").innerHTML = item[d]["name"];
	}
	if(document.getElementById("special_"+s+"_link")) {
		document.getElementById("special_"+s+"_link").href = item[d]["link"];
	}
	if(document.getElementById("special_"+s+"_img_link")) {	
		document.getElementById("special_"+s+"_img_link").href = item[d]["link"];
	}
	if(document.getElementById("special_"+s+"_full")) {
		document.getElementById("special_"+s+"_full").innerHTML = item[d]["full_price"];
	}
	if(document.getElementById("special_"+s+"_monthly")) {
		document.getElementById("special_"+s+"_monthly").innerHTML = item[d]["monthly_price"];
	}
	if(document.getElementById("special_"+s+"_image")) {
		document.getElementById("special_"+s+"_image").src = item[d]["image"];
	}

	if(document.getElementById("special_"+s+"_colour")) {
		document.getElementById("special_"+s+"_colour").innerHTML = item[d]["colour"];
	}
	if(document.getElementById("special_"+s+"_mileage")) {
		document.getElementById("special_"+s+"_mileage").innerHTML = item[d]["mileage"];
	}

	d++;

	setTimeout( function () { runSpecialShow(item,d,s) } ,6000);	

}

function showHide() {

	if(document.getElementById("part_exchange").options[document.getElementById("part_exchange").selectedIndex].value == 'yes') {
		document.getElementById("part_exchange_form").style.display = "block";
	} else {
		document.getElementById("part_exchange_form").style.display = "none";
	}

}

        function findPageOffset() {
                var x = y = 0;
                if (self.pageYOffset) { // if !ie
                        x = self.pageXOffset;
                        y = self.pageYOffset;
                } else if (document.documentElement && document.documentElement.scrollTop) { // if ie6 strict
                        x = document.documentElement.scrollLeft;
                        y = document.documentElement.scrollTop;
                } else if (document.body) { // all other ie
                        x = document.body.scrollLeft;
                        y = document.body.scrollTop;
                }
                return [x,y];
        }
