// JavaScript Document

var currentpos=0;
var currentthumbpos=0;
var maxthumbvisible = 5; //Define how many thumbnails will be visible at one time in the thumbbox--for now this should only be 3 since it's actually the css that controls the size of the viewable box
var current_imgid=0;
var moving = false;
var finishedsizing=0;
var preloadimg="no"//Preload images ("yes" or "no"):
var myloadedimage = new Array();
     myloadedimage[0]=1;
var imggallery=new Array()
var firstimagestart=1;
var nextorprev=0;
var fadeout=1;

function areweready(loadarea, imgindex, img_id){
	if ( finishedsizing++ ) { 
		modifyimage(loadarea, imgindex, img_id);
		finishedsizing = 0;
	}
}

function modifyimage(loadarea, imgindex, img_id ){
	function loadimagenow(){
		if (document.getElementById) {
			
				if(current_imgid!=img_id){
					
					var imgobj=document.getElementById(loadarea);
					imgobj.innerHTML=returnimgcode(imggallery[imgindex]);
					initImage(loadarea);
					current_imgid=img_id;
					myloadedimage[imgindex]=1;
				}
			}
		return false
	}
	if(myloadedimage[imgindex]==null){	
		new Asset.image(imggallery[imgindex][0], {onload: loadimagenow});
		
	}else{
		loadimagenow();
	}
	
}

function returnimgcode(theimg){
	var imghtml=""
	if (theimg[1]!="")
		imghtml=''
	imghtml+='<a href="'+theimg[7]+'" target="_self"><img src="'+theimg[0]+'" border="0" id="'+theimg[8]+'" /></a>'
	if (theimg[1]!="")
		imghtml+=''
	return imghtml
}


function initImage(imageId) {
	
	var fader = new Fx.Style(imageId,'opacity', {duration:fadespeed});
	fader.set(0);
	fader.start(0,1);
}

function checkbutton(mynum){
	if ( mynum == 0 ) {
		mm_shl('back','hidden');
		mm_shl('more','visible');
	} else if ( mynum < thumbnailnum - maxthumbvisible ) {
		mm_shl('back','visible');
		mm_shl('more','visible');
	} else {
		mm_shl('back','visible');
		mm_shl('more','hidden');
	}
}

function addposition(addwidth){
	if ( !moving ) {
		 // if animagic is still moving the image..don't update the current position till it's done
		if(addwidth=="minus"){
			currentpos-=1;
		}else if(addwidth=="plus"){
			currentpos+=1;
		}
	}
	return currentpos;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

	
function timedMsg()
{
	if (window.t_bool) {
		if (tempgallery.length > 1) {
			if (current_imgid + 1 >= tempgallery.length ) {
				current_imgid = 1;
				previmage(current_imgid);
			} 
			else nextimage(current_imgid);
		}
	}
}

function clearTimedMsg(reload_trans) {
	window.t_bool = false;
	var x = window.setTimeout("reloadTimedMsg();", reload_trans);
}

function reloadTimedMsg() {
	window.t_bool = true;
}

