//---------------------------------------------------
//All for the image slideshow
//---------------------------------------------------
	
	var nPlus = 5;  //the % of fading for each step
    var speed = 100; //the speed in ms
    var pause = 5000; //how long should the current image stay without fading
	var nOpac = 0; //start opacity
	var opacity = 0;
	var images = new Array();
	var currentImg = 1;
	var prevImg = 0;
	
	var currentTimeout = 0;
	
	var imgbot;
	var imgtop;

	function startShow(){
		//test for new browsers
		if(document.getElementById){
			loadImages();
			if (images.length > 0){
				initShow();	
				loadFirstImgs();
				setTimeout('PauseFadeImg()',pause);
			}
		}
	}

	function loadFirstImgs(){
			imgbot = document.getElementById('imgbot');
			imgtop = document.getElementById('imgtop');
			//Set to random image
			var ran_unrounded = Math.random() * images.length;
			prevImg = Math.floor(ran_unrounded);
			//Set the top image to this random image		
			imgtop.src = images[prevImg];	
			//calculate what the nex image will be
			nextImage(); 		
	}
    
    function initShow(){
    		nOpac = 100;
			opacity = nOpac;
    }
    	
    function PauseFadeImg()	{
        //Set lower image to new image
        imgbot.src = images[currentImg];
    	setTimeout('FadeImg()',speed);
    }
    	
    function resetTopImg(){
    //Reset the opacity for top image to 100%
        initShow();
        setOpacity (imgtop); 
    }
    	
    function FadeImg(){
    	
        //lower opacity
        opacity = nOpac-nPlus;
        nOpac = opacity;
        
        //Set the timer to change the opacity
        currentTimeout = setTimeout('FadeImg()',speed);         

        if(opacity < 1){
        	clearTimeout(currentTimeout);
        	//The top image has opacity 0 now so; Set top image to lower image
        	//Both images are the same now
            nextImage();        	
            imgtop.src = images[prevImg];
            setTimeout('resetTopImg()',pause/2); 
            setTimeout('PauseFadeImg()',pause);   
        }
		//Lower opacity of top image
      	setOpacity (imgtop)
    }
       

    function nextImage(){
    	prevImg = currentImg;
    	currentImg = currentImg + 1;
    	if (currentImg > images.length -1){
    		currentImg = 0;
    	}
    	
    }

    function setOpacity (obj){
        obj.style.opacity = opacity / 100;
        obj.style.MozOpacity = opacity / 100;
        obj.style.filter = "alpha(opacity=" + opacity + ")"; 
    }
		
//---------------------------------------------------
//Correct the Housemenu active state and IE hover problems
//---------------------------------------------------

var strId = "HouseMenuNavCurrentItem"


	function setHouseMenuCurrentItem(){	
		var oMenu = document.getElementById (strId);

		if (undefined != oMenu){
			searchUp (oMenu);
		}
	}
		
	function searchUp(oNode){
	
			var oParent = oNode.parentNode;
			if (oParent.tagName != "DIV"){
				if (oParent.tagName == "LI"){
					var oChildren = oParent.childNodes;
					for (var i=0; i<oChildren.length; i++) {
						if (oChildren[i]){
							if (oChildren[i].tagName == "A"){
								oChildren[i].className = strId;
							}
						}
					}
					oParent.className += " ";
					oParent.className += strId;
				}
				searchUp(oParent);
				
			}
	}
	
	//Correct hover for IE 6
	function newHoverFix(menuId) {
		var oMenu = document.getElementById(menuId);
		if (undefined != oMenu){
		 //alert (menuId);
			var ieLIs = oMenu.getElementsByTagName('LI');
			for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]){
				ieLIs[i].onmouseover=function() {this.className+=" sfhover";}
				ieLIs[i].onmouseout=function() {this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), '');}
			}
		}	
	}
	
	
	function InitAll()
		{
		//alert("init");
		setHouseMenuCurrentItem();
		newHoverFix ("NavTabs00");
		newHoverFix ("HouseMenuNav");
		startShow();
		}
		
		//Add function to load event of page
		if (window.addEventListener){
			window.addEventListener("load", InitAll, false);
		}
		else if (window.attachEvent){
			window.attachEvent ("onload", InitAll)
		}

    
    
    

