
//***************** Slide *************************	

/* Slide object
 * 'DivsContainer' - The div that contain all the slides
 * 'SlideArray' -  array of divs to change
 * 'TimeOutInMillSec' - timeout in millseconds
 * 'IntervalInMillSec' - intterval in millseconds
 * 'CurrentIndex' - current index of  dispay div
 * 'ObjectName' - name(id) of slide object
*/
function Slide(DivsContainer, SlideArray, TimeOutInMillSec, IntervalInMillSec, CurrentIndex, ObjectName)
{
	if( document.getElementById(DivsContainer) == null )
		return;
	this.Container = document.getElementById(DivsContainer);
	this.SlideArray=SlideArray;
	this.TimeOut=null;
	this.TimeOutInMillSec=TimeOutInMillSec;
	this.Interval=null;
	this.IntervalInMillSec=IntervalInMillSec;
	this.CurrentIndex=CurrentIndex;
	this.ObjectName = ObjectName;	
	
	var selfSlideObj = this;
	
	//destractor for current object
	this.cleanUp = function()
    {
        selfSlideObj = null; 
    }	
	addUnLoadEvent(this.cleanUp);
	
	
	//display div with current index and set interval
	
	this.startSlide=function(){

		if(this.SlideArray!=null)
		{
			for(i=0; i<this.SlideArray.length; i++)
			{
				elm=document.getElementById(this.SlideArray[i]);
				if(elm!=null)
				{
					if(i==this.CurrentIndex){
						elm.style.display="block";
						elm.style.visibility = "visible";
						}
					else{
						elm.style.visibility = "hidden";
						elm.style.display="none";
						}
				}
			}
			this.restartInterval();
		}
	}


///This method invoke when the time out for the manual slide move ended
    this.restartInterval = function () {
    
	if(this.SlideArray!=null)	{
		
		if(this.SlideArray.length>1)
		{
			//Clear the time out if needed
			if(this.TimeOut!=null) {
				window.clearTimeout(this.TimeOut);
			}
			
			//Restart the timeout					
			func=this.ObjectName + ".moveMagazineAuto(1)";
			this.Interval =setInterval(func,this.IntervalInMillSec);
		}		
	}
}


///This method move the slide
   this.moveMagazineAuto=function (direction) {
   	if(direction==null)
		direction=1;		 
	///Validate array
	if(this.SlideArray==null)
		return;
	var targetIndex=0;
	if(direction==-1 && this.CurrentIndex==0)
	{
		targetIndex = this.SlideArray.length-1;	
	}
	else 
	{
		if(direction==1 && this.CurrentIndex==this.SlideArray.length-1)
			targetIndex = 0;
		else
			targetIndex = this.CurrentIndex + direction;
	}
		
	
	if(document.getElementById(this.SlideArray[targetIndex])!=null && document.getElementById(this.SlideArray[this.CurrentIndex])!=null) {
		if(detectBrowser()) 
		{
			Switch(this.SlideArray[targetIndex],this.SlideArray[this.CurrentIndex],this.Container);
		}

		else
		{
			
			var strIdL1=""+this.SlideArray[targetIndex];					
			var strIdL2=""+this.SlideArray[this.CurrentIndex];	
			document.getElementById(strIdL1).style.display="block";				
			document.getElementById(strIdL1).style.visibility = "visible";									
			blendimage(strIdL1,strIdL2,600);	
			document.getElementById(strIdL2).style.display="none";					
		}
		this.CurrentIndex=	targetIndex;		
	}
}
	
	///This method invoke when the user move the magazine by manual
	this.moveMagazine= function (direction) {
	
		///Rotate the magzine
		this.moveMagazineAuto(direction);
		///Clear interval if needed
		if(this.Interval!=null)
			window.clearInterval(this.Interval);
		///Set time out for restart interval
		func=this.ObjectName + ".restartInterval()";
		this.TimeOut = window.setTimeout(func, this.TimeOutInMillSec);
		this.restartInterval();
	}
	
	this.stopMagazine = function (){
	
	if(this.Interval!=null) {
		window.clearInterval(this.Interval);
	}
			
} 
	
}//End of Slide




function Switch(ToShow,ToHide, filterContainer) {

	var DivToShow=document.getElementById(ToShow);
	var DivToHide=document.getElementById(ToHide);
    filterContainer.filters[0].Apply();
    DivToHide.style.visibility = "hidden";
	DivToHide.style.display = "none";
    DivToShow.style.display = "block";
    DivToShow.style.visibility = "visible";
	filterContainer.filters[0].Play();	
		
} 	
function blendimage(divid1, divid2, millisec) {
	var speed = Math.round(millisec / 100); 
	var timer = 0; 
	for(i = 0; i <= 100; i++) { 
		setTimeout("changeOpac(" + i + ",'" + divid1 + "','"+ divid2+ "')",(timer * speed)); 
		timer++; 
	} 
}
function detectBrowser() {
	var browser=navigator.appName
	if (browser=="Microsoft Internet Explorer")
		return true;
	else
		return false;
}
function changeOpac(opacity, id1,id2) { 
	var object1 = document.getElementById(id1).style; 
	var object2 = document.getElementById(id2).style;
	object1.opacity = (opacity / 100);
	object2.opacity = 0; 
}

