// JavaScript Document


//broswer detection... specifically, we need to know if the user is running safari 2

// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

var is_mac    = (agt.indexOf("mac")!=-1);

var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_safari     = ((agt.indexOf("safari") != -1) && (agt.indexOf("opera") == -1));

var is_safari2 = (is_safari && (is_major == 2));

//end severly cut down broswer detection




//Start Functions from Greybox - height and width stuff
/****
Last Modified: 28/04/06 16:23:20

 GreyBox - The pop-up window thingie
   Copyright Amir Salihefendic 2006
 AUTHOR
   4mir Salihefendic (http://amix.dk) - amix@amix.dk
 VERSION
	 1.92
 LICENSE
  LGPL (read more in LGPL.txt)
 SITE
   http://amix.dk/greybox
****/

function GB_getWindowSize(){
	var window_width, window_height;
	if (self.innerHeight) {	// all except Explorer
		window_width = self.innerWidth;
		window_height = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		window_width = document.documentElement.clientWidth;
		window_height = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		window_width = document.body.clientWidth;
		window_height = document.body.clientHeight;
	}	
	return [window_width, window_height];
}


function positionRightVertically(elm, value) {
  elm.style.top = getScrollTop()+value+"px";
}

function getScrollTop() {
  //From: http://www.quirksmode.org/js/doctypes.html
  var theTop;
  if (document.documentElement && document.documentElement.scrollTop)
      theTop = document.documentElement.scrollTop;
  else if (document.body)
      theTop = document.body.scrollTop;
  return theTop;
}

//End Functions from Greybox - height and width stuff

//start MM functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//end MM functions


//start timer functions

var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 3
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        flphotoPopDown(1);
		lastButton = -1;
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}


//end timer functions




//movie name finder - for calls to actionscript functions
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

//top menu rollover functions
// if the flash is loaded, this passes an actionscript call to the flash
// if the flash is not loaded, it calls the MM swap image function.

var lastButton = -1

function flphotoPopUp(fadenumber) {
	if (thisMovie("dtsplash")) {
		goodToCall = true
		if ((lastButton == fadenumber) && (timerRunning = true)){
			goodToCall = false;
		}
		//initialise a timer, so that safari 2 doesn't keep calling the function
		if (goodToCall == true) {
			InitializeTimer();
			lastButton = fadenumber;
   	 		thisMovie("dtsplash").photoPopUp(fadenumber);
		}
	} else {
		var rolloverimage = "images/scriptgifs/roll" + fadenumber + ".gif";
		MM_swapImage('splashgif','',rolloverimage,1);
	}
}

function flphotoPopDown(fadenumber) {
	if (thisMovie("dtsplash")) {
			if (!is_safari2) {
    			thisMovie("dtsplash").photoPopDown(fadenumber);
				StopTheClock();
				lastButton = -1;
			}
	} else {
		MM_swapImgRestore();
	}
}



//function to change the color of the mast links from the flash movie

function linkhilite(targetlink) {
	 if(!document.getElementById(targetlink)){
		 return;
	 }
	
	//variables
	var linkToChange = document.getElementById(targetlink);
	
	//methods

	linkToChange.style.color = 'white';
	
}


function linklolite(targetlink) {
	 if(!document.getElementById(targetlink)){
		 return;
	 }
	
	//variables
	var linkToChange = document.getElementById(targetlink);
	
	//methods

		linkToChange.style.color = '';

}

//javascript redirect functiont to call from flash - this is to stop safari crashing on a getURL!

function redirectfunc(theurl) {
		window.location=theurl;
}


function flashredirect(theurl) {
		window.setTimeout=(redirectfunc(theurl),1000);
}



//end this crap

function toggleVis(elementId) {
		if(!document.getElementById(elementId)){
		 return;
	 }
	 
	 if (document.getElementById(elementId).style.display == "block") {
		 document.getElementById(elementId).style.display = "none";
	 } else {
		 document.getElementById(elementId).style.display = "block";
	 }
}

function toggleVisVis(elementId) {
		if(!document.getElementById(elementId)){
		 return;
	 }
	 
	 if (document.getElementById(elementId).style.visibility == "hidden") {
		 document.getElementById(elementId).style.visibility = "visible";
	 } else {
		 document.getElementById(elementId).style.visibility = "hidden";
	 }
}




//link overlays for photo pages
function initLinkOverlays() {
	//first get the window dimensions
	var windowsize_array = GB_getWindowSize();
	var centrepix = (windowsize_array[0]/2);
	
	//now work out top and left values for previous linkbox
	var previousTop = 160;
	var previousLeft = (centrepix - 300);
	
	//next box values
	var nextTop = 160;
	var nextLeft = centrepix + 118;
	
	//define objects
	var prevLayerObj = document.getElementById("previouslayer");
	var nextLayerObj = document.getElementById("nextlayer");
	
	//now set the top values
	positionRightVertically(prevLayerObj, previousTop) ;
	positionRightVertically(nextLayerObj, nextTop) ;
	
	//set left values
	prevLayerObj.style.left  = previousLeft+"px";
	nextLayerObj.style.left  = nextLeft+"px";
	
}

//position flash absolutely. This is so that it can go off the edges of a small screen
function initFlashPosition() {
	//first get the window dimensions
	var windowsize_array = GB_getWindowSize();
	var centrepix = (windowsize_array[0]/2);
	
	//now work out top and left values for previous linkbox
	var flashTop = 152;
	var flashLeft = (centrepix - 471);
	
	
	//define objects
	var FlashObj = document.getElementById("flashsplash");
	
	//now set the top values
	positionRightVertically(FlashObj, flashTop) ;
	
	//set left values
	FlashObj.style.left  = flashLeft+"px";
	
}

function initCrPosition(id,top,width) {
	
	//define objects
	var objToToggle = document.getElementById(id);
	
		//find element dimensions
		var objWidth = width;

		
		//get the window dimensions
		var windowsize_array = GB_getWindowSize();
		var centrepix = (windowsize_array[0]/2);
		
		//now work out top and left values for previous linkbox
		var elementTop = top;
		var elementleft = (centrepix - (objWidth /2) - 31);
		
		
		//now set the top values
		positionRightVertically(objToToggle, elementTop) ;
		
		//set left values
		objToToggle.style.left  = elementleft+"px";

}


//This function checkes whether the flash movie has loaded.
// If not, the gif images for the flipbook animation are preloaded.

function conditionalPreLoadImages() {
		if (!thisMovie("dtsplash")) {
			MM_preloadImages('images/scriptgifs/roll1.gif','images/scriptgifs/roll2.gif','images/scriptgifs/roll3.gif','images/scriptgifs/roll4.gif','images/scriptgifs/roll5.gif');
		}
}


//front page initialisation wrapper
function initFrontPage() {
		initFlashPosition(); 
		initCrPosition('copyright','157','310'); 
		conditionalPreLoadImages()
}
