//IE specific tarnsitions for nav
function addFilt(obj){
	//alert(obj);
	obj.style.backgroundColor="#FEEFD0";			
	//obj.style.filter="flipv()";
	}
function remFilt(obj){
	obj.style.backgroundColor="";
}

//pre-load images to browser

 if (document.images) {
var rewOn = new Image();
rewOn.src = "images/rew_on.gif";
var rewOff = new Image();
rewOff.src = "images/rew.gif";

var stopOn = new Image();
stopOn.src = "images/stop_on.gif";
var stopOff = new Image();
stopOff.src = "images/stop.gif";

var playOn = new Image();
playOn.src = "images/play_on.gif";
var playOff = new Image();
playOff.src = "images/play.gif";
}

/* rollover function */
function flipImages() {
  if (document.images) {
    for (var i=0; i<flipImages.arguments.length; i+=2) {
      document[flipImages.arguments[i]].src = eval(flipImages.arguments[i+1] + ".src");
    }
  }
}	

function closePopUpWindow(){
	if (window.openedWindow && !window.openedWindow.closed){
		window.openedWindow.close();
	}
}

function popUpWindow(theURL,winName,features) {
	//window.onunload = closePopUpWindow;
	//closePopUpWindow();
	features = (features) ? features : "resizable,width=300,height=300,left=350,top=180,screenX=350,screenY=180";
	winName = (winName) ? winName : "_win";	
	window.openedWindow = window.open(theURL,winName,features);
	window.openedWindow.focus();
	return false;
}

// JavaScript Document

function startList(){
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}

/* SLIDE SHOW STUFF */

//Allow IE4 to work with us.
 	if(!document.getElementById && document.all)
  document.getElementById = function(id) {return document.all[id];}


//slideshow constructor
function slideshow(objName){
	
	//author: jeremy.wray@bbc.co.uk
	//required properties (must be set by user)
	
	/*name of created slideshow object (enables multiple slideshows in one page)
	passed in createSlideShow constructor*/
	this.name = objName;
	//array of images used by slideshow
	this.images = [];		
	//path to images, to keep the images array above, shorter	
	this.image_path = "";
	//id of the image on the pgae
	this.img_tag_id = "";
	//id of the href on the pgae
	this.a_tag_id = "";
	//array of links used by slideshow
	this.links = [];
	//path to links, to keep the links array above, shorter	
	this.link_path = "";
	//array of alt tags used by slideshow
	this.alt_tags = [];
	
	
	
	//optional/default properties
	
	//aray of transitions, may be set for each image or one for all, the default here is a blend	
	this.transitions = ["blendtrans(duration=1.0)"];
	//speed at which frames change in ms, this is the default:
	this.speed = 2000;
	//slideshow loops by default otherwise plays once
	this.loop = true;		
	
	//non-user properties
	
	//image array index
	this.int_index_image = 0;
	//tansition array index
	this.int_index_transition = 0;
	//error message string placeholder
	this.str_err = "";
	//boolean for filters support (currently IE only) 
	this.supportsFilters = false;		
	//reference to setInterval
	this.interval_ref = "";
	
	//methods		
	
	//plays the slideshow forwards
	this.play = slideshowPlay;
	//plays the slideshow backwards
	this.reverse = slideshowReverse;
	//plays one frame forwards
	this.playOne = slideshowplayOne;
	//plays one frame backwards
	this.reverseOne = slideshowreverseOne;
	//plays one passed-in frame 
	this.playFrame = slideshowplayFrame;
	//stops the slideshow
	this.stop = slideshowStop;
	//handles transition of image/filter
	this.transition = slideshowTransition;
	//handles validation and error messages
	this.validation = slideshowValidation;
}

//slideshow methods

//start slideshow playing
function slideshowPlay(){
		
	//validate before attempting to play			
	if (! this.validation()){return false};
	//first stop running slideshow
	this.stop();
	//set playing
	//this.transition("play");		
	this.interval_ref = setInterval(this.name+".transition('play')" , this.speed);		
}

//start slideshow playing in reverse
function slideshowReverse(){	
		
	//validate before attempting to play			
	if (! this.validation()){return false};
	//first stop running slideshow
	this.stop();
	//set playing
	this.transition("playReverse");		
	this.interval_ref = setInterval(this.name+".transition('playReverse')" , this.speed);		
}

//start slideshow playing
function slideshowplayOne(){	
		
	//validate before attempting to play			
	if (! this.validation()){return false};
	//play one forward
	this.transition("play");		
}

//start slideshow playing in reverse
function slideshowreverseOne(){		

	//validate before attempting to play			
	if (! this.validation()){return false};		
	//play one back
	this.transition("playReverse");		
}

//play frame passed in by user
function slideshowplayFrame(intFrame){		
	
	//validate before attempting to play			
	if (! this.validation()){return false};	
	//set image index
	this.int_index_image  = intFrame;
	//set transition index
	this.int_index_transition = intFrame;
	//play passed-in frame
	this.transition("frame");		
}

//stop slideshow playing
function slideshowStop(){

	//clears interval if it exists
	this.interval_ref ? clearInterval(this.interval_ref) : '';
}

//end slideshow methods

//this changes the image and applies the transition
function slideshowTransition(dir){
	
	switch(dir){
	
	case "play": 
							
		//if not set to loop, stop show after it reaches end of show
		if (! this.loop){
			if (this.int_index_image >= this.images.length -1){
				//stop show
				this.stop();
				//exit function
				return;
				}
		}	
		
		//increment image index	
		this.int_index_image ++;
		//increment transition index
		this.int_index_transition ++;
				
		//if at end of images array, reset index
		if (this.int_index_image == this.images.length){				
			//reset image index
			this.int_index_image = 0;
		}
		//if at end of transitions array, reset index
		if (this.int_index_transition == this.transitions.length){
			//reset transition index
			this.int_index_transition = 0;
		}
					
		break;
		
	case "playReverse":
	
		//if not set to loop, stop show after it reaches end of show
		if (! this.loop){
			if (this.int_index_image <= 0){
				//stop show
				this.stop();
				//exit function
				return;
				}
		}
	
		//decrement image index	
		this.int_index_image --;
		//decrement tansition index	
		this.int_index_transition --;			
					
		//if beyond beginning (ie. playing backwards) of images array, reset counter
		if (this.int_index_image < 0){
			//reset image frame
			this.int_index_image = this.images.length -1;
		}
		//if at end of transitions array, reset index
		if (this.int_index_transition < 0){
			this.int_index_transition = this.transitions.length -1;
		}
		
		break;
		
	case "frame":	
			
		//check we have the image passed-in
		if (typeof this.images[this.int_index_image] == "undefined"){
			this.str_err += "Selected frame is out of range. ";
			this.validation();
			return false;
		}
		//check we have relevant transition
		if (typeof this.transitions[this.int_index_transition] == "undefined"){
			//if not set index to first transition
			 this.int_index_transition = 0;
		}			
		
		break;
	default: //otherwise
		
		break;
	}		
		
	//perform platform specific transitions/swaps
	
	if (this.supportsFilters){			
	//alert(this.image_path + this.images[this.int_index_image]);
		//select transition
		document.getElementById(this.img_tag_id).style.filter = this.transitions[this.int_index_transition];
		//apply transition
		document.getElementById(this.img_tag_id).filters.item(0).apply();
		//swap image
		document.getElementById(this.img_tag_id).src = this.image_path + this.images[this.int_index_image];
		
		//play filter
		document.getElementById(this.img_tag_id).filters.item(0).play();			
	}else{	
		//swap image	
		document.images[this.img_tag_id].src = this.image_path + this.images[this.int_index_image];			
	}		
	//all browsers
	
	//apply link
	if (document.getElementById(this.a_tag_id)){
		document.getElementById(this.a_tag_id).href = this.link_path + this.links[this.int_index_image];	
	}
		
	//do alt tag	
	if (this.alt_tags.length > 0){		
		document.getElementById(this.img_tag_id).alt = this.alt_tags[this.int_index_image];			
		document.getElementById(this.img_tag_id).title = this.alt_tags[this.int_index_image];
	}
	
	
	return true;
}

//fucntion to create slideshow object
function createSlideShow(name){
	eval("window."+name+" = new slideshow('"+name+"');");
	return eval(name);
}

//validate and check for errors
function slideshowValidation(){		
	//check for no image array or image tag id errors
	this.images.length < 2 ? this.str_err += "No images array defined or too few images in array. " : '';
	this.img_tag_id == "" ? this.str_err += "No image ID tag defined. " : '';
	
	//set properties for object support
	if (document.getElementById){		
		//check that image ID exists			
		if (document.getElementById(this.img_tag_id)){			
			////check that filters are supported
			if (typeof document.getElementById(this.img_tag_id).style.filter != "undefined"){
				this.supportsFilters = true;
			}
		}else{			
		//image ID error
		this.str_err += "No or incorrect ID defined in image tag or no image tag defined. ";
		}
	//no filters, but check image name exists
	}else if (! document.images[this.img_tag_id]){
	//image name error
	this.str_err += "No or incorrect NAME defined in image tag or no image tag defined. ";
	}		
	
	//show error alert if any
	if (this.str_err != ""){
		alert("Slideshow Error: " + this.str_err);
		this.stop();
	return false;
	}else{
		return true;
	}		
}

/* END SLIDESHOW STUFF */



//to stop stupid norton preventing debug	
window.onerror = "";
