// JavaScript Document
addLoadListener(loadFlash);
addLoadListener(startList);
addLoadListener(externalLinks);

function addLoadListener(fn){
	if (typeof window.addEventListener != 'undefined'){
		window.addEventListener('load', fn, false);
	}else if (typeof document.addEventListener != 'undefined'){
		document.addEventListener('load', fn, false);
	}else if (typeof window.attachEvent != 'undefined'){
		window.attachEvent('onload', fn);
	}else{
		var oldfn = window.onload;
		if (typeof window.onload != 'function'){
			window.onload = fn;
		}else{
			window.onload = function(){
				oldfn();
				fn();
			};
		}
	}
}
function loadFlash(){
	if(document.getElementById("flashContent")){
		var flashDiv = document.getElementById("flashContent");
		var fc = "<object type='application/x-shockwave-flash' data='Images/flotech.swf' width='750' height='200' id='FlotechMain'>\n";
		fc += "<param name='movie' value='Images/flotech.swf' />\n";
		fc += "<param name='allowScriptAcess' value='sameDomain' />\n";
		fc += "<param name='quality' value='best' />\n";
		fc += "<param name='scale' value='noScale' />\n";
		fc += "<param name='salign' value='TL' />\n";
		fc += "<param name='wmode' value='transparent' />\n";
		fc += "</object>";
		flashDiv.innerHTML = fc;
	}
}
function startList(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav_248770");
		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", "");
				}
			}
		}
 	}
}
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"; 
 } 
} 

//Slideshow - Home Page
$(function(){
	im = shuffle([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]);
	//always start on image no 1
	images = "<img src='/Images/slideshow/homegallery_"+im[0]+".jpg' />\n";
	//randomise the rest
	for(i=1;i< 20; i++){
		images += "<img src='/Images/slideshow/homegallery_"+im[i]+".jpg' />\n";	
	}
	$(".imageSlider").html(images).cycle({
		speed:    1100, 
    	timeout:  4500 	
	});
});

shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};


