﻿// Slide Show 

        function stoperror(){ return true;}
	    window.onerror=stoperror;
	    var slideShowSpeed = 5000;
		var crossFadeDuration = 1500;
		var MaxH = 136;
		var MaxW = 966;
		var Pic = new Array();
		var preLoad = new Array();
		var LoadAttempts = 10;
		var sID = "sImgx";
	    var sBasePath = "";   
        function $(v) { return(document.getElementById(v)); }
    	var CurrentImage = 0;
    	var bOddEven = true;
    	var tf1 = 0;
    	var tf2 = 0;
    	var WhatSlideShow = 1;
    	var h = 0;
    	var w = 0;
        
		Pic[0] = 'images/MainShort_r3_c2.jpg'		            
		Pic[1] = 'images/MainShort_r3_c2_2.jpg'		            
		Pic[2] = 'images/MainShort_r3_c2_3.jpg'	     
		//Pic[3] = '0702270806516picture-31_L.jpg '		            
		//Pic[4] = '0710162116271kenya_2007__4338_-_2007-10-01__L.jpg '
		            
	    preLoad[0] = new Image();
	    preLoad[0].src = sBasePath + Pic[0];
	    preLoad[0]["loaded"] = 0;
    	preLoad[0].onload = function() {this["loaded"] = 1;}
		
	    function zPreLoadImages() {
        	if (Pic.length > 1)	{
    	        for (var i = 1; i < Pic.length; i++) {	
    	            preLoad[i] = new Image();
    	            preLoad[i].src = sBasePath + Pic[i];
    	            preLoad[i]["loaded"] = 0;
    	            preLoad[i].onload = function() {this["loaded"] = 1;}
    	        }
    	    }
	    }
		
	  	function VerifyImage() {
	        if (preLoad[CurrentImage]["loaded"] == 0 && isNaN(preLoad[CurrentImage].width)) {
	            LoadAttempts--;
	            if (LoadAttempts < 1) {	                
	                LoadAttempts = 10;
	                clearTimeout(tf1);
	                tf1 = setTimeout("zLoadImage()",100);
                    return;
	            }
	            else {
	                clearTimeout(tf2);
	                tf2 = setTimeout("VerifyImage()",500); 
	            }
	        }
	        else {
	            LoadAttempts = 10;
	            GenHTM();
	        }
	    }
    	    
	    function opacity(id, opacStart, opacEnd, millisec) { 
            var speed = Math.round(millisec / 100); 
            var timer = 0; 
            if(opacStart > opacEnd) { 
                for(i = opacStart; i >= opacEnd; i--) { 
                    setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
                    timer++; 
                }
             } else if(opacStart < opacEnd) { 
                for(i = opacStart; i <= opacEnd; i++) 
                    { 
                    setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
                    timer++; 
                } 
            } 
        }
    	
	    function changeOpac(opacity, id) { 
           if (!$(id)) {
                clearTimeout(tf1);
                tf1 = setTimeout("zLoadImage()",100);
                return;
            }
            var o = $(id).style; 
            o.opacity = (opacity / 100); 
            o.MozOpacity = (opacity / 100); 
            o.KhtmlOpacity = (opacity / 100); 
            o.filter = "alpha(opacity=" + opacity + ")"; 
            if (opacity == 100) o.filter = null; 
        } 
		
        function NormalizeSize() {
	        var c = 1;
            if (w > MaxW) {
                c = MaxW / w;
                w =w * c;
                h = h * c;
                c = 1;
            } 
            if (h > MaxH) {
                c =MaxH / h;
                w =w * c;
                h = h * c;
            }
	        w = Math.round(w);
	        h = Math.round(h);  
	    }
		
	    function GenHTM() {
	        var timg = preLoad[CurrentImage];
            h = timg.height;
            w = timg.width;
            NormalizeSize();
	        var ph = Math.round((MaxW -w )/2);
	        var pv = Math.round((MaxH - h )/2);
	        sID = "sImg" + CurrentImage;
	        NewDiv = '<div style="padding-left:' + ph + 'px;padding-right:' + ph + 'px;padding-top:' + pv + 
				'px;padding-bottom:' + pv + 'px;"><img id="' + sID + '" src="' + timg.src + 
				'" border="0" align="absmiddle" height="' + h + '" width="' + w + '"></div>';
             if (bOddEven) {
	            $("IdivE").innerHTML = "";
	            $("IdivE").innerHTML = NewDiv;
	            $("IdivE").style.zIndex = 3;
                $("IdivO").style.zIndex = 2;
                opacity("IdivE",0,100,crossFadeDuration);
	            opacity("IdivO",100,0,crossFadeDuration);
	        }
	        else {
	            $("IdivO").innerHTML = "";
	            $("IdivO").innerHTML = NewDiv;
	            $("IdivO").style.zIndex = 3;
	            $("IdivE").style.zIndex = 2;
	            opacity("IdivO",0,100,crossFadeDuration);
	            opacity("IdivE",100,0,crossFadeDuration);
	        }
	        bOddEven = (bOddEven) ? false : true;
	        clearTimeout(tf1);
	        tf1 = setTimeout("zLoadImage()", (crossFadeDuration + slideShowSpeed));
	    }
    	
		
	    function zLoadImage() {
	        CurrentImage++;
	        if (CurrentImage > Pic.length -1) CurrentImage = 0;
	        VerifyImage(); 
	    }
    		    	    
	    function runSlideShow() {
            if (navigator.appVersion.indexOf("MSIE")!=-1)
            {
                var version = 0;
                var temp=navigator.appVersion.split("MSIE");
                version=parseFloat(temp[1]);
                if (version >= 4) 
                {
                    if (document.images.sImgx.style.filter) WhatSlideShow = 2; 
                }
                if (version >= 6) WhatSlideShow = 3;            
            }  
            if (WhatSlideShow == 1) {
                if (preLoad[0].width && $("tdzImg").innerHTML && $("divWrapper").style)
                {
                    if (preLoad[0].width > 1 && $("divWrapper").style.overflow) WhatSlideShow = 3;          
                }
            }
            
            if (WhatSlideShow == 3) {
                h = preLoad[0].height;
                w = preLoad[0].width;
                if (w > MaxW || h > MaxH) {
                    NormalizeSize();
                    $("tdzImg").innerHTML = '<img src="' + Pic[0] + '" border="0" height="' + h + '" width="' + w + '" />';
                }
                $("IdivE").style.display = "block";
                $("divWrapper").style.overflow="hidden";
                $("divWrapper").style.zIndex = "1";
                $("divWrapper").style.height="136px";
                $("divWrapper").style.width="966px";
            }
            $("divWrapper").style.display = "block";
            zPreLoadImages();
	        if (WhatSlideShow == 1) tf1 = setTimeout("SimpleSlide()",slideShowSpeed);
	        if (WhatSlideShow == 2) tf1 = setTimeout("SimpleSlideIE()",slideShowSpeed);
	        if (WhatSlideShow == 3) tf1 =  setTimeout("zLoadImage()",slideShowSpeed - 2500); 
          }
	    
 	    
 	    function SimpleSlideIE() {
		    CurrentImage++;
		    if (CurrentImage > Pic.length -1) CurrentImage = 0;
	    	document.images.sImgx.style.filter="blendTrans(duration=2)";
			document.images.sImgx.style.filter="blendTrans(duration=crossFadeDuration)";
			document.images.sImgx.filters.blendTrans.Apply();
			document.images.sImgx.src = preLoad[CurrentImage].src;
			document.images.sImgx.filters.blendTrans.Play();
			tf1 = setTimeout('SimpleSlideIE()', slideShowSpeed);
	    }
 	 	    
 	    function SimpleSlide() {
 	        CurrentImage++;
 	        if (CurrentImage > preLoad.length-1) CurrentImage = 0;
 	        if ($("tdzImg").innerHTML) // inner html helps some browsers render images sized correctly
 	        {
 	            $("tdzImg").innerHTML = "";
 	            var s = '<img border="0" src="' + Pic[CurrentImage] + '" />';
 	            $("tdzImg").innerHTML = s;
 	        }
 	        else {
 	             document.images.sImgx.src = Pic[CurrentImage];
 	        }
 	        setTimeout("SimpleSlide()",slideShowSpeed + 2000);
 	    }


