   	/***********************************************************************************************
	
	Copyright (c) 2005 - Alf Magne Kalleland post@dhtmlgoodies.com
	
	UPDATE LOG:
	
	March, 10th, 2006 : Added support for a message while large image is loading
	
	Get this and other scripts at www.dhtmlgoodies.com
	
	You can use this script freely as long as this copyright message is kept intact.
	
	***********************************************************************************************/ 
   	
	var displayWaitMessage=true;	// Display a please wait message while images are loading?
  	
   		
	var activeImage = false;
	var imageGalleryLeftPos = false;
	var imageGalleryWidth = false;
	var imageGalleryObj = false;
	var maxGalleryXPos = false;
	var slideSpeed = 0;
	var imageGalleryCaptions = new Array();
	var shImageScales;
	function startSlide(e)
	{
		if(document.all)e = event;
		var id = this.id;
		this.getElementsByTagName('IMG')[0].src = 'images/' + this.id + '_over.jpg';	
		if(this.id=='arrow_right'){
			slideSpeedMultiply = Math.floor((e.clientX - this.offsetLeft) / 5);
			slideSpeed = -1*slideSpeedMultiply;
			slideSpeed = Math.max(-10,slideSpeed);
		}else{			
			slideSpeedMultiply = 10 - Math.floor((e.clientX - this.offsetLeft) / 5);
			slideSpeed = 1*slideSpeedMultiply;
			slideSpeed = Math.min(10,slideSpeed);
			if(slideSpeed<0)slideSpeed=10;
		}
	}
	
	function releaseSlide()
	{
		var id = this.id;
		this.getElementsByTagName('IMG')[0].src = 'images/' + this.id + '.jpg';
		slideSpeed=0;
	}
		
	function gallerySlide()
	{
		if(slideSpeed!=0){
			var leftPos = imageGalleryObj.offsetLeft;
			leftPos = leftPos/1 + slideSpeed;
			if(leftPos>maxGalleryXPos){
				leftPos = maxGalleryXPos;
				slideSpeed = 0;
				
			}
			if(leftPos<minGalleryXPos){
				leftPos = minGalleryXPos;
				slideSpeed=0;
			}
			
			imageGalleryObj.style.left = leftPos + 'px';
		}
		setTimeout('gallerySlide()',20);
		
	}
	
	function showImage()
	{
		if(activeImage){
			activeImage.style.filter = 'alpha(opacity=50)';	
			activeImage.style.opacity = 0.5;
		}	
		this.style.filter = 'alpha(opacity=100)';
		this.style.opacity = 1;	
		activeImage = this;	
	}
	
	function initSlideShow()
	{
		document.getElementById('arrow_left').onmousemove = startSlide;
		document.getElementById('arrow_left').onmouseout = releaseSlide;
		document.getElementById('arrow_right').onmousemove = startSlide;
		document.getElementById('arrow_right').onmouseout = releaseSlide;
		
		imageGalleryObj = document.getElementById('theImages');
		imageGalleryLeftPos = imageGalleryObj.offsetLeft;
		imageGalleryWidth = document.getElementById('galleryContainer').offsetWidth - 80;
		maxGalleryXPos = imageGalleryObj.offsetLeft; 
		minGalleryXPos = imageGalleryWidth - document.getElementById('slideEnd').offsetLeft;
		var slideshowImages = imageGalleryObj.getElementsByTagName('IMG');
		for(var no=0;no<slideshowImages.length;no++){
			slideshowImages[no].onmouseover = showImage;
		}
		
		imageGalleryCaptions.length = 0;
		var divs = imageGalleryObj.getElementsByTagName('DIV');
		for(var no=0;no<divs.length;no++){
			if(divs[no].className=='imageCaption')imageGalleryCaptions[imageGalleryCaptions.length] = divs[no].innerHTML;
		}
		gallerySlide();
	}
	
	function showPreview(imagePath,imageIndex){
		var subImages = document.getElementById('previewPane').getElementsByTagName('IMG');
		if(subImages.length==0){
			var img = document.createElement('IMG');
			document.getElementById('previewPane').appendChild(img);
		}else img = subImages[0];
		
		if(displayWaitMessage){
			document.getElementById('waitMessage').style.display='inline';
		}
		//document.getElementById('largeImageCaption').style.display='none';
		img.onload = function() { hideWaitMessageAndShowCaption(imageIndex-1); };
		img.height = shImageScales[imageIndex-1][0];
		img.width = shImageScales[imageIndex-1][1];
		img.src = imagePath;
		img.onclick = function() {showBigImage(shImageScales[imageIndex-1][4], shImageScales[imageIndex-1][3], shImageScales[imageIndex-1][2],imageGalleryCaptions[imageIndex - 1])}
		
	}
	function hideWaitMessageAndShowCaption(imageIndex)
	{
		document.getElementById('waitMessage').style.display='none';	
		document.getElementById('largeImageCaption').innerHTML = imageGalleryCaptions[imageIndex];
		//document.getElementById('largeImageCaption').style.display='block';
		
	}
	//window.onload = initSlideShow;


    function showBigImage(url, w, h, caption){
        var content = "<div class='fadeSH'></div>";
		var left = Math.round(($(window).width() - parseInt(w, 10))/2);
		var top = Math.round(($(window).height() - parseInt(h, 10))/2);
		var ctop = top + 2;
		var cleft = left + w - 35; 
		var ct = parseInt(top, 10)+2;
		var cl = parseInt(left, 10)+parseInt(w, 10)-35;
        content += "<div class='SHClose' style='position:absolute;top:"+ct+"px;left:"+cl+"px' ><a href='javascript:void(0)' style='color:black;text-decoration:none'>[Close X]</a></div>";
        content += "<div class='SHImage' style='position:absolute;top:"+top+"px;left:"+left+"px;width:"+w+"px'>";
        content += "<img src='"+url+"' border='0' height='"+h+"' width='"+w+"' onload='hideSHLoading()' title='Click&nbsp;to&nbsp;close'/>";
        content += "<div class='SHCaption' style='color:black;padding-top:5px' >" + caption + "</div>";
        content += "</div>";
		left = Math.round($(window).width()/2)-33;
		top = Math.round($(window).height()/2)-33;
        content += "<div class='SHLoading' style='position:absolute;top:"+top+"px;left:"+left+"px'><img src='images/loading_t.gif' border='0'></div>"
        $("body").append(content);
		var wsize = getWindowSize();
		var ie6 = (jQuery.browser.msie && jQuery.browser.version < 7);	
		$(".fadeSH").css({ position: (ie6)? "absolute" : "fixed", height: wsize.height, width: "100%", top: (ie6)? getWindowScrollOffset():0, left: 0, right: 0, bottom: 0 });
        $(".SHImage").css({cursor: "pointer", zIndex:11, width:w, background:"#fff", padding:"15px", border:"1px solid #666"});        
        $(".SHClose").css({zIndex:13, color:"black", font:"10px Verdana, Geneva, Arial, Helvetica, sans-serif"});        
        $(".SHCaption").css({zIndex:13, color:"black", font:"10px Verdana, Geneva, Arial, Helvetica, sans-serif"});        
        $(".SHImage").click(function(){
            $(".fadeSH").remove();
            $(".SHImage").remove();
            $(".SHLoading").remove();
            $(".SHClose").remove();
            $(".SHCaption").remove();
        });
        $(".SHClose").click(function(){
            $(".fadeSH").remove();
            $(".SHImage").remove();
            $(".SHLoading").remove();
            $(".SHClose").remove();
            $(".SHCaption").remove();
        });
        $(".fadeSH").fadeIn('slow');        
    }

    function hideSHLoading(){
        $(".SHLoading").hide();
    }
    
	function getWindowSize(){ 
		var size = {
			width: window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth),
			height: window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight)
		};
		return size;
	}   
	
    function getWindowScrollOffset(){ 
		return (document.documentElement.scrollTop || document.body.scrollTop) + 'px'; 
	};		