// JScript source code
var STP=new Array();   //static show picture time spam
var FTP=new Array();   //fading out time spam
var Tstep=new Array();   //every step time spam
var TotalStep=new Array();  //total steps for one picture
var Trans=new Array();  

var opacityValues = new Array();  //intial the first step, more than 100, igore the transparent 
var maxLinks =new Array();
var startValue = 1;
var cdiv=new Array();
var maxHeight=new Array();
var maxWidth=new Array();
var minHeight=0;
var transitionType = 'fade';

//test feild
//testval=document.getElementById("txtS");  
//testC=document.getElementById("txtC");
isIE = false; 
navVer = navigator.appVersion; 
ver = parseFloat(navVer); 
IEPos = navVer.indexOf('MSIE'); 
	    if (IEPos !=-1) { 
  	        isIE = true; 
  	        ver = parseFloat(navVer.substring(IEPos+5,navVer.indexOf(';',IEPos))); 
	    }
isIE5up = (isIE && ver >= 5);

//var transitionType = 'fade';
//var transitionType = 'slide';

function determineTransition() {
	var ran_number=Math.floor(Math.random()*2); 
	
	if (ran_number == 0) {
		transitionType = 'fade';
	}
	else if (ran_number == 1) {
		transitionType = 'slide';
	}
}

var jumpTimeout;
var tempLoc;
var tempNumc;
var gobackafter = false;			
function jjump(location,numc,direction) {
	clearTimeout(jumpTimeout);
	
    if (transitionType == 'fade') {
		clearTimeout(Trans[location]);
		if(numc>1){
			cdiv[location]=numc-1;   
		}
		else
		{
			cdiv[location]=maxLinks[location];
		}
		
		for (i=1;i<=maxLinks[location];i++){
			  document.getElementById('link' + location +'_'+ i ).style.zIndex = 200-i;
			  //document.getElementById('bt'+location +'_'+ i).style.backgroundImage="url(/images/core/no_bg.gif)";
			   offTurn('bt'+location +'_'+ i, i);//Commented out by DM - only showing play,next,pause buttons
			   if(i==numc){
			  document.getElementById('link' + location +'_'+ i ).style.zIndex = 200- i + 10;
			   //document.getElementById('bt'+location +'_'+ i).style.backgroundImage="url(/images/core/no_bg_highlight.gif)";
			   onTurn('bt'+location +'_'+ i, i);//Commented out by DM - only showing play,next,pause buttons
			  }
			  if(i>cdiv[location])
			  {
			   setTransparent(i,TotalStep[location],location);
			  }
			 else
			 {
				setTransparent(i,0,location);
			 } 
								 
		}
		opacityValues[location] = 1 ;
		Trans[location]= setTimeout("nextImage("+cdiv[location] + "," + location +")",Tstep[location]);
	}
	else if (transitionType == 'slide') {
		
		if (numc == currentImage) {return;}
		
		
		if (isSliding) {
			tempLoc = location;
			tempNumc = numc;
			if (direction == "back") {	
				gobackafter = true;
			}
			jumpTimeout = setTimeout("jjump(tempLocation,tempNumc)", 100);
		}
		else {
			clearTimeout(incSlideTimeout);
			
			for (i=1; i<=maxLinks[location]; i++) {
				offTurn('bt'+location +'_'+ i, i);	//Commented out by DM - only showing play,next,pause buttons
			}
			
			onTurn('bt'+location +'_'+ numc, numc); //Commented out by DM - only showing play,next,pause buttons
			//alert(currentImage + ',' + numc);
			if (gobackafter == true) {direction = "back";gobackafter = false; numc = null;}
			
			if (direction == "back") {
				tempDirection = direction;
				nextSlide(currentImage, location, 0, numc,tempDirection);
			}else {
				nextSlide(currentImage, location, 0, numc);
			}
		
		}
	}
} 

function setTransparent(adiv,tVal,location)  //set the transparent of a div
    {
     if(document.getElementById('link'+ location + '_'+adiv)!=null)
     {
        if(isIE5up){
            document.getElementById('link'+ location + '_'+adiv).filters[0].opacity = tVal;                   
        }else{
            document.getElementById('link'+ location + '_'+adiv).style.MozOpacity = tVal/100;         		   
		    document.getElementById('link'+ location + '_'+adiv).style.opacity  = tVal/100;
		    document.getElementById('link'+ location + '_'+adiv).style.KhtmlOpacity = tVal/100;
        }
    }
    }
    
function setTransparent1(adiv,tVal,location)  //set the transparent of a div
    {
     if(document.getElementById(adiv)!=null)
     {
        if(isIE5up){
            document.getElementById(adiv).filters[0].opacity = tVal;                   
        }else{
            document.getElementById(adiv).style.MozOpacity = tVal/100;         		   
		    document.getElementById(adiv).style.opacity  = tVal/100;
		    document.getElementById(adiv).style.KhtmlOpacity = tVal/100;
        }
    }
    }
    
function isPause(location){
    if (document.getElementById("img" + location + "_pause").src.indexOf("play") > 0)
    {
        return true;
    }else
    {
        return false;
    }
}
function jpause(location){
    if(maxLinks[location]==null){return false;}
     clearTimeout(Trans[location]);
	 clearTimeout(nextSlideTimeout);
	 //alert('');
    if(isPause(location))
    {
		//alert('is paused');
        document.getElementById("img" + location + "_pause").src = "images/core/slide_pause.gif"; 
		if (transitionType == 'fade') {
        	Trans[location]= setTimeout("nextImage("+cdiv[location] + "," + location +")",Tstep[location]); 
		} else if (transitionType == 'slide') {
			
			tempValue = currentImage;
			tempLocation = location;
			tempNextImage = nextImageAfterPause;
			nextSlideTimeout = setTimeout("nextSlide(tempValue, tempLocation, 0, tempNextImage)", 2000);
		}
		
    }
    else
    {       
		//alert('not paused');
        document.getElementById("img" +location + "_pause").src="images/core/slide_play.gif";       
    }
}

function jcontinue(location){
        if(maxLinks[location]==null){return false;}
        clearTimeout(Trans[location]);
        document.getElementById("img" + location + "_pause").src = "images/core/slide_pause.gif";         
        Trans[location]= setTimeout("nextImage("+cdiv[location] + "," + location +")",Tstep[location]);
}


	
/*
function jback(location){
    clearTimeout(Trans[location]);   
    document.getElementById('link' + location +'_'+ cdiv[location] ).style.zIndex=200-cdiv[location];
    setTransparent(cdiv[location],100,location);
    //document.getElementById('bt'+location +'_'+ cdiv[location]).style.backgroundImage="url(/images/core/no_bg.gif)";
    offTurn('bt'+location +'_'+ cdiv[location]);
  
    if(cdiv[location]>1){
        cdiv[location]=cdiv[location]-1;
        document.getElementById('link' + location +'_'+ cdiv[location]).style.zIndex=200-cdiv[location];
        setTransparent(cdiv[location],100,location);

         opacityValues[location] =TotalStep[location];
    }
    else{      
        cdiv[location]=maxLinks[location]-1;
        opacityValues[location] =1;
    }
   //document.getElementById('bt'+location +'_'+ cdiv[location]).style.backgroundImage="url(/images/core/no_bg_highlight.gif)";
   onTurn('bt'+location +'_'+ cdiv[location]);
  
   //testC.value=opacityValue + "," + cdiv;   
    Trans[location]= setTimeout("nextImage("+cdiv[location]+ "," + location +")",Tstep[location]);
    
}
*/
function jback(location){
    clearTimeout(Trans[location]);

	var prevImageNo = currentImage - 1;
	if (prevImageNo < 1) {prevImageNo = maxLinks[location];}
    jjump(location,prevImageNo,'back');
}

function jnext(location){
    clearTimeout(Trans[location]);
    //setTransparent(cdiv[location],0,location);    
    //opacityValues[location] =1 ; 
	var nextImageNo = currentImage+ 1;
	if (nextImageNo >maxLinks[location]) {nextImageNo = 1;}
	//alert(nextImageNo + "," + maxLinks[location]);
    //Trans[location]= setTimeout("nextImage("+nextImageNo+ "," + location +")",0);
    jjump(location,nextImageNo);
}
    
function nextImage(value,location){
   
    if(value==0){value=1;}
    cdiv[location]=value;     
    opacityValues[location] =opacityValues[location] - 1;
    //document.getElementById("txtC").value=value + "," + opacityValues[1] + "," +cdiv[1]; 
    if(opacityValues[location]<= 25){
        setTransparent(value,opacityValues[location]*4,location);			
    }
    
    if (opacityValues[location] == 0){   
        document.getElementById('link' + location +'_'+ value).style.zIndex = 100-value; 
        opacityValues[location] = TotalStep[location]; 
        //document.getElementById('bt'+location +'_'+ value).style.backgroundImage="url(/images/core/no_bg.gif)";
        offTurn('bt'+location +'_'+ value, value); //OffTurn Commented out by DM - only showing play,next,pause buttons
        value= value+1;
		currentImage = currentImage+1
        if (value>maxLinks[location]){
        value=1;     
		currentImage=1
        }
        //document.getElementById('bt'+location +'_'+ value).style.backgroundImage="url(/images/core/no_bg_highlight.gif)";
        onTurn('bt'+location +'_'+ value, value); //OnTurn Commented out by DM - only showing play,next,pause buttons
        cdiv[location]=value;
        if (value==1){
            for (i=1;i<=maxLinks[location];i++){
                 document.getElementById('link' + location +'_'+ i ).style.zIndex = 200-i*4;
                
                 setTransparent(i,100,location);	
                 
            }
        }
        if (value==maxLinks[location]){   
            //alert(value);         
            for (i=1;i<maxLinks[location];i++){
                document.getElementById('link' + location +'_'+ i ).style.zIndex = 100-i*4;
                                
             }
             setTransparent(1,100,location); 
        }        
		
		
	}
    if(!isPause(location))
    {
	    Trans[location]= setTimeout("nextImage("+value + "," + location +")",Tstep[location]);
	}
}


var slideWidth = 554;
//important
var isSliding = false;
var nextSlideTimeout;
var incSlideTimeout;
var tempValue;
var tempLocation;
var tempPosition;
var tempDirection;
var slideDisplayTime = 5000;
var slidingSpeed = 100;
var currentImage;
var nextImageAfterPause;
function nextSlide(value, location, position, nextImage,direction){

	clearTimeout(incSlideTimeout);
	clearTimeout(nextSlideTimeout);
	
	if(!isPause(location) || isSliding) {
			
		currentImage = value;
		
		if (direction == "back") {
			if (nextImage == null) {
				nextImage = currentImage-1;
			}
			if (nextImage < 1) {
				nextImage = maxLinks[location];
			}
			
		} else {
			if (nextImage == null) {
				nextImage = currentImage+1;
			}
			if (nextImage > maxLinks[location]) {
				nextImage = 1;
			}
		}
			//getMyHTMLElement('holder_SEARCHBAR').style.color = '#ffffff';
			//getMyHTMLElement('holder_SEARCHBAR').innerHTML = nextImage;
			
		
		if (!isSliding) {		
			isSliding = true;
			if (direction == "back") {
				document.getElementById('link' + location +'_'+ nextImage).style.left = -slideWidth + "px";
				//alert('');
			}
		}
		
		var currentImagePos = parseInt(document.getElementById('link' + location +'_'+ currentImage).style.left);
		var nextImagePos = parseInt(document.getElementById('link' + location +'_'+ nextImage).style.left);
		var increment = 54.4; // changed from 90 - must divide evenly into slideWidth value
		//important
		var maxPosition;
		
		
		if (position < slideWidth) {
			
			if (direction == "back") {
				
				document.getElementById('link' + location +'_'+ currentImage).style.left = (currentImagePos + increment) + "px";
				document.getElementById('link' + location +'_'+ nextImage).style.left = (nextImagePos + increment) + "px";
				position += increment;
				
			} else {
				document.getElementById('link' + location +'_'+ currentImage).style.left = (currentImagePos - increment) + "px";
				document.getElementById('link' + location +'_'+ nextImage).style.left = (nextImagePos - increment) + "px";
				position += increment;
			}
			
			tempValue = currentImage;
			tempLocation = location;
			tempPosition = position;
			tempNextImage = nextImage;
			tempDirection = direction;
			incSlideTimeout = setTimeout("nextSlide(tempValue, tempLocation, tempPosition, tempNextImage, tempDirection)",slidingSpeed);
			
		}
		else {
	
			isSliding = false;
			
			offTurn('bt'+location +'_'+ value, value);//Commented out by DM - only showing play,next,pause buttons
			onTurn('bt'+location +'_'+ nextImage, nextImage);//Commented out by DM - only showing play,next,pause buttons
			
			currentImage = nextImage;
			
			if (currentImage>maxLinks[location]){
				currentImage=1;			
			}
			nextImage = currentImage+1;
			
			if (nextImage>maxLinks[location]){
				nextImage=1;			
			}
			
			for (i=1; i<=maxLinks[location]; i++) {
				
				if (i != currentImage) {
					document.getElementById('link' + location +'_'+ (i)).style.left = slideWidth + "px";
				}
			}
			
			tempValue = currentImage;
			tempLocation = location;
			tempNextImage = nextImage;
			
			if(!isPause(location)) {
				//alert(1);
				nextSlideTimeout = setTimeout("nextSlide(tempValue, tempLocation, 0, tempNextImage)", slideDisplayTime);
			}
			else {
				nextImageAfterPause = nextImage;	
			}
			
		}
	
	}// else {
		//alert('');
		//tempValue = currentImage;
		//tempLocation = location;
		//tempNextImage = nextImage;
		//nextSlideTimeout = setTimeout("nextSlide(tempValue, tempLocation, 0, tempNextImage)", slideDisplayTime);
			
	//}
	
}


function startFad(location,STPvalue, FTPvalue){
	
	//alert(location);
	clearTimeout(Trans[location]);
	//alert(location+ "," + STPvalue + "," + FTPvalue);
	maxHeight[location]=0;
	STP[location]=STPvalue;
	FTP[location]=FTPvalue;
	Tstep[location]=FTP[location]/25;  //every step time spam
	TotalStep[location]=(FTP[location]+STP[location])/Tstep[location];  //total steps for one picture
	cdiv[location]=0;   
	opacityValues[location] = TotalStep[location];     
	maxLinks[location]=document.getElementById( "maxval_"+ location).value;
	for(i=1;i<=maxLinks[location];i++){
		if(document.getElementById('link' + location +'_'+ i).offsetHeight>maxHeight[location])
		{
		maxHeight[location]=document.getElementById('link' + location +'_'+ i).offsetHeight;
		maxWidth[location]=document.getElementById('link' + location +'_'+ i).offsetWidth;
		}
	}
	for(i=1;i<=maxLinks[location];i++){
	   
	  //  document.getElementById('link' + location +'_'+ i).style.height="315px";
		document.getElementById('link' + location +'_'+ i).style.height="374px";
		
	}
	if(document.getElementById('num' + location +'_bar')!=null)
	{
		//document.getElementById('num' + location +'_bar').style.width= "760px";
	}
	
	if(document.getElementById('num' + location +'_cover')!=null)
	{
		document.getElementById('num' + location + '_cover').style.width = slideWidth + "px";
	}
	//document.getElementById('bt' +location +'_1').style.backgroundImage="url(/images/core/no_bg_highlight.gif)";
	onTurn('bt' +location +'_1', 1);
	setTransparent1('num' + location +'_cover',80,location);  
	
	if (transitionType == 'fade') {
		currentImage = startValue;
		Trans[location]= setTimeout("nextImage("+startValue + "," + location + ")",Tstep[location]);
		
	}
    else if (transitionType == 'slide') {
	
		for (i=1; i<=maxLinks[location]; i++) {
			if (i==1) {
				document.getElementById('link' + location +'_'+ i).style.left = 0 + "px";
			}
			else {
				document.getElementById('link' + location +'_'+ i).style.left = slideWidth + "px";
			}
		}
		currentImage = startValue;
		incSlideTimeout= setTimeout("nextSlide("+currentImage + "," + location + "," + 0 + ")",slideDisplayTime);
	
	}
	
	
}
    
function onTurn(id, i){
	//document.getElementById(id).style.fontWeight = "normal";
	//document.getElementById(id).style.color = "#DE2489";
	//document.getElementById(id).style.width = "15px";
	//document.getElementById(id).style.height = "15px";
	document.getElementById(id).src = "/images/core/slide_" + i + "_selected.gif";
	//document.getElementById(id).style.fontSize="8pt";
}

 function offTurn(id, i){
	//document.getElementById(id).style.fontWeight="normal";
	//document.getElementById(id).style.color="#000000";
	//document.getElementById(id).style.width = "15px";
	//document.getElementById(id).style.height = "15px";
	document.getElementById(id).src = "/images/core/slide_" + i + ".gif";
	//document.getElementById(id).style.fontSize="8pt";
}


/* CODE FOR FADE IN BUTTONS ON HOVER */


 var buttonsOpacityTimeout;
 var slidebuttonsObjectTemp;
 var slidebuttonsDirectionTemp;
 var slidebuttonsOpacityTemp;
 var slidebuttonsVisible = false;
 var zoomButtonsOpacity = 0;
 var maxTransparency = 100;
function fadeObject(object, direction,value) {
	clearTimeout(buttonsOpacityTimeout);
	this.increment = 10;
	//zoomButtonsOpacity = value;
	this.slidebuttonsObject = getMyHTMLElement(object);
	slidebuttonsObjectTemp = object;
	slidebuttonsDirectionTemp = direction;
	
	//getMyHTMLElement("holder_BASKETHEADER").innerHTML = value + "," + zoomButtonsOpacity;
	//alert(value);

		this.isfading = true;
		if (direction == "in") {
		
			if (slidebuttonsVisible == true && zoomButtonsOpacity == maxTransparency) {
				return;}
			if (zoomButtonsOpacity < maxTransparency && ((maxTransparency - zoomButtonsOpacity) < this.increment) ) {
				zoomButtonsOpacity = maxTransparency;
				slidebuttonsVisible = true;
			}
			else if (zoomButtonsOpacity < maxTransparency) {
				zoomButtonsOpacity += this.increment;
				
			}
			
			if (zoomButtonsOpacity == maxTransparency) {
				this.isfading == false;
				 slidebuttonsVisible = true;
			}
			
		}
		else if (direction == "out") {
			
			if (zoomButtonsOpacity > 0 && zoomButtonsOpacity < this.increment) {
				zoomButtonsOpacity = 0;
				
			}
			else if (zoomButtonsOpacity > 0) {
				zoomButtonsOpacity -= this.increment;
			}
			
			if (zoomButtonsOpacity == 0) {
				slidebuttonsVisible = false;
				this.isfading == false;
				clearTimeout(buttonsOpacityTimeout);
			}
		}
		
		setOpacity(this.slidebuttonsObject, zoomButtonsOpacity);
		
		if (this.isfading == true) {
			buttonsOpacityTimeout = setTimeout("fadeObject(slidebuttonsObjectTemp, slidebuttonsDirectionTemp,this.opacity)",50);
		}
}

function setOpacity(object, value) {	
	object.style.opacity = value/100;
	object.style.mozOpacity = value/100;
	object.style.filter = "alpha(opacity=" + value + ")";
}

function showZoomButtons(object) {
	//alert(BROWSER_VER);
	if (detectBrowser() == "IE" && is_ie6 == false) {maxTransparency = 60;} else {maxTransparency = 100}
	clearTimeout(fadeZoomButtonsTimeout);
	if (zoomButtonsOpacity < maxTransparency) {
		clearTimeout(buttonsOpacityTimeout);
		fadeObject(object,'in',zoomButtonsOpacity);
	}
}

var fadeZoomButtonsTimeout;
var fadeZoomButtonsTempObject;
var fadeZoomButtonsTempDirection;
var fadeZoomButtonsTempValue;
function fadeZoomButtons(object,direction,value) {
	
	fadeZoomButtonsTempObject = object;
	fadeZoomButtonsTempDirection = direction;
	fadeZoomButtonsTempValue = value;
	fadeZoomButtonsTimeout = setTimeout("fadeObject(fadeZoomButtonsTempObject,fadeZoomButtonsTempDirection,fadeZoomButtonsTempValue);",500);
}


