
var docmousemove = document.onmousemove;
var __curobj;
var __isIE;
var __thumbsdiv="";
var __title="";

function ImageSlide(name,height, width)
{
    
    this.Name = name || "";
    
    if(this.Name == ""){
        alert("A name is required for the ImageList!");
        return;
    }
    
    
    this.Height = (height==undefined)? "300px" : height;
    this.Width = (width==undefined)? "100px" : width;
    this.Duration = 5;
    this.Interval = this.Duration * 1000;  
    this.ImageSrc = new Array(0);
    this.ThumbNail = new Array(0);
    this.ImageURL = new Array(0);
    this.ImageCaption = new Array(0);
    this.Visible = true;
    this.AutoSize = true;
    this.IntervalID = null;
    this.LoopCount = -1;
    this.CurrentImage = 0;
    this.CurrentLoop = 0;
    this.CaptionWidth = "200";
    this.Created = false;
    this.FilterIndex = 16;
    this.isIE = (navigator.appName == "Microsoft Internet Explorer");
    __isIE = this.isIE;
    this.CanTransform = true;
    this.SideBar = false;
    this.BottomBar = false;
    this.ClassPrefix = "";
    this.ImageChangeOnMouseOverThumbs = true;
    this.ShowThumbsCaption = true;
    this.NoTransfermation = true;
    this.BackgroundAnimation = "";
    this.BackgroundColor = "black";
    this.OnBeforeChange = "";
    this.OnAfterChange = "";
    
}

ImageSlide.prototype.AddImage = function(index,src,url,title, caption){
    var img = new Image();
	var regex =/[']/;
    img.src = src;
    img.alt = title;
    
    title = title.replace(regex, "\\'");
    this.ImageSrc[index] = img;
    this.ImageURL[index] = url;
    this.ImageCaption[index] = caption;
}

ImageSlide.prototype.AddThumbNail = function(index,src){
    var img = new Image();
    
    img.src = src;
    img.id = this.Name + "_thumbnail" + index; 
	
	this.ThumbNail[index] = img;    
}

ImageSlide.prototype.Show = function(size){
    
    this.AutoSize = (size=='auto');
    this.Created = true;
    
    document.write("<div oncontextmenu='return false;' onselectstart='return false' class='" + this.ClassPrefix + "maindiv' id='" + this.Name + "_maindiv'>");
   
    document.write("<table id='" + this.Name + "_maintable' cellpadding='0' cellspacing='0' style='border-collapse:collapse;'>");

    document.write("<tr><td>");

    document.write("<a id='" + this.Name + "_href' href='" + this.ImageURL[0] + "' onclick='" + this.Name + ".CanTransform=false;'>");
    
    document.write("<DIV id='" + this.Name + "_oTransContainer' STYLE='text-align:center;width:" + (this.Width) + "px;height:" + this.Height + "px;position:relative;Filter:" + ___SetTransition(this.FilterIndex, 2 ) + ";background-color:" + this.BackgroundColor + ";background-image:url(" + this.BackgroundAnimation + ");background-repeat:no-repeat;background-position:center' >");
    
    
	if(this.AutoSize){
        document.write("<img id='" + this.Name + "_img1' onmouseover='" + this.Name + ".CanTransform=false;' onmouseout='" + this.Name + ".CanTransform=true;'  src='" + this.ImageSrc[0].src + "' alt='" + this.ImageSrc[0].alt + "' style='visibility:hidden;border:0px;cursor:hand' onclick='" + this.Name + "_href.click()' >") ;
    }else{
        document.write("<img id='" + this.Name + "_img1' onmouseover='" + this.Name + ".CanTransform=false;' onmouseout='" + this.Name + ".CanTransform=true;'  src='" + this.ImageSrc[0].src + "' alt='" + this.ImageSrc[0].alt + "' width='" + this.Width + "' height='" + this.Height +"' style='visibility:hidden;border:0px;cursor:hand'  onclick='" + this.Name + "_href.click()'  >") ;
    }
   	
    document.write("</div>");
    document.write("</a>");
	document.write("</td>");
	
	document.write("<tr><td>");
	
	
    document.write("<div class='" + this.ClassPrefix + "captiondiv' style='width:" + (this.Width-10) + "'><a href='javascript:" + this.Name + "_href.click()' style='overflow:auto;width:" + (this.Width - 10) + "' id='" + this.Name + "_caption' class='" + this.ClassPrefix + "captionhref'  onclick=''></a><br/><div id='" + this.Name + "_captext' class='" + this.ClassPrefix + "captext' style='visibility:hidden;display:none;overflow:auto;width:" + (this.Width - 10) + "'>&nbsp;</div></div>" );
    
    
   
    document.write("</td></tr>");
    
    document.write("</table>");
    
    
    
    //////////bottombar////////////
    if(this.BottomBar  && this.ThumbNail.length>0){
			this.SideBar = false; 
			document.write("<div id='" + this.Name + "_bottombar' class='" + this.ClassPrefix + "bottombar' style='visibility:hidden;padding:1px;position:relative;background-color:transparent;width:" + (parseInt(this.Width) - 4) + "'>");
			for(i = 0; i < this.ThumbNail.length; i++){
				document.write("<img id='" + this.Name + "_thumbnail" + i + "' vspace='3' hspace='3' src='" + this.ThumbNail[i].src + "' class='" + this.ClassPrefix + "thumbnailnormal' onmouseover='___thumbsmouseover(\"" + this.Name + "\"," + i + ")' onmouseout='___thumbsmouseout(\"" + this.Name + "\"," + i + ")' onclick='___thumbsClick(\"" + this.Name + "\"," + i + ")'   />");
			}
			document.write("</div>");
	}
	/////////////////////////////////
	
	
	
    
    document.write("</div>");
    
    
    document.write("<div id= '" + this.Name + "_thumbsdiv' class='" + this.ClassPrefix + "thumbscaption' style='width:" + this.CaptionWidth + "px;z-index:2;visibility:hidden;display:none;position:absolute;'></div>");
    
  
}

ImageSlide.prototype.SetFilterIndex = function(index){
	index = index || 0;
	
	this.FilterIndex = (index % 29);
	
	var transdiv = document.getElementById(this.Name + "_oTransContainer");
	transdiv.style.filter = ___SetTransition(this.FilterIndex, 2);
	
}

ImageSlide.prototype.Start = function(interval,loopcount){
    this.Duration = (interval==undefined)?this.Duration:interval;
    this.Interval = this.Duration * 1000;
    this.LoopCount = (loopcount==undefined)?this.LoopCount:loopcount;
    this.IntervalID = window.setInterval('___Next("' + this.Name + '")',this.Interval);
    
    if(this.BottomBar){
		var objbbMainDiv = document.getElementById(this.Name + "_bottombar");
		var objmainDiv = document.getElementById(this.Name + "_maindiv");
		var objThumbImg = document.getElementById(this.Name + "_thumbnail0");
		
		if(__isIE){
			objbbMainDiv.style.posTop = 0 - parseInt(objThumbImg.currentStyle.height)- 15;
			objbbMainDiv.style.height = objThumbImg.style.height;
		}
		else{
			objbbMainDiv.style.top = 0 - parseInt(objThumbImg.height)- 15 + "px";
		}
		
		objbbMainDiv.style.visibility = "visible";	
    }
    
    
    if(this.SideBar){
		var objbbMainDiv = document.getElementById(this.Name + "_sidebar");
		var objmainDiv = document.getElementById(this.Name + "_maindiv");
		var objThumbImg = document.getElementById(this.Name + "_thumbnail0");
		var imgheight = 0;
		
		
		if(__isIE){
			
			if(this.BottomBar)		
				imgheight = parseInt(objThumbImg.currentStyle.height);
		
			objbbMainDiv.style.posTop = 0 - this.Height - imgheight;
			objbbMainDiv.style.left = this.Width - parseInt(objbbMainDiv.currentStyle.width);
		}
		else{
		
			if(this.BottomBar)		
				imgheight = parseInt(objThumbImg.height);
				
			objbbMainDiv.style.top =  0 - this.Height - imgheight + "px";
			objbbMainDiv.style.left = (this.Width - parseInt(objbbMainDiv.width) - 10 - imgheight) +  "px";
		}
		
		objbbMainDiv.style.visibility = "visible";	
    }
    
    
    ___ChangeImage(this.Name);
}


function ___SetTransition(index, duration){
    switch(index)
    {
    
        case 0: return "progid:DXImageTransform.Microsoft.Inset(Duration=" + duration + ")";break;
        case 1: return "progid:DXImageTransform.Microsoft.Blinds(Duration=" + duration + ",bands=20)"; break;
        case 2: return "progid:DXImageTransform.Microsoft.Checkerboard(Duration=" + duration + ",squaresX=20,squaresY=20)"; break;
        case 3: return "progid:DXImageTransform.Microsoft.Strips(Duration=" + duration + ",motion=rightdown)";break;
        case 4: return "progid:DXImageTransform.Microsoft.Barn(Duration=" + duration + ",orientation=vertical)";break;
        case 5: return "progid:DXImageTransform.Microsoft.GradientWipe(duration=" + duration + ")"; break;
        case 6: return "progid:DXImageTransform.Microsoft.Iris(Duration=" + duration + ",motion=out)"; break;
        case 7: return "progid:DXImageTransform.Microsoft.Wheel(Duration=" + duration + ",spokes=12)";break;
        case 8: return "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=" + duration + ")"; break
        case 9: return "progid:DXImageTransform.Microsoft.RadialWipe(Duration=" + duration + ",wipeStyle=clock)";break;
        case 10: return "progid:DXImageTransform.Microsoft.RandomBars(Duration=" + duration + ",orientation=vertical)";break;
        case 11: return "progid:DXImageTransform.Microsoft.Slide(Duration=" + duration + ",slideStyle=push)";break;
        case 12: return "progid:DXImageTransform.Microsoft.RandomDissolve(Duration=" + duration + ",orientation=vertical)";break;
        case 13: return "progid:DXImageTransform.Microsoft.Spiral(Duration=" + duration + ",gridSizeX=40,gridSizeY=40)";break;
        case 14: return "progid:DXImageTransform.Microsoft.Stretch(Duration=" + duration + ",stretchStyle=push)";break;
        case 15: return "progid:DXImageTransform.Microsoft.Zigzag(Duration=" + duration + ",GridSizeX=25, GridSizeY=25)";break;
        case 16: return "progid:DXImageTransform.Microsoft.Fade(duration=" + duration + ")";break;
        case 17: return "progid:DXImageTransform.Microsoft.Slide(Duration=" + duration + ",slideStyle=swap)";break;
        case 18: return "progid:DXImageTransform.Microsoft.Slide(Duration=" + duration + ",slideStyle=HIDE)";break;
        case 19: return "progid:DXImageTransform.Microsoft.Strips(Duration=" + duration + ",motion=leftdown)";break;
        case 20: return "progid:DXImageTransform.Microsoft.Strips(Duration=" + duration + ",motion=leftup)";break;
        case 21: return "progid:DXImageTransform.Microsoft.Strips(Duration=" + duration + ",motion=rightup)";break;
        case 22: return "progid:DXImageTransform.Microsoft.Barn(Duration=" + duration + ",orientation=horizontal)";break;
        case 23: return "progid:DXImageTransform.Microsoft.Iris(Duration=" + duration + ",motion=in)"; break;
        case 24: return "progid:DXImageTransform.Microsoft.RadialWipe(Duration=" + duration + ",wipeStyle=wedge)";break;
        case 25: return "progid:DXImageTransform.Microsoft.RadialWipe(Duration=" + duration + ",wipeStyle=radial)";break;
        case 26: return "progid:DXImageTransform.Microsoft.RandomBars(Duration=" + duration + ",orientation=HORIZONTAL)";break;
        case 27: return "progid:DXImageTransform.Microsoft.Stretch(Duration=" + duration + ",stretchStyle=HIDE)";break;
        case 28: return "progid:DXImageTransform.Microsoft.Stretch(Duration=" + duration + ",stretchStyle=SPIN)";break;
        
     }
        
     return "";
}


function ___Next(obj){
    obj = eval(obj);
   
   if(__isIE){
		if (obj.OnBeforeChange!=""){
			window.execScript(eval(obj.OnBeforeChange),"javascript");
		}
   }
   else if (obj.OnBeforeChange!=""){
	eval(obj.OnBeforeChange);
   }
   
   ___thumbsHilite(obj, false);
   
   if(!obj.CanTransform)
        return;
    
    if(obj.CurrentImage >= obj.ImageSrc.length - 1){
        
        if(obj.LoopCount>=0 && obj.CurrentLoop >= obj.LoopCount){
            window.clearInterval(obj.IntervalID);
            return;
        }else{
            obj.CurrentLoop++;
        }
        obj.CurrentImage = -1;
    }
    
    obj.CurrentImage++;
    
    ___ChangeImage(obj);
}

function ___ChangeImage(obj){
	obj = eval(obj);
	 
	var img1 = document.getElementById(obj.Name + "_img1");
    var cpt = document.getElementById(obj.Name + "_caption");
    var cpttext = document.getElementById(obj.Name + "_captext");
    var div1 = document.getElementById(obj.Name + "_oDIV1");
    var containerDiv = document.getElementById(obj.Name + "_oTransContainer");
    var ahref = document.getElementById(obj.Name + "_href");
    
    img1.style.visibility = "visible";
    if(obj.isIE &&  !obj.NoTransfermation){
        containerDiv.filters[0].Apply();
    }    
    img1.src = obj.ImageSrc[obj.CurrentImage].src;
    img1.alt = obj.ImageSrc[obj.CurrentImage].alt;
    ahref.href = obj.ImageURL[obj.CurrentImage];
    cpt.innerHTML = obj.ImageSrc[obj.CurrentImage].alt;
    cpttext.innerHTML = obj.ImageCaption[obj.CurrentImage];
   
   
   ___thumbsHilite(obj, true);
    
    if(obj.isIE && !obj.NoTransfermation)
        containerDiv.filters[0].Play();
    
    /*    
	if (obj.OnAfterChange!=""){
	
		window.execScript(obj.OnAfterChange,"javascript");
	}
	*/
	
	if(__isIE){
		if (obj.OnAfterChange!=""){
			window.execScript(eval(obj.OnAfterChange),"javascript");
		}
   }
   else if (obj.OnAfterChange!=""){
	eval(obj.OnAfterChange);
   }

}


function ___thumbsmouseover(obj, index){
	obj = eval(obj);
		
	if(obj.ShowThumbsCaption){
		if (__thumbsdiv!="")
			if(__thumbsdiv.id == (obj.Name + "_thumbsdiv"))
				return;
			
		__thumbsdiv = document.getElementById(obj.Name + "_thumbsdiv");
		__thumbsdiv.innerHTML = "<b>" + obj.ImageSrc[index].alt + "</b><br/><span class='" + obj.ClassPrefix + "thumbscaptiontext' >" + obj.ImageCaption[index] + "</span>";
		
		__thumbsdiv.style.visibility = "visible";
		__thumbsdiv.style.display = "inline";
		
		__title = obj.ImageSrc[index].alt;
		obj.ImageSrc[index].alt = "";
	}
		
	__curobj = obj;	
	document.onmousemove = ___thumbsmousemove;
	
	if(obj.ImageChangeOnMouseOverThumbs)
		___thumbsChangeImage(obj, index);
	
	
	
}

function ___thumbsmouseout(obj, index){
	obj = eval(obj);
	
	if(obj.ShowThumbsCaption){
		__thumbsdiv.style.visibility = "hidden";
		__thumbsdiv.style.display = "none";
		__thumbsdiv = "";
		
		obj.ImageSrc[index].alt = __title;
	}
	
	document.onmousemove = docmousemove;
	__curobj = "";
	
}

function ___thumbsChangeImage(obj, index){
	obj = eval(obj);
	window.clearInterval(obj.IntervalID);
	
	___thumbsHilite(obj, false);
	
	obj.CurrentImage = index;
	obj.Start();
}

function ___thumbsClick(obj, index){
	obj = eval(obj);
	
	if(obj.ImageChangeOnMouseOverThumbs){
		window.clearInterval(obj.IntervalID);
		document.location.href = obj.ImageURL[obj.CurrentImage];	
	}
	else{
		___thumbsChangeImage(obj, index);
	}	
	
}


function ___thumbsmousemove(e)
{
	if(__curobj.ShowThumbsCaption){
		
		
		if(__isIE){
			if(__curobj.SideBar){
				
				__thumbsdiv.style.posLeft = parseInt(event.clientX) - parseInt(__thumbsdiv.style.width) - 25;
				__thumbsdiv.style.posTop = parseInt(event.clientY);
			}
			else{
				
				if( (parseInt(event.clientX) - (parseInt(__thumbsdiv.style.width) )/2 + 20)< 1)
					__thumbsdiv.style.posLeft = 1;
				else if ((parseInt(event.clientX) - (parseInt(__thumbsdiv.style.width) )/2 + 20) + parseInt(__thumbsdiv.style.width) >screen.availWidth )
					__thumbsdiv.style.posLeft = screen.availWidth - parseInt(__thumbsdiv.style.width)-18;
				else
					__thumbsdiv.style.posLeft = parseInt(event.clientX) - (parseInt(__thumbsdiv.style.width) )/2 ;//+ 20;
					
								
				__thumbsdiv.style.posTop = parseInt(event.clientY)+ 30;
			}
		}else{
			
			if(__curobj.SideBar){
				__thumbsdiv.style.left = "" + (parseInt(e.clientX) - parseInt(__thumbsdiv.style.width) - 25) + "px";
				__thumbsdiv.style.top = "" + parseInt(e.clientY) + "px";
			}else{
				if((parseInt(e.clientX)- (parseInt(__thumbsdiv.style.width) )/2 + 20)<1)
					__thumbsdiv.style.left = "1px";
				else
					__thumbsdiv.style.left = "" + (parseInt(e.clientX)- (parseInt(__thumbsdiv.style.width) )/2 /*+ 20*/) + "px";
					
				__thumbsdiv.style.top = "" + (parseInt(e.clientY) + 30) + "px";
			}
			
		}
	}
	
	
}

function ___thumbsHilite(obj, hilite){
	obj = eval(obj);
	
	var thumbnail = document.getElementById(obj.Name + "_thumbnail" + obj.CurrentImage);
	
	if(thumbnail!=undefined){
		thumbnail.className = (hilite)? obj.ClassPrefix + "thumbnailhilite" : obj.ClassPrefix + "thumbnailnormal";
		
		if(hilite){
			
			if(obj.SideBar){
				var sidebar = document.getElementById(obj.Name + "_sidebar");
				
				if(sidebar!=undefined){
					sidebar.scrollTop = thumbnail.height * obj.CurrentImage;
				}
			}
			else{
				var bottombar = document.getElementById(obj.Name + "_bottombar");
				
				if(bottombar!=undefined){
					bottombar.scrollLeft = thumbnail.width * obj.CurrentImage;
				}
			}
			
			
			
		}
	}
	
}