var currentpos=0
var currentthumbpos=0
var moveamount=600
var thumbnailnum
var maxthumbvisible=5
var current_imgid=0
var moving=false
var finishedsizing=0
var preloadimg="no"
var myloadedimage=new Array()
myloadedimage[0]=1
var imggallery=new Array()
var firstimagestart=1
var nextorprev=0
var fadeout=1

function loadinfo(){
if(fadeout==0){
var fademe=new Fx.Opacity('iptc_info',{duration:transspeed})
fademe.custom(0,.75)
fadeout=1
}else{
var fademe=new Fx.Opacity('iptc_info',{duration:transspeed})
fademe.custom(.75,0)
fadeout=0}}

function areweready(loadarea,imgindex,img_id) {
	//alert('areweready()');
	//setTimeout("moretext()",1000);
	//if(finishedsizing++){
		modifyimage(loadarea,imgindex,img_id)
		//finishedsizing=0
	//}
}

function modifyimage(loadarea,imgindex,img_id){
	//alert('modifyimage('+loadarea+','+imgindex+','+img_id+')');
	
	if(myloadedimage[imgindex]==null){
		//alert('1')
		var mynewimage=new Image()
		//alert('imagedeclared')
		//alert('imgsrc='+imggallery[imgindex][0])
		mynewimage.src=imggallery[imgindex][0]
		//mynewimage.onload=function(){loadimagenow()}
		loadimagenow()
	}else{
		//alert('img cached')
		loadimagenow()
	}

function loadimagenow(){
	//alert('loadimagenow()');
	if(document.getElementById){
		//alert('1');
		if(current_imgid!=img_id){
			//alert('2');
			var imgobj=document.getElementById(loadarea)
			var iptch=document.getElementById('iptc_info')
			//var photonum=document.getElementById('photocount')
			var phototitle=document.getElementById('imgtitle')
			//alert('3');
			imgobj.innerHTML=returnimgcode(imggallery[imgindex])
			//alert('3.2');
			iptch.innerHTML=returniptc(imggallery[imgindex])
			//alert('3.3');
			//photonum.innerHTML=(Number(imgindex)+1)+" av "+imggallery.length+" bilder"
			//alert('3.4');
			
			
			// HÄR!!!!!!!!!!
			
			
			phototitle.innerHTML=tempgallery[img_id][4]+" "+tempgallery[img_id][7]


			//alert('4');
			initImage(loadarea)
			current_imgid=img_id
			myloadedimage[imgindex]=1
			//alert('5');
		}
		//alert('6');
	}
		//alert('7');
		return false
	}
}

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

function returniptc(theimg){
	//alert('returniptc('+theimg+')');
	var iptchtml=''+
	'<div class=\'iptc_left\'><br/>'+
	'	Title <br/>'+
	'	Author <br/>'+
	'	Copyright <br/><br/>'+
	'	Description <br/><br/>'+
	'</div>'+
	'<div class=\'iptc_right\'><br/>'+
	'	'+theimg[4]+'<br/>'+
	'	'+theimg[5]+'<br/>'+
	'	'+theimg[6]+'<br/><br/>'+
	'	'+theimg[7]+'<br/><br/>'+
	'</div>'
	return iptchtml
}

function initImage(imageId){
	//alert('initImage(' + imageId + ')');

	var fader=new Fx.Opacity(imageId,{duration:fadespeed})
	fader.hide()
	fader.toggle()
	//var titlefade=new Fx.Opacity('imgtitle',{duration:transspeed})
	//titlefade.hide()
	//titlefade.toggle()
	var fadeiptc=new Fx.Opacity('iptc_btn',{duration:transspeed})
	fadeiptc.hide()
	fadeiptc.toggle()
	if(fadeout==0){
	var fademe=new Fx.Opacity('iptc_info',{duration:transspeed})
	fademe.hide()
	fadeout=0
	}else{
	var fademe=new Fx.Opacity('iptc_info',{duration:transspeed})
	fademe.toggle()
	fadeout=1}
}

function checkbutton(mynum){
	//alert('checkbutton!mynum=' + mynum + ', thumbnailnum=' + thumbnailnum + ', maxthumbvisible=' + maxthumbvisible);
	//alert(moveamount * mynum + ', width=' + document.getElementById('widthbox').offsetWidth);

	//alert(document.getElementById('widthbox').offsetWidth);

	if (mynum == 0) {
		mm_shl('back','hidden')
		mm_shl('more','visible')
	} else if ((moveamount * mynum) < (document.getElementById('widthbox').offsetWidth-moveamount)) {
		mm_shl('back','visible')
		mm_shl('more','visible')
	} else {
		mm_shl('back','visible')
		mm_shl('more','hidden')
	}
}

function checknext(mynum){
	//alert('checknext(' + mynum + ')');
	thumbmax=(Number(thumbnailnum)-1)
	if(mynum<1){
		mm_shl('prev','hidden')
		mm_shl('next','visible')
	}else if(mynum<thumbmax){
		mm_shl('prev','visible')
		mm_shl('next','visible')
	}else{
		mm_shl('prev','visible')
		mm_shl('next','hidden')
	}
	//alert('checknext - at bottom');
}

function mm_shl(){
	var obj,args=arguments
	if((obj=MM_findObj(args[0]))!=null){
		if(obj.style) {
			obj=obj.style
		}
		obj.visibility=args[1]
	}
}

function MM_findObj(n,d){
	var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){
	d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
	if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n]
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document)
	if(!x&&d.getElementById)x=d.getElementById(n);return x
}

function addposition(addwidth){
	if(!moving){
	if(addwidth=="minus"){
	currentpos-=1
	}else if(addwidth=="plus"){
	currentpos+=1}}
	return currentpos
}

function movethumbs(way){
	//alert('movethumbs(' + way + ')');
	if(way=='plus'){
		move=(currentthumbpos+moveamount)
		var movethumbs=new Fx.Styles('thumbgall',{duration: transspeed,transition: Fx.Transitions.quadOut})
		movethumbs.custom({left: [currentthumbpos,move]})
		currentthumbpos+=moveamount
	}else if(way=='minus'){
		move=(currentthumbpos-moveamount)
		var movethumbs=new Fx.Styles('thumbgall',{duration: transspeed,transition: Fx.Transitions.quadOut})
		movethumbs.custom({left: [currentthumbpos,move]})
		currentthumbpos-=moveamount
	}
}

function MM_openBrWindow(theURL,winName,features){
window.open(theURL,winName,features)}
var thumbopen=0

function thumbs(){
	//alert('thumbs()');
	var resizethumb=new Fx.Height('thumbhide',{duration:transspeed,transition: Fx.Transitions.quadOut})
	var movethumbs=new Fx.Styles('thumbbox',{duration: transspeed,transition: Fx.Transitions.quadOut})
	if(thumbopen==1){
		resizethumb.custom(0,119)
		movethumbs.custom({top: [-120,0]})
		thumbopen=0
	}else{
		resizethumb.custom(119,0)
		movethumbs.custom({top: [0,-120]})
		thumbopen=1
	}
}

