﻿// JScript File
function $get(id) {return document.getElementById(id); }
var isIE = (navigator.appName == 'Microsoft Internet Explorer');
var SlidePicture = 
{
	pictureArr	: null,
	pageSize	: null,
	pageNow		: null,
	cols		: null,
	container	: null,
	curImage	: null,
	timer		: null,
	transTime	: 10000,
	id          : null,
	
	init		: function(args)
	{
		for (var i in args)
			this[i] = args[i];
			
		this.pageNow = 1;
		if (!this.cols) this.cols = 3;		
		id=args["container"].split('_')[args["container"].split('_').length-1];
		this.showSlideShow(0);
		this.play(id);
	},
	
	goPage		: function(inc)
	{
		var total = Math.ceil(this.pictureArr.length * 1.0 / this.pageSize);
		switch (inc)
		{
			case -2 :
				this.pageNow = 0;
				break;
			case 2 :
				this.pageNow = total;
				break;
			default :
				this.pageNow += inc;
		}
		if (this.pageNow <= 0) this.pageNow = 1;
		if (this.pageNow > total) this.pageNow = total;
		this.loadPage();
	},
	
	loadPage	: function()
	{
		var div			= $get(this.container);
		var imgHTML		= "", titleHTML = "", html = "";
		var titleHTML	= "";
		
		var start	= (this.pageNow - 1) * this.pageSize;
		var count	= 1;
		var width	= 100.0 / this.cols;
		for (var i = 0 ; i + start < this.pictureArr.length && i < this.pageSize; i++)
		{
			var item = this.pictureArr[i + start];
			imgHTML += "<td width='" + width + "%'><img class='SmallImageThum' width='150' height='150' onclick='SlidePicture.showSlideShow(" + (i + start) + ")' src='" + item[0] + "' alt='" + item[1] + "' /></td>";
			titleHTML += "<td width='" + width + "%'>" + item[1] + "</td>";
			if (count++ >= this.cols)
			{
				html	+= "<tr>" + imgHTML + "</tr><tr>" + titleHTML + "</tr>";
				imgHTML = titleHTML = "";
				count	= 1;
			}
		}
		if (imgHTML != "")
			html += "<tr>" + imgHTML + "</tr><tr>" + titleHTML + "</tr>";
		
		div.innerHTML = "<table width='100%'>" + html + "</table>";
	},
	
	showSlideShow : function(index)
	{
		var html = "";
		for (var i = 0 ; i < this.pictureArr.length ; i++)
		{
			var item = this.pictureArr[i];
			var src=item[0].replace(item[0].split('.')[2].split('_')[item[0].split('.')[2].split('_').length-2],'100x70');
			src=src.replace('.png','.jpg');
			if(s_Path=='')
			    src=src.replace('../','');
			html += "<div style='clear:both'><img height='70' width='89%' onclick='SlidePicture.viewLargeImage(" + i + ","+id+")' class='ThumImageClass' onclick='' src='" + src+ "' alt='" + item[1] + "' title='" + item[1] + "' /></div>";
		}
	
		var thumZone		= $get('Div_SlideShow_ThumZone_'+id);
		thumZone.scrollTop	= 0;
		thumZone.innerHTML	= html;
	
		this.curImage = null;
		//$get('Div_SlideShowZone').style.display = '';
		this.viewLargeImage(index,id);
	},
	
	viewLargeImage : function(index,id)
	{
		if (index < 0) index = 0;
		if($get('hdf_picture_'+id)!=null)
		{
		    this.pictureArr=$get('hdf_picture_'+id).value.split('@');
		    if (index > this.pictureArr.length - 1)
		    {		    
		        index = this.pictureArr.length - 1;	
		        $get('hdf_pos_'+id).value=index;
		    }
		    var item	= this.pictureArr[index].split(',');
		}
		else
		{		 
		    if (index > this.pictureArr.length - 1) index = this.pictureArr.length - 1;	
		    var item	= this.pictureArr[index];
		}
		var img		= $get('Img_SlideShow_LargeImage_'+id);
		
		if (isIE)
		{
			img.filters.item(0).apply();        
			img.filters.revealTrans.transition = Math.random() * 100; 
			img.filters.item(0).play();
		}
        if(s_Path=='')
			    item[0]=item[0].replace('../','');    
		img.src		= item[0];
		img.title	= item[1];
		
		$get('TD_SlideShow_Title_'+id).innerHTML = item[1];
		
		var thumZone	= $get('Div_SlideShow_ThumZone_'+id);
		var imgs		= thumZone.getElementsByTagName('IMG');
		if (this.curImage != null)
			imgs[this.curImage].className = 'ThumImageClass';
		this.curImage	= index;
		var curImg		= imgs[index]
		var thumZone	= $get('Div_SlideShow_ThumZone_'+id);
		var lImg1		= curImg.offsetLeft;
		var lImg2		= lImg1 + curImg.width;
		var lZone1		= thumZone.scrollLeft;
		var lZone2		= lZone1 + 415;
		
		if (lImg1 < lZone1 || lImg2 > lZone2)
			this.scrollThum(lImg1 - thumZone.scrollLeft);
		
		curImg.className	= 'ThumImageClassSelect';
		
	},
	
	scrollThum : function(incPos,id)
	{
		var thumZone	= $get('Div_SlideShow_ThumZone_'+id);
		if (Math.abs(incPos) <= 20)
			thumZone.scrollTop += incPos;
		else
		{
			var inc = (incPos > 0) ? 20 : -20;
			thumZone.scrollTop += inc;
			window.setTimeout("SlidePicture.scrollThum(" + (incPos - inc) +","+id+ ")", 2);
		}
	},
	
	closeSlideShow : function()
	{
		//$get('Div_SlideShowZone').style.display = 'none';
		this.stop();
	},
	
	firstImage : function(id){this.viewLargeImage(0,id);},
	backImage : function(id){
	    if($get('hdf_pos_'+id)!=null)
		{
		    this.curImage=$get('hdf_pos_'+id).value;		
		    $get('hdf_pos_'+id).value=this.curImage*1 - 1;
		}		
	    this.viewLargeImage(this.curImage*1 - 1,id);},
	nextImage : function(id){
	    if($get('hdf_pos_'+id)!=null)
		{
		    this.curImage=$get('hdf_pos_'+id).value;		
		    $get('hdf_pos_'+id).value=this.curImage*1 + 1;
		}		
	    this.viewLargeImage(this.curImage*1 + 1,id);},
	lastImage : function(id){this.viewLargeImage(this.pictureArr.length - 1,id);},
	
	nextslide : function(id)
	{
	    if($get('hdf_pos_'+id)!=null)
		{
		    this.curImage=$get('hdf_pos_'+id).value;				    
		    $get('hdf_pos_'+id).value= this.curImage*1 + 1;
		}		
		var index = this.curImage*1 + 1;
		
		if($get('hdf_picture_'+id)!=null)
		{
		    this.pictureArr=$get('hdf_picture_'+id).value.split('@');		    
		}		
		if (index > this.pictureArr.length - 1)
		{ 
		    index = 0;
		    if($get('hdf_pos_'+id)!=null)
		    {		    
		        $get('hdf_pos_'+id).value=0;
		    }		
		}
		SlidePicture.viewLargeImage(index,id);
		if($get('hdf_timer_'+id)!=null)
		    $get('hdf_timer_'+id).value = window.setTimeout('SlidePicture.nextslide('+id+')', SlidePicture.transTime);
		else
		    this.timer = window.setTimeout('SlidePicture.nextslide('+id+')', SlidePicture.transTime);
	},
	
	play : function(id)
	{
		$get('Img_SlideShow_Stop_'+id).style.display = '';
		$get('Img_SlideShow_Play_'+id).style.display = 'none';		
		if($get('hdf_picture_'+id)!=null)
		{
		    this.pictureArr=$get('hdf_picture_'+id).value.split('@');		   
		}		
		if(this.pictureArr.length>1)
		{
		    if($get('hdf_timer_'+id)!=null)
		        $get('hdf_timer_'+id).value = window.setTimeout('SlidePicture.nextslide('+id+')', SlidePicture.transTime);
		    else
		        this.timer = window.setTimeout('SlidePicture.nextslide('+id+')', SlidePicture.transTime);
		}
	},
	
	stop : function(id)
	{
		$get('Img_SlideShow_Stop_'+id).style.display = 'none';
		$get('Img_SlideShow_Play_'+id).style.display = '';
		if($get('hdf_timer_'+id)!=null)
		    window.clearTimeout($get('hdf_timer_'+id).value);
		else
		    window.clearTimeout(this.timer);
	}
}