// $Id$

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;

var recentHash = "";

function preloadTabs(){
	var imgPath = "";
	var images = [];
	var pageSection = window.location.href.replace(window.location.protocol + "//" + window.location.host,"");
	switch(pageSection){
		case "/our-work/transport-for-london.html":
			imgPath = "/img/our-work/tabs/";
			images = ["online-tv-over","PR-tab-over","press-tab-over"];
		break;
		case "/our-work/rolls-royce.html":
			imgPath = "/img/our-work/tabs/";
			images = ["brochure-tab-over","mail-tab-over","films-tab-over","online-tab-over"];
		break;
		case "/our-work/dcsf.html":
			imgPath = "/img/our-work/tabs/";
			images = ["films-tab-over","online-tab-over"];
		break;
		case "/our-work/abbey.html":
			imgPath = "/img/our-work/tabs/";
			images = ["tv-tab-over","POS-tab-over","press-tab-over","online-tab-over"];
		break;
		case "/our-work/fun-on-the-floor.html":
			imgPath = "/img/our-work/tabs/";
			images = ["experimental-tab-over","outdoor-tab-over","PR-tab-over","online-tab-over"];
		break;
		case "/about-engine/our-model/expertise.html":
		case "/about-engine/our-model/sector-practise.html":
		case "/about-engine/our-model/companies.html":
			imgPath = "/img/our-model/tabs/";
			images = ["companies-over","practices-over","expertise-over"];
		break;
		case "/corporate-information/our-journey.html":
			replaceJourneyFlash();
		break;
	}
	
	for(i=0;i<images.length;i++){
		var img = new Image();
		img.src = imgPath + images[i] + ".png";
		//console.log(img);
	}
}

// onLoad functions
function init() {

	externalLinks();
}

function replaceJourneyFlash() { 
	if(!(swfobject.hasFlashPlayerVersion("1"))){
		document.getElementById('content').innerHTML = '<img src="/img/corporate-information/our-journey/engine_journey_graphic.jpg" style="margin:125px auto 0;"/>';
	}
}

// opens links in new window with rel="external" to validate xhtml strict
function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
 	for (var i=0; i<anchors.length; i++) { 
   			var anchor = anchors[i]; 
 			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){
 				anchor.target = "_blank"; 
       		} else if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "thiswindow")anchor.target = "_top";
 	} 
}

//change bg_colors of text fields and text areas
Event.observe(window, "load", function() {
	if($('map')){
		if(document.body.clientWidth <= 1024){
			$('map').setStyle({"width":'998px'});
			$('intro').setStyle({"width" : "998px","margin" : "0 0 0 -20px"});
		}
	}
/*
	var inputFields = document.getElementsByTagName("input");
	var textFields = document.getElementsByTagName("textarea");
	
	if(inputFields){
		
		for(i=0; i<=(inputFields.length - 1); i++){
			var att = $(inputFields[i]).readAttribute("type");
			if(att=="text"){
			
				inputFields[i].observe('focus', function(e){
					e.element().style.backgroundColor = "#fff";
					e.element().style.color = "#000";
				});
				inputFields[i].observe('blur', function(e){
					e.element().style.backgroundColor = "#242424";
					e.element().style.color = "#fff";
				});
			}
		}
	}
		
	if(textFields){
		for(i=0; i<=(textFields.length - 1); i++){
			
				textFields[i].observe('focus', function(e){
					e.element().style.backgroundColor = "#fff";
					e.element().style.color = "#000";
				});
				textFields[i].observe('blur', function(e){
					e.element().style.backgroundColor = "#242424";
					e.element().style.color = "#fff";
				});

		}
	}

*/

	if ($('smallTabs')) {
		var links = $('smallTabs').select('li');
		for (var i=0; i<=links.length-1; i++) {
			$(links[i]).observe('mouseover', function(e) {
				this.addClassName('over-' + this.down('a').innerHTML.replace(" ",""));
			});
			$(links[i]).observe('mouseout', function(e) {
				this.removeClassName('over-' + this.down('a').innerHTML.replace(" ",""));
			});
		}
	}

	if ($('largeTabs')) {
		var links = $('largeTabs').select('li');
		for (var i=0; i<=links.length-1; i++) {
			$(links[i]).observe('mouseover', function(e) {
				this.addClassName('over-' + this.down('a').innerHTML.replace(" ",""));;
			});
			$(links[i]).observe('mouseout', function(e) {
				this.removeClassName('over-' + this.down('a').innerHTML.replace(" ",""));
			});
		}
	}

	if ($('introPanel')) {
		$('introPanel').observe('mouseover', function(e) {
			this.addClassName('over');
		});
		$('introPanel').observe('mouseout', function(e) {
			this.removeClassName('over');
		});
	}
	preloadTabs();
});

function setHash(idToShow){
	//update temp var
	recentHash = idToShow;
	//update hash
	window.location.hash = idToShow;
}

function pollHash() {
	 if (window.location.hash==recentHash) {
	   return; // Nothing's changed since last polled.
	 }
	 recentHash = window.location.hash;
	 //strip out the has to pass to switcher
	 intialiseStateFromURL();
}

function engineStrategyVideo() {
	/*if($j.browser.msie && $j.browser.version < 9) {
		flash_in_lightbox.embed('/swf/media-player/mediaPlayer.swf', { uid: 'engineStrategyFilm', xmlurl:'../../../xml/lightbox.xml' }, { wmode: "transparent", allowscriptaccess: "always" }, false);
	}else{
		vlb.embedVideos({ uid: 'engineStrategyFilm' }, '/video/about-engine/our-model/companies/engine-strategy.flv', '/swf/media-player/mediaPlayer.swf');
	}*/

	flash_in_lightbox.embed('/swf/media-player/mediaPlayer.swf', { uid: 'engineStrategyFilm', xmlurl:'../../../xml/lightbox.xml' }, { wmode: "transparent", allowscriptaccess: "always" }, false);
//	flash_in_lightbox.embed('/swf/media-player/mediaPlayer.swf', { uid: '/video/our-work/abbey/02-skyHPTO.flv' }, { wmode: "transparent", allowscriptaccess: "always" }, false);
}

function closeLightbox() {
	//alert('close lightbox');
	flash_in_lightbox.close();
	lpb_lightbox.end();
}

externalLinks();
