//	general.js
//	Syzygy Ltd 08 March 2002
//	Requires:	-
//	Language:	Javascript 1.2
//	Version:	1.1
//	Modified:	08/03/2002


debug = false;

var menuIsPositioned = false;
var linksLayerPositioned = false;

//   ===========================================================================
//    WORK THAT WORKS - INITIALISATION FOR TV/PRINT/RADIO LINK LAYERS
//   ===========================================================================

function workInit(){
	mediaLinks = new Array();
	var initialmediaLinksPos = getLinkPos("#_initialmediaLinksPos");

	// MEDIA LINKS ON CASE STUDIES AND FAVOURITES
		mediaLinks["tv"] = new LayerLite("tvLayer");
		mediaLinks["tv"].moveTo(initialmediaLinksPos.x+3, initialmediaLinksPos.y+8)

		mediaLinks["print"] = new LayerLite("printLayer");
		mediaLinks["print"].moveTo(initialmediaLinksPos.x+3, initialmediaLinksPos.y+8)
		
		mediaLinks["radio"] = new LayerLite("radioLayer");
		mediaLinks["radio"].moveTo(initialmediaLinksPos.x+134, initialmediaLinksPos.y+8)

		var rhsGraphicPos = getLinkPos("#_rhsGraphicPos");
		rhsGraphicLayer = new LayerLite("rhsGraphic");

	// links layer created, ok to show links
	linksLayerPositioned = true;
	return true;
}

//   ===========================================================================
//    CONTACT - PEOPLE - MUST BE INCLUDED ONLOAD FOR CONTACT/PEOPLE/INDEX.ASP
//   ===========================================================================

function peopleInit(){
	people = new Array();
	var initialPeoplePos = getLinkPos("#_initialPeoplePos");
	initialPeoplePos.x -= 90;
	// PEOPLE
		people["start"] = new LayerLite("startLayer");
		people["start"].moveTo(initialPeoplePos.x + 230, initialPeoplePos.y + 30);

		//var addresss = new LayerLite("addressLayer");
		//addresss.moveTo(initialPeoplePos.x + 55, initialPeoplePos.y + 95);

		people["cbarker"] = new LayerLite("cbarkerLayer");
		people['cbarker'].moveTo(initialPeoplePos.x + 170, initialPeoplePos.y +5);

		people["lclay"] = new LayerLite("lclayLayer");
		people["lclay"].moveTo(initialPeoplePos.x + 210, initialPeoplePos.y +5);

		people["mcadman"] = new LayerLite("mcadmanLayer");
		people["mcadman"].moveTo(initialPeoplePos.x + 194, initialPeoplePos.y +5);
		
		people["nbell"] = new LayerLite("nbellLayer");
		people["nbell"].moveTo(initialPeoplePos.x + 80, initialPeoplePos.y +5);

		people["mrimini"] = new LayerLite("mriminiLayer");
		people["mrimini"].moveTo(initialPeoplePos.x + 138, initialPeoplePos.y +5);

		people["kbruges"] = new LayerLite("kbrugesLayer");
		people["kbruges"].moveTo(initialPeoplePos.x + 80, initialPeoplePos.y +5);

		people["pcowie"] = new LayerLite("pcowieLayer");
		people["pcowie"].moveTo(initialPeoplePos.x+  336, initialPeoplePos.y +5);

		people["rlidstone"] = new LayerLite("rlidstoneLayer");
		people["rlidstone"].moveTo(initialPeoplePos.x + 100, initialPeoplePos.y + 5);
		
		people["jharman"] = new LayerLite("jharmanLayer");
		people["jharman"].moveTo(initialPeoplePos.x + 20, initialPeoplePos.y +5);

		people["sbolton"] = new LayerLite("sboltonLayer");
		people["sbolton"].moveTo(initialPeoplePos.x +200, initialPeoplePos.y +5);
}

//   ===========================================================================
//    MENU INITIALISATION - REQUIRED ONLOAD IN EVERY PAGE
//   ===========================================================================

function menuInit() {
	var initialMenuPos = getLinkPos("#_initialMenuPos");
	if(initialMenuPos == null) return false;

	/* NAME DROPPING
		namedropLayer = new LayerLite("namedrop");
		namedropLayer.moveTo(initialMenuPos.x, initialMenuPos.y)

	//  MAKE IT HAPPEN
		happenLayer = new LayerLite("happen");
		happenLayer.moveTo(initialMenuPos.x + 184, initialMenuPos.y)

	// THE COMPANY WE KEEP
		companyLayer = new LayerLite("company");
		companyLayer.moveTo(initialMenuPos.x + 276, initialMenuPos.y)

		peopleLayer = new LayerLite("people");
		peopleLayer.moveTo(initialMenuPos.x + 368, initialMenuPos.y)

*/
	//	WORK THAT WORKS
	workLayer = new LayerLite("work");
	workLayer.moveTo(initialMenuPos.x + 93, initialMenuPos.y)

	casestudiesLayer = new LayerLite("casestudies");
	casestudiesLayer.moveTo(initialMenuPos.x + 93, initialMenuPos.y)

	favouritesLayer = new LayerLite("favourites");
	favouritesLayer.moveTo(initialMenuPos.x + 93, initialMenuPos.y)

	//  MAKE CONTACT
	contactLayer = new LayerLite("contact");
	contactLayer.moveTo(initialMenuPos.x + 369, initialMenuPos.y)

	recruitmentLayer = new LayerLite("recruitment");
	recruitmentLayer.moveTo(initialMenuPos.x + 369, initialMenuPos.y)
	
	
	//  MAKE HEADLINES
	pressLayer = new LayerLite("press");
	pressLayer.moveTo(initialMenuPos.x + 553, initialMenuPos.y)

	

	// menu in position, ok to show menu
	menuIsPositioned = true;
	return true;
}

//   ===========================================================================
//    WORK THAT WORKS - PRINT - REPLACES LAYER WITH VARIOUS PRINT IMAGES ONCLICK
//   ===========================================================================

function changeImageLayer(orient,adName){
	document.images['initialGraphic'].src = "/images/common/spacer.gif";

		if ((adName == "organic_baby") || (adName == "baby_steriliser") || (adName == "mechanics") || (adName == "air_hostess") || (adName == "minicab_drivers") || (adName == "ice") || (adName == "plantation") || (adName == "sunset") || (adName == "scientist")){
			var content = '<table><tr><td><a href="#"><IMG SRC="/print/' + adName + '.jpg" ALT="" BORDER="0" onClick="window.open(\'/includes/print_ads_popup.html?whichPrint=' + adName + '\',\'JWTPrintAds\',\'width=640,height=480,resizable=yes,scrollbars=yes\');"></a></td></tr><tr><td align="center"><font face="Verdana, Geneva, Arial, Helvetica, sans-serif" size="1" color="#999999"><b>click for pop-up</b></td></tr></table></P>';
		} else {
			var content = '<table><tr><td><IMG SRC="/print/' + adName + '.jpg" ALT="" BORDER="0"></td></tr><tr><td>&nbsp;</td></tr></table>';
		}

		var initialPrintPos = getLinkPos("#_initialMenuPos");
		rhsGraphicLayer = new LayerLite("rhsGraphic");
		// orient can be 'h' for horizontal or 'v' for vertical
		if (orient == "v"){
			if (adName == "halfprice") {
				rhsGraphicLayer.moveTo(initialPrintPos.x+540, initialPrintPos.y-20)
			}
			else if (adName == "vodafone") {
				rhsGraphicLayer.moveTo(initialPrintPos.x+525, initialPrintPos.y-10)
			}
			else {
				rhsGraphicLayer.moveTo(initialPrintPos.x+520, initialPrintPos.y-32)
			}
			
		}
		else if (orient == "h"){
			if ((adName == "looks") || (adName == "reel_men")){
				rhsGraphicLayer.moveTo(initialPrintPos.x+370, initialPrintPos.y+10)
			}
			else if ( adName == "sandwich" || adName == "gym" || adName == "dressing" || adName == "sleep" || adName == "sock") {
				rhsGraphicLayer.moveTo(initialPrintPos.x+375, initialPrintPos.y+75)
			}
			else if ( adName == "pregnant_woman" ){
				rhsGraphicLayer.moveTo(initialPrintPos.x+425, initialPrintPos.y+50)
			}
			else if (( adName == "traffic" ) || ( adName == "longvehicle" )){
				rhsGraphicLayer.moveTo(initialPrintPos.x+440, initialPrintPos.y+10)				
			}
			else
			{
				rhsGraphicLayer.moveTo(initialPrintPos.x+375, initialPrintPos.y+25)
			}
		}
		else if ((adName == "smirnoff_red") || (adName == "smirnoff_red")) {
			if (UA.NS4) {
				rhsGraphicLayer.moveTo(initialPrintPos.x+460, initialPrintPos.y+2)
			}
			else {
				rhsGraphicLayer.moveTo(initialPrintPos.x+461, initialPrintPos.y+3)
			}
		}
	rhsGraphicLayer.replace(content)
}

//   =============================================================================
//    WORK THAT WORKS - CREATES A LINK WITH QUERY STRING BASED ON PLUGIN DETECTION
//    ASP code is then used to display correct embed tag and file name
//   =============================================================================

function createLink(media,subSection,page,adName){
	var quickTimeIsInstalled = detectQuickTime();
	var quickTimeAxpIsInstalled = detectQuickTimeActiveXPlayer();
	var WindowsMediaPlayerIsInstalled = detectWindowsMedia();
	var daURL;

	var pathStart = "/work/" +subSection+ "/media_" +page+ ".asp?media=" +media
	var pathEnd =  "&adName=" +adName

	if (media == "radio") {
		daURL = pathStart + "&pluginType=";

		if(quickTimeAxpIsInstalled) daURL += "qtaxp" + pathEnd;
		else if(quickTimeIsInstalled) daURL += "qt" + pathEnd;
		else daURL += "none" + pathEnd;
	}
	else if (media == "print")
	{
		var daURL = "/work/" +subSection+ "/print_" + page + ".asp?media=" +media
	}
	else if (media == "tv")
	{
		if(quickTimeIsInstalled){
			var daURL = pathStart + "&pluginType=qt" + pathEnd
		}
		else if (WindowsMediaPlayerIsInstalled){
			var daURL = pathStart + "&pluginType=wmp" + pathEnd
		}
		else {
			var daURL = pathStart + "&pluginType=none" + pathEnd
		}
	}
	//return window.location = daURL
	window.location.replace(daURL);
}

//   =========================================================================
//    CONTACT - PEOPLE - FOR ROLLOVERS AND ONCLICK
//   =========================================================================

var CLICKEDPERSON = "none";

function peoplePicOn(person){
	document[person].src = "/images/contact/people/" + person + "_on.jpg"
}

function peoplePicOff(person){
	if (CLICKEDPERSON != person){
		document[person].src = "/images/contact/people/" + person + "_off.jpg"
	}else{
		return false;
	}
}

function peopleShowDetail(person){
	if (CLICKEDPERSON != "none"){
		var lastClickedPerson = CLICKEDPERSON;
	}
	CLICKEDPERSON = person;

	peopleHideDetails();
	people[person].show();

	if (lastClickedPerson){
		peoplePicOff(lastClickedPerson);
	}
}

function peopleHideDetails(){
	for (var i in people)
		people[i].hide();
}

//   ===========================================================================
//    WORK THAT WORKS - SHOW HIDE LAYERS CONTAINING SUBLINKS FOR TV/PRINT/RADIO
//   ===========================================================================

function workShowLinks(media){
	if (linksLayerPositioned == true){
		workHideLinks();
		mediaLinks[media].show();
	}
}

function workHideLinks(){
	for (var i in mediaLinks)
		mediaLinks[i].hide();
}

function linkColour(media) {
	if (linksLayerPositioned == true){
		if (UA.IE){
			linksAllOff();
			if (media == "tv"){
			 	tvLink.className = "subnavOn"
			 }
		 	if (media == "radio"){
			 	radioLink.className = "subnavOn"
			 }
		 	if (media == "print"){
			 	printLink.className = "subnavOn"
			 }
		}
	}
}
function linksAllOff() {
	tvLink.className = "subnavOff"
	if (typeof printLink != "undefined"){
		printLink.className = "subnavOff"
	}
	if (typeof radioLink != "undefined"){
		radioLink.className = "subnavOff"
	}
}

function printLinksOff(){
	var printLinks = new Array();
		for (var i in printLinks)
			printLinks[i].className = "subnavOff";
}

//   =========================================================================
//    TOP NAVIGATION - ON/OFF IMAGE STATE
//   =========================================================================

function topnav(imageName,status){

	// document["bttn_" + imageName].src = "/images/topnav/bttn_" + imageName + "_" + status + ".gif"
	var preLoad = (status =="on") ? preLoadedOn: preLoadedOff;

	if(preLoad[imageName] && (preLoad[imageName].complete || status == "off")) {
		document["bttn_" + imageName].src = preLoad[imageName].src;
	}
}

function menuNav(imageName,status,loc){

	var  doc = document;
	if(document.layers) {
		doc = self.document[loc].document[loc].document;
	}
	doc["bttn_" + imageName].src = "/images/topnav/bttn_" + imageName + "_" + status + ".gif"
	//alert(doc.bttn_newbusiness.src+" src");
}

//   =========================================================================
//    NAME DROPPING - FILOFAX PAGE FLIP
//   =========================================================================

function filofaxToggle(direction){
	if (direction == "goForward"){
		document.left.src = "/images/namedrop/arrow_left_on.gif"
		document.filofax.src = "/images/namedrop/filofax_p02.jpg"
		document.right.src = "/images/namedrop/arrow_right_off.gif"
	}
	else if (direction == "goBack"){
		document.right.src = "/images/namedrop/arrow_right_on.gif"
		document.filofax.src = "/images/namedrop/filofax_p01.jpg"
		document.left.src = "/images/namedrop/arrow_left_off.gif"
	}
}

var preLoadedOff = new Array();
var preLoadedOn = new Array();

function getPreLoadedImg(name) {
	preLoadedOff[name] = new Image();
	preLoadedOn[name] = new Image();
	preLoadedOff[name].src = "/images/topnav/bttn_" + name + "_off.gif";
	preLoadedOn[name].src = "/images/topnav/bttn_" + name + "_on.gif";
}

getPreLoadedImg("newbusiness");
getPreLoadedImg("namedrop");
getPreLoadedImg("work");
getPreLoadedImg("happen");
getPreLoadedImg("company");
getPreLoadedImg("contact");
getPreLoadedImg("recruit");
getPreLoadedImg("people");
getPreLoadedImg("casestudies");
getPreLoadedImg("favourites");
getPreLoadedImg("showcase");
getPreLoadedImg("headlines");