productsMenu = document.getElementById('products');
productsMenuYPos = -310;
productsMenuOpacity = 0;
productsMenu.style.top = productsMenuYPos + "px";
showProducts=false;

splashScreen = (Math.floor(Math.random()*10)); //nos 0-9
splashProdHeadingArray = ["Transportable<br>Fuel Tanks","Heavy Duty Transportable<br>Fuel Tanks","Transportable<br>Refuellers","Site Tow<br>Refuellers","Road Tow<br>Refuellers","Storage<br>Fuel Tanks","UN Portable<br>Tank Containers","DoT Refueller<br>Tank Containers","Storage<br>Tank Containers"];
splashProdSubHeadingArray = ["Pump or generator back up fuel!","For that extra protection","On site fuel ups!","Get fuel where you want it!","Fuel delivery at speed!!","Fuel storage with Transcube features!","Bulk fuel movement","Transportable refueller","Bulk storage"];

splashProdBulletsArray = [];
splashProdBulletsArray.push("<li>UN approved fuel transportation</li><li>Back up fuel for up to 3 generators</li><li>Stackable, fork and crain liftable</li><li>Removable inner tank</li><li>UL142, Vlarem & Kiwa</li>");
splashProdBulletsArray.push("<li>Full galvinised</li><li>Maxium fuel protection</li><li>Inspection chambers</li><li>Baffled tanks, smooth ride</li><li>Unic dimensions</li>");
splashProdBulletsArray.push("<li>Large cabinets for pump and<br>hose reels</li><li>Hazardous bunded storage</li><li>Heavy duty mesh grill</li><li>Your tool box with a fuel tank!</li>");
splashProdBulletsArray.push("<li>Heavy duty 'A' frame<br>construction chassis</li><li>Agriculture duty wheels & tyres</li><li>Rear Bumper crash protection</li><li>Galvinised chassis</li>");
splashProdBulletsArray.push("<li>Rubber suspension road tow axles</li><li>Hub type auto reverse braking system<br>or optional Electric</li><li>Non slip operating platform</li><li>Tank unmounts from chassis</li>");
splashProdBulletsArray.push("<li>Generator feed and<br>returns standard</li><li>Double wall 110% fuel tank</li><li>Transportable empty only<br>under UN1202</li>");
splashProdBulletsArray.push("<li>Transportable full road, rail<br>and sea</li><li>Double wall 110% Fuel Tank</li><li>UL142 above ground fuel tank</li>");
splashProdBulletsArray.push("<li>Built for the weather</li><li>Bulk transportable fuel with<br>large despensing cabinet</li>");
splashProdBulletsArray.push("<li>Containerised bulk fuel storage<br>tanks CSC plated</li><li>UL 142 above ground double<br>wall tanks</li><li>Relocatable tank farms</li>");

splashProdBGImageArray = ["transportable-fuel-tanks-bg.jpg","heavy-duty-transportable-fuel-tanks-bg.jpg","transportable-refuellers-bg.jpg","site-tow-refuellers-bg.jpg","road-tow-refuellers-bg.jpg","storage-fuel-tanks-bg.jpg","un-portable-tank-containers-bg.jpg","dot-refueller-tank-containers-bg.jpg","storage-tank-containers-bg.jpg"];
splashProdXPosArray = [340,280,300,260,290,360,320,320,320];
splashProdImageArray = ["transportable-fuel-tanks.png","heavy-duty-transportable-fuel-tanks.png","transportable-refuellers.png","site-tow-refuellers.png","road-tow-refuellers.png","storage-fuel-tanks.png","un-portable-tank-containers.png","dot-refueller-tank-containers.png","storage-tank-containers.png"];

function splashInit(screenNo) {
	if (!screenNo) {
		splashScreen == splashProdHeadingArray.length ? splashScreen = 1 : splashScreen ++;
		splashScreen == 1 ? lastSplashScreen = splashProdHeadingArray.length : lastSplashScreen = splashScreen-1;
	} else {
		lastSplashScreen = splashScreen;
		splashScreen = screenNo;
		prevColour = "#ed1c22";
	}
	document.getElementById('splashHeading').innerHTML = splashProdHeadingArray[splashScreen-1];
	document.getElementById('splashSubHeading').innerHTML = splashProdSubHeadingArray[splashScreen-1];
	document.getElementById('splashBullets').innerHTML = splashProdBulletsArray[splashScreen-1];
	document.getElementById('splashBG').src = "images/" + splashProdBGImageArray[splashScreen-1];
	document.getElementById('splashProdImage').src = "images/" + splashProdImageArray[splashScreen-1];
	document.getElementById('splashPaging'+splashScreen).style.color = "#ffffff";
	document.getElementById('splashPaging'+splashScreen).style.backgroundColor = "#ed1c22";
	document.getElementById('splashPaging'+lastSplashScreen).style.color = "#ed1c22";
	document.getElementById('splashPaging'+lastSplashScreen).style.backgroundColor = "#ffffff";
	splashBGOpacity = 0;
	splashHeadingYPos = 115;
	splashDetailsYPos = -150;
	splashProductXPos = 485;
	document.getElementById('splashBG').style.opacity = splashBGOpacity;
	document.getElementById('splashBG').style.filter = "alpha(opacity = "+(splashBGOpacity*100)+")";
	document.getElementById('splashHeading').style.marginTop = splashHeadingYPos + "px";
	document.getElementById('splashDetails').style.marginTop = splashDetailsYPos + "px";
	document.getElementById('splashProdImage').style.left = splashProductXPos + "px";
}

function splashPagingChange(elem,doState) {
	if (doState=="over") {
		prevColour = elem.style.backgroundColor;
		elem.style.backgroundColor="#cccccc";
	} else {
		elem.style.backgroundColor=prevColour;
	}
}

function showHideMenu(elem,vis) {
	menu = document.getElementById(elem);
	menuVis = vis;
	if (typeof slideProductsMenu != "undefined") 	{clearInterval(slideProductsMenu);}
	if (typeof fadeProductsMenu != "undefined")	{clearInterval(fadeProductsMenu);}
	slideProductsMenu = setInterval('slideMenu()',50);
	fadeProductsMenu = setInterval('fadeMenu()',50);
}

function slideMenu() {
	if (menuVis == "show") {
		productsMenuYPos < -1 ? productsMenuYPos = (productsMenuYPos/2) : productsMenuYPos = 0;
	}
	productsMenu.style.top = productsMenuYPos + "px";
	if ((menuVis=="hide") || (menuVis=="show" && productsMenuYPos == 0)) {
		clearInterval(slideProductsMenu);
	}
}

function fadeMenu() {
	if (menuVis == "show") {
		if (document.getElementById('productsMenuContainer').style.display == 'none') {document.getElementById('productsMenuContainer').style.display = 'inline-block'};
		productsMenuOpacity < 1 ? productsMenuOpacity += 0.2 : productsMenuOpacity = 1;
	} else {
		productsMenuOpacity > 0 ? productsMenuOpacity -= 0.2 : productsMenuOpacity = 0;
	}
	productsMenu.style.opacity = productsMenuOpacity;
	productsMenu.style.filter = "alpha(opacity = "+(productsMenuOpacity*100)+")";
	if ((menuVis=="hide" && productsMenuOpacity==0) || (menuVis=="show" && productsMenuOpacity==1)) {
		clearInterval(fadeProductsMenu);
		if (menuVis == "hide") {
			productsMenuYPos = -310;
			productsMenu.style.top = productsMenuYPos + "px";
			document.getElementById('productsMenuContainer').style.display = 'none';
		}
	}
}

function navFadeInOut(elem,dir) {
	dir == "in" ? elem.style.opacity = 1 : elem.style.opacity = 0.8;
	dir == "in" ? elem.style.filter = "alpha(opacity = 100)" : elem.style.filter = "alpha(opacity = 80)";
}

function moveSplashImage(elem, dir) {
	dir == "in" ? elem.style.left = (parseFloat(elem.style.left)-10)+'px' : elem.style.left = (parseFloat(elem.style.left)+10)+'px';
}

function splashAnimStep1() {
	if (splashBGOpacity<1) {
		splashBGOpacity += 0.1;
	} else {
		splashBGOpacity = 1;
		clearInterval(splashAnim);
		splashAnim = setInterval('splashAnimStep2()',50);
	}
	document.getElementById('splashBG').style.opacity = splashBGOpacity;
	document.getElementById('splashBG').style.filter = "alpha(opacity = "+(splashBGOpacity*100)+")";
}

function splashAnimStep2() {
	if (splashHeadingYPos>16 && splashDetailsYPos < -1) {
		splashHeadingYPos -= ((splashHeadingYPos-15)/4);
		splashDetailsYPos += ((-splashDetailsYPos)/4);
	} else {
		splashHeadingYPos = 15;
		splashDetailsYPos = 0;
		clearInterval(splashAnim);
		splashAnim = setInterval('splashAnimStep3()',50);
	}
	document.getElementById('splashHeading').style.marginTop = splashHeadingYPos + "px";
	document.getElementById('splashDetails').style.marginTop = splashDetailsYPos + "px";
}

function splashAnimStep3() {
	if (splashProductXPos>(splashProdXPosArray[splashScreen-1]+1)) {
		splashProductXPos -= ((splashProductXPos-splashProdXPosArray[splashScreen-1])/4);
	} else {
		splashProductXPos = splashProdXPosArray[splashScreen-1];
		clearInterval(splashAnim);
		splashAnim = setTimeout('clearInterval(splashAnim);splashInit();splashAnim = setInterval(\'splashAnimStep1()\',50)',10000);
	}
	document.getElementById('splashProdImage').style.left = splashProductXPos + "px";
}

function goSplashPage(pageNo) {
	clearInterval(splashAnim);
	splashInit(pageNo);
	splashAnim = setInterval('splashAnimStep1()',50);
}

function goSplashURL() {
	splashProdURL = ["/transportable-fuel-tanks","heavy-duty-transportable-fuel-tanks","transportable-refuellers","site-tow-refuellers","road-tow-refuellers","storage-fuel-tanks","un-portable-fuel-tank-containers","dot-refueller-tank-containers","storage-tank-containers"];
	window.location = splashProdURL[splashScreen-1];
}

function showHideMouseIcon(showHide) {
	mI = document.getElementById('mouseIcon');
	document.mapPoint.pointType.value == "Distributor" ? mI.src = "images/distributor-map-pin.png" : mI.src = "images/distributor-map-transcube.png";
	if (document.mapPoint.pointName.value!="" && document.mapPoint.pointURL.value!="" && document.mapPoint.pointURL.value!="http://www.") {
		showHide == "show" ? mI.style.display = "inline-block" : mI.style.display = "none";
	} else {
		mI.style.display = "none";
	}
	mI.style.display == "none" ? document.getElementById('map').style.cursor = "auto" : document.getElementById('map').style.cursor = "none";
}

function moveMouseIcon(e) {
	if (document.layers||document.getElementById&&!document.all) {
		// NS
		xPos = e.pageX;
		yPos = e.pageY;
	} else if (document.all) { 
		// IE
		xPos = event.clientX;
		yPos = event.clientY;
	}
	document.mapPoint.pointType.value == "Distributor" ? mI.style.left = (xPos+1) + "px" : mI.style.left = (xPos-10) + "px";
	document.mapPoint.pointType.value == "Distributor" ? mI.style.top = (yPos-19) + "px" : mI.style.top = (yPos-21) + "px";
}

function placeNewMapPoint(obj,e) {
	if (document.mapPoint.pointName.value.length>0 && document.mapPoint.pointURL.value.length>0) {
		// Find x&y of current object
		var currLeft = currTop = 0;
		if (obj.offsetParent) {
			do {
			currLeft += obj.offsetLeft;
			currTop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		// Then find mouse position according to that object
		if (document.layers||document.getElementById&&!document.all) {
			// NS
			document.mapPoint.xPos.value = (e.pageX-currLeft);
			document.mapPoint.yPos.value = (e.pageY-currTop);
		} else if (document.all) { 
			// IE
			document.mapPoint.xPos.value = (event.clientX-currLeft);
			document.mapPoint.yPos.value = (event.clientY-currTop);
		}
	document.mapPoint.submit();
	} else {
		alert('Please enter a name & URL for the new map point first');
	}
}

function showHidePinNote(elem,state) {
	state == "show" ? document.getElementById(elem).style.display = "inline-block" : document.getElementById(elem).style.display = "none";
}
