function imageholderclass(){
	this.over=new Array();
	this.down=new Array();
	this.src=new Array();
	this.store=store;
	
	function store(src, down, over){
		var AL=this.src.length;
		this.src[AL]=new Image(); this.src[AL].src=src;
		this.over[AL]=new Image(); this.over[AL].src=over;
		this.down[AL]=new Image(); this.down[AL].src=down;
	}
}

var ih = new imageholderclass();
var mouseisdown=0;

function preloader(t){
	for(i=0;i<t.length;i++){
		if(t[i].getAttribute('srcover')||t[i].getAttribute('srcdown')){
			
			storeimages(t[i]);
			var checker='';
			checker=(t[i].getAttribute('srcover'))?checker+'A':checker+'';
			checker=(t[i].getAttribute('srcdown'))?checker+'B':checker+'';
			
			switch(checker){
			case 'A' : mouseover(t[i]);mouseout(t[i]); break;
			case 'B' : mousedown(t[i]); mouseup2(t[i]); break;
			case 'AB' : mouseover(t[i]);mouseout(t[i]); mousedown(t[i]); mouseup(t[i]); break;
			default : return;			
			}
			
			if(t[i].src){t[i].setAttribute("oldsrc",t[i].src);}
		}
	}
}
function mouseup(t){
	var newmouseup;
	if(t.onmouseup){
		t.oldmouseup=t.onmouseup;
		newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("srcover");this.oldmouseup();}

	}
	else{newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("srcover");}}
	t.onmouseup=newmouseup;
}

function mouseup2(t){
	var newmouseup;
	if(t.onmouseup){
		t.oldmouseup=t.onmouseup;
		newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("oldsrc");this.oldmouseup();}
		}
	else{newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("oldsrc");}}
	t.onmouseup = newmouseup;
}

function mousedown(t){
	var newmousedown;
	if(t.onmousedown){
		t.oldmousedown=t.onmousedown;
		newmousedown=function(){if(mouseisdown==0){this.src=this.getAttribute("srcdown");this.oldmousedown();}}
	}
	else{newmousedown=function(){if(mouseisdown==0){this.src=this.getAttribute("srcdown");}}}
	t.onmousedown=newmousedown;
}

function mouseover(t){
	var newmouseover;
	if(t.onmouseover){
		t.oldmouseover=t.onmouseover;
		newmouseover=function(){this.src=this.getAttribute("srcover");this.oldmouseover();}
	}
	else{newmouseover=function(){this.src=this.getAttribute("srcover");}}
	t.onmouseover=newmouseover;
}

function mouseout(t){
	var newmouseout;
	if(t.onmouseout){
		t.oldmouseout=t.onmouseout;
		newmouseout=function(){this.src=this.getAttribute("oldsrc");this.oldmouseout();}
	}
	else{newmouseout=function(){this.src=this.getAttribute("oldsrc");}}
	t.onmouseout=newmouseout;
}

function storeimages(t){
	var s=(t.getAttribute('src'))?t.getAttribute('src'):'';
	var d=(t.getAttribute('srcdown'))?t.getAttribute('srcdown'):'';
	var o=(t.getAttribute('srcover'))?t.getAttribute('srcover'):'';
	ih.store(s,d,o);
}

function preloadimgsrc(){
	if(!document.getElementById) return;
	var it=document.getElementsByTagName('IMG');
	var it2=document.getElementsByTagName('INPUT');
	preloader(it);
	preloader(it2);
}

if(window.addEventListener){window.addEventListener("load", preloadimgsrc, false);} 
else{
	if(window.attachEvent){window.attachEvent("onload", preloadimgsrc);}
	else{if(document.getElementById){window.onload=preloadimgsrc;}}
}

function PageInit(url,Paras,timeLapse)
{
    SetURL(url);
    SetRotationHero(Paras,timeLapse);
}

//set categories url
function SetURL(url)
{        
    if ( document.getElementById("divNav") == null ) return ;        
    var info_rows = url.split("^^");
    
    var divString = "";
    divString += "<ul class='navList'>";
    for(var i=0;i<info_rows.length-1;i++)
    {
        info_cols = info_rows[i].split("~~");
                
        divString += "<li><a id='href"+i+"' onMouseover='onMouseover(this)' onmouseout='onMouseout()'  href='"+info_cols[1]+"'>"+info_cols[0]+"</a></li>";
    }     
    divString += "</ul>";   
    
    document.getElementById("divNav").innerHTML = divString; 
}

function onMouseover(obj)
{
    var as= document.getElementsByTagName("a");       
    for(var i=0,i=0;i<as.length;i++)
    {        
        if ( as[i].id.indexOf("href") > -1 )
        {                        
            if ( obj.id != as[i].id )
            {                            
                as[i].style.color = "#9A876D";
            }                            
        }
    }
}

function onMouseout()
{
    var as= document.getElementsByTagName("a");    
    for(var i=0,i=0;i<as.length;i++)
    {        
        if ( as[i].id.indexOf("href") > -1 )
        {                        
            as[i].style.color = "#42210B";
        }
    }    
}

var a;
var b=1;
var time=600;
var tm;

var pic = new Array(3);	       	
var titCon = new Array(3)	        	
var titConLink = new Array(3)

function SetRotationHero(Paras,timeLapse)
{
    for (var i=0;i<Paras.length;i++)
    {	            
        pic[i] = Paras[i][0];
        titConLink[i] = Paras[i][1];	            
    }	        
    
    time = 1000*parseInt(timeLapse);
}	    	 

function playPic(a)
{
    if(a>2){a=0};
    
    document.getElementById("txtIndex").value =a;
    
    var divbigPic = document.getElementById('bigPic');
    if ( divbigPic == null ) return ;	
    SetImgOff();	   
    SetImgOn(a); 		    
    divbigPic.innerHTML='<a href="'+titConLink[a]+'" ><img onMouseover=\'onImgMouseover()\' onMouseout=\'onImgMouseout('+a+')\' style=\'border:none\'  src="' + pic[a] + '" /></a>';
    document.getElementById("imgReadmore").onclick = openImgURL;
    		    
    b=a;
    a++;
    tm=setTimeout('playPic('+a+')',time);
	
}

function openImgURL()
{	
	var strHero = pic[parseInt(document.getElementById("txtIndex").value)];
	for(var i=strHero.length-1;i>-1;i--)
	{
		if ( strHero.substr(i,1) == "/")
		{
			strHero = strHero.substr(i+1,strHero.length-i-5);
			break;
		}		
	}								
	
	window.location = titConLink[parseInt(document.getElementById("txtIndex").value)];
}

function gotoAndPlay(a)
{
    clearTimeout(tm);
    
    var divbigPic = document.getElementById('bigPic');
    if ( divbigPic == null ) return ;	
    SetImgOff();
    SetImgOn(a);
    divbigPic.innerHTML='<a href="'+titConLink[a]+'" ><img onMouseover=\'onImgMouseover('+a+')\' onMouseout=\'onImgMouseout()\' style=\'border:none\'  src="' + pic[a] + '" /></a>';    
    document.getElementById("txtIndex").value =a;
    document.getElementById("imgReadmore").onclick = openImgURL;
    
    b=a;
    a++;
    //time=600;
    tm=setTimeout('playPic('+a+')',time);
}

function SetImgOff()
{
    if ( document.getElementById("imghref1") != null )
        document.getElementById("imghref1").src = "images/homepage/off1.gif";
        
    if ( document.getElementById("imghref2") != null )
        document.getElementById("imghref2").src = "images/homepage/off2.gif";
        
    if ( document.getElementById("imghref3") != null )
        document.getElementById("imghref3").src = "images/homepage/off3.gif";            
}

function SetImgOn(n)
{
    n+=1;
    var imghrefName = "imghref"+n;
    var imgName = "images/homepage/on"+n+".gif";    
    
    if ( document.getElementById(imghrefName) != null )
        document.getElementById(imghrefName).src = imgName;                
}

function onImgMouseover()
{
    clearTimeout(tm);
}

function onImgMouseout(b)
{  
    if ( b == null )
    {
        b = parseInt(document.getElementById("txtIndex").value);        
    }
    if ( b == null ) b=0;
    
    gotoAndPlay(b)
}