var isIE5;
isIE5=navigator.userAgent.indexOf('MSIE 5.')>0
var timer; 
var transitiontype;
var current_location = 0;
var timeout_value =  5 * 1000;
var photo_urls = new Array;
var photo_captions = new Array;
var photo_descriptions = new Array;
var playing = 0;
var lblImageIndex;
var lblName;
var lblDescription;
var txtId;
var imgMain;

var pageIndex = 0;
var perPage = 3;


var SkipFirstImage = false;

function display_thumb(){
	document.getElementById('tumb_loader_portion').style.display = 'none';
	document.getElementById('tumb_display_portion').style.display = '';
	document.getElementById('tumb_button_portion').style.display = '';
	document.getElementById('thumb_prev_button').style.display = '';
	document.getElementById('thumb_next_button').style.display = '';
}

function preload_complete(){
}

function reset_timer() {
    clearTimeout(timer);
    if (playing){
        timer = setTimeout('go_to_next_photo()', timeout_value);
    }
}

function go_to_next_photo() {
	if (current_location == photo_count){
		current_location = 0;
	}
	for(i=0; i<maxslides; i++){
		obj = document.getElementById('thumb_'+(i+1));
		if(current_location != i) obj.className = "thumb_box";
		if(current_location == i) obj.className = "thumb_box_hover";
	}
	if(current_location!=0 && ((current_location)%perPage) == 0){
		pageIndex = parseInt(current_location/perPage)-1;
		dispNextPic();
	}
	else if((current_location == maxslides) || (current_location == 0)){
		pageIndex = 1;
		dispPreviousPic();
	}
	//doTransistions = true;
	//alert(doTransistions);
	//doTransistions=1;
	if (SkipFirstImage){
		current_location++;
		SkipFirstImage = false;
		reset_timer();
	}
	else
	{
		var browserName=navigator.appName;
		current_location++;
		
		if (current_location > photo_count){
			current_location = 1;
		}
	    //document.getElementById(lblImageIndex).innerHTML = current_location;		
		document.getElementById(lblName).innerHTML = photo_captions[current_location];
		document.getElementById(lblDescription).innerHTML = photo_descriptions[current_location];
		
		//document.getElementById(txtId).value = current_location - 1;
	    
		if (doTransistions){
			if(browserName=="Microsoft Internet Explorer"){
				//IEtransitionNew(4000/5000);
				//document.getElementById(imgMain).filters.blendTrans.apply()    
				//document.getElementById(imgMain).src = photo_urls[current_location].src;
				//document.getElementById(imgMain).filters.blendTrans.play()
				document.getElementById('mainPropImgRel').innerHTML = '<a href=\"'+lightbox_images[current_location]+'\" rel=\"lightbox\"><img src=\"'+photo_urls[current_location].src+'\" border=\"0\" id=\"imgMain\" title=\"'+image_title[current_location]+'\" /></a>';
				//document.getElementById('mainPropImgRel').filters[0].Play();
			}
			else{
				document.getElementById('mainPropImgRel').innerHTML = '<a href=\"'+lightbox_images[current_location]+'\" rel=\"lightbox\"><img src=\"'+photo_urls[current_location].src+'\" border=\"0\" id=\"imgMain\" title=\"'+image_title[current_location]+'\" /></a>';
				/*document.getElementById(imgMain).src = photo_urls[current_location].src;*/
			}
			reset_timer();
		}
		else{
			document.getElementById('mainPropImgRel').innerHTML = '<a href=\"'+lightbox_images[current_location]+'\" rel=\"lightbox\"><img src=\"'+photo_urls[current_location].src+'\" border=\"0\" id=\"imgMain\" title=\"'+image_title[current_location]+'\" /></a>';
			/*document.getElementById(imgMain).src = photo_urls[current_location].src;*/
		}
	}
	initLightbox();
}

function TogglePlay(val){
	//document.getElementById('ajax_loader_map').style.display="none";
	document.getElementById("imgMain").style.display="";
	//document.getElementById("googleMapDisp").style.display="none";
	document.getElementById("videoPortion").style.display="none";
	//document.getElementById('video').value = "Walk Through";
	
	if (playing){
		if (document.getElementById("imgAutoPlay") != null){
			document.getElementById('imgAutoPlay').src = "/images/btn_play.jpg";
		}
		playing  = 0;
		clearTimeout(timer);
	}
	else{
		if (document.getElementById("imgAutoPlay") != null){
			document.getElementById('imgAutoPlay').src = "/images/btn_pause.jpg"; 
		}
		playing  = 1;
		go_to_next_photo();
	}
}

function TogglePlayNew(val){
	//document.getElementById('ajax_loader_map').style.display='none';
	document.getElementById("imgMain").style.display="";
	//document.getElementById("googleMapDisp").style.display="none";
	document.getElementById("videoPortion").style.display="none";
	//document.getElementById('video').value = "Walk Through";
	
	if (document.getElementById("imgAutoPlay") != null){
		document.getElementById('imgAutoPlay').src = "/images/btn_play.jpg";
	}
	playing  = 0;
	clearTimeout(timer);
}


function nextPic(val){
	current_location++;	
	if (current_location > photo_count){
		current_location = 1;
	}
	
	if (playing){
		if (document.getElementById("imgAutoPlay") != null){
			document.getElementById('imgAutoPlay').src = "/images/btn_play.jpg";
		}
		playing  = 0;
		////document.getElementById(lblImageIndex).innerHTML = current_location;		
		document.getElementById(lblName).innerHTML = photo_captions[current_location];
		document.getElementById(lblDescription).innerHTML = photo_descriptions[current_location];
		document.getElementById(imgMain).src = photo_urls[current_location].src;
		clearTimeout(timer);
	}
	else{
		playing  = 0;
		//document.getElementById(lblImageIndex).innerHTML = current_location;		
		document.getElementById(lblName).innerHTML = photo_captions[current_location];
		document.getElementById(lblDescription).innerHTML = photo_descriptions[current_location];
		document.getElementById(imgMain).src = photo_urls[current_location].src;
		clearTimeout(timer);
	}
}



function prePic(val){
	current_location--;	
	if (current_location < 1){
		current_location = photo_count;
	}
	
	if (playing){
		if (document.getElementById("imgAutoPlay") != null){
			document.getElementById('imgAutoPlay').src = "/images/btn_play.jpg";
		}
		playing  = 0;
		//document.getElementById(lblImageIndex).innerHTML = current_location;		
		document.getElementById(lblName).innerHTML = photo_captions[current_location];
		document.getElementById(lblDescription).innerHTML = photo_descriptions[current_location];
		document.getElementById(imgMain).src = photo_urls[current_location].src;
		clearTimeout(timer);
	}
	else{
		playing  = 0;
		//document.getElementById(lblImageIndex).innerHTML = current_location;		
		document.getElementById(lblName).innerHTML = photo_captions[current_location];
		document.getElementById(lblDescription).innerHTML = photo_descriptions[current_location];
		document.getElementById(imgMain).src = photo_urls[current_location].src;
		clearTimeout(timer);
	}
}

function randomPick() {
   return randomPick.arguments[Math.floor(Math.random()*randomPick.arguments.length)]
}

function IEtransitionNew(d) {
   var trans=transitiontype
   d='duration='+d
   if (trans===void 0) switch (Math.floor(Math.random()*17)) {
	  case 0: trans='Barn('+d+',motion='+randomPick('in','out')+',orientation=',randomPick('horizontal','vertical')+')'
			  break;
	  case 1: trans='Blinds('+d+',bands='+randomPick(2,4,6,8)+',direction='+randomPick('up','down','right','left')+')'
			  break;
	  case 2: trans='CheckerBoard('+d+',squaresX='+randomPick(2,4,8,12)+',squaresY='+randomPick(2,4,8,12)+',direction='+randomPick('up','down','right','left')+')'
			  break;
	  case 3: trans='Fade('+d+',overlap='+randomPick(0.25,0.5,0.75,1)+')'
			  break;
	  case 4: trans='GradientWipe('+d+',gradientSize='+randomPick(0,0.1,0.3,0.5,0.7,0.9,1)+',wipeStyle='+randomPick(0,1)+',motion='+randomPick('forward','reverse')+')'
			  break;
	  case 5: trans='Inset('+d+')'
			  break;
	  case 6: trans='Iris('+d+',irisStyle='+randomPick('DIAMOND','CIRCLE','CROSS','PLUS','SQUARE','STAR')+',motion='+randomPick('in','out')+')'
			  break;
	  case 7: trans='Pixelate('+d+',maxSquare='+randomPick(5,10,20,30,40,50)+')'
			  break;
	  case 8: trans='RadialWipe('+d+',wipeStyle='+randomPick('CLOCK','WEDGE','RADIAL')+')'
			  break;
	  case 9: trans='RandomBars('+d+',orientation='+randomPick('horizontal','vertical')+')'
			  break;
	  case 10: trans='RandomDissolve('+d+')'
			  break;
	  case 11: trans='Slide('+d+',pushStyle='+randomPick('HIDE','PUSH','SWAP')+',bands='+randomPick(1,2,3,4,5,6,7)+')'
			  break;
	  case 12: trans='Spiral('+d+',gridSizeX='+randomPick(8,16,32,64)+',gridSizeY='+randomPick(8,16,32,64)+')'
			  break;
	  case 13: trans='Stretch('+d+',stretchStyle='+randomPick('HIDE','PUSH','SPIN')+')'
			  break;
	  case 14: trans='Strips('+d+',motion='+randomPick('leftdown','leftup','rightdown','rightup')+')'
			  break;
	  case 15: trans='Wheel('+d+',spokes='+randomPick(2,4,10,16,20)+')'
			  break;
	  case 16: trans='Zigzag('+d+',gridSizeX='+randomPick(8,16,32,64)+',gridSizeY='+randomPick(8,16,32,64)+')'
			  break;
   }
	var name = imgMain;
	var chk
	if (isIE5) chk = document.all[name]
	if (document.getElementById) chk = document.getElementById(name)
	if (document.all) chk = document.all[name]
	if (document.layers) chk = document[name]
	chk.style.filter='progid:DXImageTransform.Microsoft.'+trans
	chk.filters[0].Apply();
}



function dispPreviousPic(){
	perPage = parseInt(perPage);
	pageIndex = parseInt(pageIndex);
	if((pageIndex-1) >= 0){
		pageIndex = pageIndex-1;
		for(i=0; i<maxslides; i++){
			obj = document.getElementById('thumb_'+(i+1));
			if(obj) obj.style.display = 'none';
		}
		for(n=((pageIndex*perPage)+1); n<=(perPage*(pageIndex+1)); n++){
			pObj = document.getElementById('thumb_'+n);
			if(pObj) pObj.style.display = '';
		}
	}
}


function dispNextPic(){
	perPage = parseInt(perPage);
	pageIndex = parseInt(pageIndex);
	if(maxslides >= (perPage*(pageIndex+1))){
		pageIndex = pageIndex+1;
		for(i=0; i<maxslides; i++){
			obj = document.getElementById('thumb_'+(i+1));
			if(obj) obj.style.display = 'none';
		}
		for(n=((pageIndex*perPage)+1); n<=(perPage*(pageIndex+1)); n++){
			nObj = document.getElementById('thumb_'+n);
			if(nObj) nObj.style.display = ''; 
		}
	}
}
