var substatus = false;

//Image preloader
imageSource = new Array (
	"images/bg.jpg",
	"images/bg_footer.gif",
	"images/bg_main.jpg",
	"images/brd_pic.jpg",
	"images/head_car.jpg",
	"images/logo_citiusmotorsport.gif",
	"images/logo_citiusmotorsport_pop.gif",
	"images/nav_bar.jpg",
	"images/btn_visabilarna.gif",
	"images/btn_stangfonstret.gif"
)

imageList = new Array ();

for (counter in imageSource) {
    imageList[counter] = new Image();
    imageList[counter].src = imageSource[counter];
}

//Iframe resizer
var ie = (document.all) ? true : false; //sets browser to Internet Explorer
var ns6_mozilla = (document.getElementById) ? true : false; //sets browser to Netscape 6 or higher, or Mozilla

//Choose show or hide layer
function showOrHide(object) {
	if (substatus == false) {
		showLayer(object);
		substatus = true;
	}
	else if (substatus == true) {
		hideLayer(object);
		substatus = false;
	}
}

//show layer
function showLayer(object) {
	if (document.all) {
		document.all[object].style.visibility = 'visible';
		//document.all[object].style.position = 'absolute';
  	}
  	else if (document.getElementById) {
		document.getElementById(object).style.visibility = 'visible';
		//document.getElementById(object).style.position = 'absolute';
	}
  	else if (document.layers && document.layers[object]) {
		document.layers[object].visibility = 'visible';
		//document.layers[object].position = 'absolute';
  	}
}

//hide layer
function hideLayer(object) {
	if (document.all) {
    	document.all[object].style.visibility = 'hidden';
		//document.all[object].style.position = 'absolute';
 	}
  	else if (document.getElementById) {
		document.getElementById(object).style.visibility = 'hidden';
		//document.getElementById(object).style.position = 'absolute';
  	}
  	else if (document.layers && document.layers[object]) {
    	document.layers[object].visibility = 'hidden';
		//document.layers[object].position = 'absolute';
  	}
}

//Choose show or hide layer 2
function showOrHide2(object) {
	if (substatus == false) {
		showLayer2(object);
		substatus = true;
	}
	else if (substatus == true) {
		hideLayer2(object);
		substatus = false;
	}
}

//show layer 2
function showLayer2(object) {
	if (document.all) {
		document.all[object].style.visibility = 'visible';
		document.all[object].style.position = 'static';
  	}
  	else if (document.getElementById) {
		document.getElementById(object).style.visibility = 'visible';
		document.getElementById(object).style.position = 'static';
	}
  	else if (document.layers && document.layers[object]) {
		document.layers[object].visibility = 'visible';
		document.layers[object].position = 'static';
  	}
}

//hide layer 2
function hideLayer2(object) {
	if (document.all) {
    	document.all[object].style.visibility = 'hidden';
		document.all[object].style.position = 'absolute';
 	}
  	else if (document.getElementById) {
		document.getElementById(object).style.visibility = 'hidden';
		document.getElementById(object).style.position = 'absolute';
  	}
  	else if (document.layers && document.layers[object]) {
    	document.layers[object].visibility = 'hidden';
		document.layers[object].position = 'absolute';
  	}
}

//Function for contact form
function funcfrmOrder(){
	if (document.frmOrder.Kontaktperson.value == "") {
		alert('Du måste ange kontaktperson!');
		document.frmOrder.Kontaktperson.focus();
		return false;
	}
	else if (document.frmOrder.Epostadress.value == "") {
		alert('Du måste ange din epostadress!');
		document.frmOrder.Epostadress.focus();
		return false;
	}
	else if (document.frmOrder.Meddelande.value == "") {
		alert('Du måste skriva ett meddelande!');
		document.frmOrder.Meddelande.focus();
		return false;
	}
	document.frmOrder.email.value = document.frmOrder.Epostadress.value;
	document.frmOrder.realname.value = document.frmOrder.Kontaktperson.value;
	document.frmOrder.submit();
}

function funcfrmOrderCatalogue(){
	if (document.frmOrder.Kontaktperson.value == "") {
		alert('Du måste ange kontaktperson!');
		document.frmOrder.Kontaktperson.focus();
		return false;
	}
	else if (document.frmOrder.Postadress.value == "" || document.frmOrder.Postnummer.value == "" || document.frmOrder.Postort.value == "") {
		alert('Du måste ange din fullständiga adress!');
		document.frmOrder.Postadress.focus();
		return false;
	}
	else if (document.frmOrder.Epostadress.value == "") {
		alert('Du måste ange din epostadress!');
		document.frmOrder.Epostadress.focus();
		return false;
	}
	document.frmOrder.email.value = document.frmOrder.Epostadress.value;
	document.frmOrder.realname.value = document.frmOrder.Kontaktperson.value;
	document.frmOrder.submit();
}

	
//Open window
openTeam = function(thisPage) {
	var iWidth = 580;
	var iHeight = 240;
	openPopupWin(thisPage,'no',iWidth,iHeight,50,50,'teampage');
}

openCar = function(thisPage,thisHeight) {
	var iWidth = 682;
	var iHeight =  parseInt(thisHeight) + 71;
	openPopupWin(thisPage,'no',iWidth,iHeight,50,50,'carpage');
}

function openPopupWin(newWindow, iScrollbars, iWidth, iHeight, iX, iY, winName) {
	var win = null;
	
	iX = (screen.width) ? (screen.width-iWidth)/2 : 10;
	iY = (screen.height) ? (screen.height-iHeight)/2 : 10;
				
	winStats="menubar=no,location=no,directories=no,status=no,resizable=no,scrollbars=" + iScrollbars;
	
	if (navigator.appName.indexOf("Microsoft")>=0) {
	      winStats+=",left=" + iX + ",top=" + iY + ",width=" + iWidth + ",height=" + iHeight;
	} else {
	      winStats+=",screenX=" + iX + ",screenY=" + iY + ",width=" + iWidth + ",height=" + iHeight;
	}
	
	win = window.open(newWindow,winName,winStats);
	if (win.opener == null) win.opener = window;
	win.opener.name = "opener";
}