// THIS CODE was mutated, modified, and re-done by the K10kª semi-bald posse
// THIS CODE was done in 1997-2001
//
// ----------------------------------------------------------------------
//
// NOTE1: IE4 fucks up if you try to "compress" js statements, like this:
// if (!document.getElementById) { browserNew = false; That's why all
// the lines have been written out in full.
//
// NOTE2: The innerHTML function actually crashes IE4/IE4.5 if you're not
// careful - the solution is to add a small delay before you call that function.
// As of this writing, innerHTML is not supported in Opera5.
//
// ----------------------------------------------------------------------




// CHECK CLIENT BROWSER & PLATFORM
// original code from http://developer.apple.com/internet/_javascript/
//
// USAGE:	browserNaming();
// NOTES:	call it from within an external JS document
// RESULT:	browserNew = true/false
//			browserName = IE/NS/Opera
//			browserNameLong = IE5/etc
//			Macintosh = true/false
// WORKS:	everything

	var its;
	var browserName;
	var browserNameLong;
	var browserNew;
	var preloadFlag = false;
	var Macintosh = navigator.userAgent.indexOf('Mac')>0;

	function its() {
		var n = navigator;
		var ua = ' ' + n.userAgent.toLowerCase();
		var pl = n.platform.toLowerCase();
		var an = n.appName.toLowerCase();

		// browser version
		this.version = n.appVersion;
		this.nn = ua.indexOf('mozilla') > 0;

		// 'compatible' versions of mozilla aren't navigator
		if(ua.indexOf('compatible') > 0) {
			this.nn = false;
		}
		
		this.opera = ua.indexOf('opera') > 0;
		this.ie = ua.indexOf('msie') > 0;
		this.major = parseInt( this.version );
		this.minor = parseFloat( this.version );

		// platform
		this.mac = ua.indexOf('mac') > 0;
		this.win = ua.indexOf('win') > 0;

		// workaround for IE5 which reports itself as version 4.0
		if(this.ie) {
			if(ua.indexOf("msie 5") > 1) {
			var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
			this.major = parseFloat(navigator.appVersion.substr(msieIndex,3));
			}
		}

		return this;
	}

	function browserNaming() {
		its = new its();
		
		// is it a DOM-enabled browser?
		if (!document.getElementById) {
			browserNew = false;
		}
		else {
			browserNew = true;
		}

		// need the name, too
		if (its.opera) {
			browserName = "Opera";
		}
		else if (its.ie) {
			browserName = "IE";
		}
		else {
			browserName = "NS";
		}

		// and the number
		browserNameLong = browserName + its.major;
	
	}
	
	browserNaming();
	
	
// PRELOAD FUNCTION
// USAGE:	window.onload = preloadMe();
// NOTES:	call it from within the html page
// WORKS:	ie4+, ns4+, opera5

	//function preloadMe() {
	//	createObject('car','../images/audi-tt.jpg');
	//	createObject('stone','../images/bg_stone.gif');
	//	preloadFlag = true;
	//}


// CREATING THE MOUSEOVER IMAGES
// USAGE:	createObject('buttonoff','images/specfeature_celluar_off.gif');
// NOTES:	call it from within the preload function
// WORKS:	ie4+, ns4+, opera5

	function createObject(imgName,imgSrc) {
		if (browserNew && (browserName == "NS")) {
		// a DOM-compatible browser
		// which is probably NS6/mozilla (the other code works better in IE/Opera)
			var tempImg = document.createElement("img");
			tempImg.src = imgSrc;
			tempImg.id = imgName;
			tempImg.style.visibility = 'hidden';
			tempImg.style.position = 'absolute';
			tempImg.style.top = 0;
			document.body.appendChild(tempImg);
		}
		else {
		// a non-DOM-compatible browser
		// and IE/Opera
			eval(imgName+' = new Image()');
			eval(imgName+'.src = "'+imgSrc+'"');
		}
	}


// MOUSEOVER SWITCHING
// USAGE:	<a href="#" onmouseover="changeImage(null,'buttonname','buttonnameon');" onmouseout="changeImage(null,'buttonname','buttonnameoff');">
// NOTES:	if the image is in a DIV, substitute 'null' with the DIV name.
// WORKS:	ie4+, ns4+, opera5

	function changeImage(layer,imgName,imgObj) {
		if (preloadFlag) {
			if (browserNew && (browserName == "NS")) {
			// a DOM-compatible browser
			// which is probably NS6/mozilla (the other code works better in IE/Opera)
				thisImage = document.getElementById(imgName);
				newImage = document.getElementById(imgObj);
				newSrc = newImage.getAttribute("src");
				thisImage.setAttribute("src",newSrc);
			}
			else {
			// a non-DOM-compatible browser
			// and IE/Opera
				if ((browserName == "NS") && layer!=null) eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src')
				else document.images[imgName].src = eval(imgObj+".src")
			}
		}
	}


// POPUP WINDOW (FIXES THE IE4/MAC PROBLEM WHICH MAKES WINDOWS TOO SMALL)
// USAGE:	<a href="#" onclick="spawnWindow('newpage.html','windowname',400,384,'no');">
// NOTES:	substitute 400 with the width, 384 with the height, windowname with the name of the new window, scroll with either 'yes', 'no' or 'auto'
// WORKS:	ie4+, ns4+, opera5

	function spawnWindow(desktopURL,windowName,width,height,scroll) {
 		if (Macintosh) {
 			if (browserNameLong == "IE4") {
				newheight = parseInt(height + 17);
			}
			else if (browserNameLong == "IE4.5") {
				newheight = parseInt(height + 17);
			}
			else {
				newheight = height;
			}
 		}
 		else { newheight = height; }	
 		window.open(desktopURL, windowName, "toolbar=no,location=no,status=yes,menubar=no,scrollbars="+scroll+",width="+width+",height="+newheight+",resizable=no" );
	}

	
// STANDARD DROPDOWN SCRIPT (SAME FRAME/WINDOW)
// USAGE:	<form name="form">
//			<select name="site" size="1" onchange="javascript:standardwarp(this)">
//			<option value="">this is my dropdown header
//			<option value="page1.htm">page 1
//			<option value="page2.htm">page 2
//			<option value="page3.htm">page 3
//			</select>
//			</form>
// WORKS:	ie4+, ns4+, opera5


	function standardwarp(dropdown) {
	var tempURL = dropdown.options[dropdown.selectedIndex].value;
		if(tempURL!="") {
			document.location.href = tempURL;
		}
	}


// REMOVES THE LINK BORDER IN IE5/NS6
// original code by evil@chelu.ro
//
// USAGE:	getLinksToBlur();
// NOTES:	call it from within the preload function
// WORKS:	ie5+, ns6+, opera5+

	function unblur() {
		this.blur();
	}

	function getLinksToBlur() {
		if (!document.getElementById) return
		links = document.getElementsByTagName("a");
		for(i=0; i<links.length; i++) {
			links[i].onfocus = unblur
		}
	}


// THE NS CSS RELOAD
// original code from http://www.webmonkey.com/
//
// USAGE:	call it from within the html page
// NOTES:	place on frameset page if used on a frames-based website
// WORKS:	ns4

	function MM_reloadPage(init) {
		if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
		else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
	}
			
	//MM_reloadPage(true);


// DOM / GET PROPERTY
// original code from http://www.alistapart.com/
//
// NOTES:	given an id and a property (as strings), return the given property of that id.
// WORKS:	ie5+, ns6+, opera5+

	function getIdProperty(id,property) {
		var styleObject = document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
				if (styleObject[property]) {
					return styleObject[ property ];
				}
			}
		return (styleObject != null) ?
		styleObject[property] :
		null;
	}


// DOM / SET PROPERTY
// original code from http://www.alistapart.com/
//
// NOTES:	given an id and a property (as strings), set the given property of that id to the value provided.
// WORKS:	ie5+, ns6+, opera5+

	function setIdProperty(id,property,value) {
		var styleObject = document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
			styleObject[ property ] = value;
		}
	}

// does the same, but within a frame

	function setIdPropertyParent(id,property,value) {
		var styleObject = parent.document.getElementById( id );
		if (styleObject != null) {
			styleObject = styleObject.style;
			styleObject[ property ] = value;
		}
	}


// DOM / MASTER MOVE FUNCTION
// original code from http://www.alistapart.com/
//
// USAGE:	used within other functions
// NOTES:	If additive is true, then move it by xValue dots horizontally and yValue units vertically.
//			If additive is false, then move it to (xValue, yValue).
// WORKS:	ie5+, ns6+, opera5+

	function generic_move(id,xValue,yValue,additive ) {
		var left = parseInt(getIdProperty(id, "left"));
		var top = parseInt(getIdProperty(id, "top"));
		if (additive) {
			setIdProperty(id,"left",left + xValue);
			setIdProperty(id,"top",top + yValue);
		}
		else {
			setIdProperty(id,"left",xValue);
			setIdProperty(id,"top",yValue);
		}
	}

// NON-DOM / MASTER MOVE FUNCTION
// USAGE:	used within other functions
// NOTES:	If additive is true, then move it by xValue dots horizontally and yValue units vertically.
//			If additive is false, then move it to (xValue, yValue).
// WORKS:	ie4, ns4

	function generic_move_nondom(id,xValue,yValue,additive) {
		// gets the id
		if (browserName == "NS") {
			var thisLayer = document.layers[id];
		}
		else {
			var thisLayer = document.all[id].style;
		}
		// gets the present values
		thisLayer.xpos = parseInt(thisLayer.left);
		thisLayer.ypos = parseInt(thisLayer.top);
		// move to, or move by?
		if (additive) {
			thisLayer.xpos += xValue;
			thisLayer.ypos += yValue;
			thisLayer.left = thisLayer.xpos;
			thisLayer.top = thisLayer.ypos;
		}
		else {
			thisLayer.left = xValue;
			thisLayer.top = yValue;
		}
	}


// MOVE TO - SHORTHAND
// original code from http://www.alistapart.com/
//
// USAGE:	move('yourdiv',100,100,true);
//			move('yourdiv',100,100,false);
// WORKS:	ie4+, ns4+, opera
	
	function move(id,x,y,addit) {
		if (browserNew) {
			generic_move(id,x,y,addit);
		}
		else {
			generic_move_nondom(id,x,y,addit);
		}
	}


// DOM / CLIPPING FUNCTION
// USAGE:	clipTo('mydiv',0,200,200,0);
// NOTES:	Clip a given id to a given size (top, right, bottom, left)
// WORKS:	ie5+, ns6+, opera5+

	function clipTo(id,top,right,bottom,left) {
		if (browserNew) {
			newClip = "rect(" + top + "px, " + right + "px, " + bottom + "px, " + left + "px)";
			setIdProperty(id,"clip",newClip);
		}
	}


// HIDE AND SHOW LAYERS (ON THE SAME PAGE)
// USAGE:	show('layername'); hide('layername');
// WORKS:	ie4+, ns4+, opera

	function hide(id) {
		if (browserNew) {
			setIdProperty(id,"visibility","hidden");
		}
		else {
			if (browserName == "NS") { document.layers[id].visibility = "hide"; }
			else { document.all[id].style.visibility = "hidden"; }
		}
	}

	function show(id) {
		if (browserNew) {
			setIdProperty(id,"visibility","visible");
		}
		else {
			if (browserName == "NS") { document.layers[id].visibility = "show"; }
			else { document.all[id].style.visibility = "visible"; }
		}
	}


// HIDE AND SHOW LAYERS (IN ANOTHER FRAME)
// USAGE:	showToo('layername'); hideToo('layername');
// WORKS:	ie4+, ns4+, opera

	function showToo(id) {
		if (browserNew) {
			setIdPropertyParent(id,"visibility","visible");
		}
		else {
			parent.document.all[id].style.visibility = "visible";
		}
	}

	function hideToo(id) {
		if (browserNew) {
			setIdPropertyParent(id,"visibility","hidden");
		}
		else {
			parent.document.all[id].style.visibility = "hidden";
		}
	}

// DYNAMICALLY UPDATES THE CONTENTS OF A DIV
// USAGE:	writeNewDiv('thisdiv');
//			replace 'newCnt' with the new contents of the div
// WORKS:	ie4+, ns4+

	//var newCnt = '<div style="position: absolute;">hello - i am the new content</div>';
	//var theDelay = true;

	function writeNewDiv(id) {
		if (browserNew) {
			document.getElementById(id).innerHTML=newCnt;
		}
		else {
			if (browserName == "NS") {
				document.layers[id].document.write(newCnt);
				document.layers[id].document.close();
			}
			else {
			//IE4 crashes if you set the innerhtml without a delay, strange
				if (browserNameLong == "IE4") {
					if (theDelay == true) {
						thisID = id;
						setTimeout("writeNewDiv(thisID);",100);
						theDelay = false;
					}
					else {
						document.all[id].innerHTML=newCnt;
						theDelay = true;
					}
				}
				else {
					document.all[id].innerHTML=newCnt;
				}
			}
		}
	}


// FRAMESET FORCER
// original code from http://www.zeldman.com/
//
// USAGE:	use it within the <head> and </head>
// NOTES:	replace the url with your own frame url
// WORKS:	ie4+, ns4+, opera

	//if (top == self) self.location.href = "frameset.htm";


// GETS THE SIZE OF A BROWSER WINDOW
// USAGE:	writeNewDiv('thisdiv');
// NOTES:	call it after the window has loaded (important!)
// RESULT:	aWidth = the width of the window
//			aHeight = the height of the window
// WORKS:	ie4+, ns4+

	function getWindowSize() {
		if ((document.layers||document.getElementById)&&(!document.all)) {
			aWidth = innerWidth;
			aHeight = innerHeight;
		}
		if (document.all) {
			aWidth = document.body.clientWidth;
			aHeight = document.body.clientHeight;
		}
	}


// RANDOM NUMBER GENERATOR
// USAGE:	var ranNumber = 0+randNum(40);
// NOTES:	call it from within the main html page
// WORKS:	ie4+, ns4+, opera

	function randNum (num) {
		var now = new Date();
		var rand = Math.round(num * Math.cos(now.getTime()));
		if (rand < 0) rand = - rand; 
		if (rand == 0) rand++;
		return rand;
	}
	
// SWOOSH IN A GIVEN DIRECTION
// USAGE:	swoosh( layerName, Direction=left/right/up/down, Distance, Rate=( >=2 pixels at a time, <2 accelerate ), TimeoutWait, 1, 1 )
// NOTES:	last three parameters in call should be 1

	function swoosh( layer, dir, x, rate, timeout, i, j ) {
		if ( rate >= 2 ) {
			j = rate;
		}
		else {
			j = Math.ceil( i < ( x / 2 ) ? ( j * rate ) : ( j / rate ) ) + 1;	// jump this much
			j = Math.ceil( ( j + i ) <= x ? j : ( j + i ) - x );				// jump the rest of the way if nearing the end
		}
		i += j;

		if ( i <= x ) {
			if ( dir == "left" )
				move( layer, ( -1 * Math.ceil( j ) ), 0, true );
			if ( dir == "right" )
				move( layer, ( 1 * Math.ceil( j ) ), 0, true );
			if ( dir == "up" )
				move( layer, 0, ( -1 * Math.ceil( j ) ), true );
			if ( dir == "down" )
				move( layer, 0, ( 1 * Math.ceil( j ) ), true );

			window.setTimeout( "swoosh( '" + layer + "', '" + dir + "', " + x + ", " + rate + ", " + timeout + ", " + i + ", " + j + " );", timeout );
		}
	}
	
// STICKY MENU
// USAGE:	menustick( FunctionToCall, id, action=true/false )
// NOTES:	settimeout for menus. use id to have more than one menu on a page

	var menuIDs = new Array();
	var menuPos = new Array();
	function menustick( func, id, action, time ) {
		if ( action ) {
			window.clearTimeout( menuIDs[ id ] );
			if ( !menuPos[ id ] ) {
				eval( func );
			}
			menuPos[ id ] = true;
		}
		else {
			menuIDs[ id ] = window.setTimeout( "menuPos[ " + id + " ] = false; " + ( menuPos[ id ] ? func : "" ), time );
		}
	}
	
// LLOYDS SPECIFIC FUNCTIONS

	function doPageFollow() {
		var el = document.all.callout;
		var topEdge = 268 + document.body.scrollTop;
		el.style.pixelTop = topEdge;
	}

	function menuOver() {
		menustick( "move('contactus',0,16,true);", 1, 1, 1 );
	}
	
	function menuOut() {
		menustick( "move('contactus',0,-16,true);", 1, 0, 1 );
	}
	
	function init() {
		createObject( "sites_lloyds_f1", "images/sites_lloyds.gif" );
		createObject( "sites_lloyds_f2", "images/sites_lloyds_f2.gif" );
		createObject( "sites_club_f1", "images/sites_club.gif" );
		createObject( "sites_club_f2", "images/sites_club_f2.gif" );
		createObject( "sites_sandals_f1", "images/sites_sandals.gif" );
		createObject( "sites_sandals_f2", "images/sites_sandals_f2.gif" );
		createObject( "sites_breakaway_f1", "images/sites_breakaway.gif" );
		createObject( "sites_breakaway_f2", "images/sites_breakaway_f2.gif" );

		createObject( "nav_contact_f1", "images/nav_contact.gif" );
		createObject( "nav_contact_f2", "images/nav_contact_f2.gif" );

		preloadFlag = true;

		if ( document.all != null ) {
			window.onscroll = doPageFollow;
			window.onresize = doPageFollow;
		}
	}
