
var lastImg=null;

function mi(o,nr) {
	o.style.backgroundColor='#f5f5f5';
	if(o.attributes['class'].value=='box hor')	o.style.backgroundImage='url(bg3.png)';
	else o.style.backgroundImage='url(bg4.png)';
	o.style.border='#C8BC7B 1px dashed';
	if(pics[nr][4]!='') window.status=pics[nr][4];
	return true;
}
function mo(o) {
	o.style.backgroundColor='';
	if(o.attributes['class'].value=='box hor')	o.style.backgroundImage='url(bg1.png)';
	else o.style.backgroundImage='url(bg2.png)';
	o.style.border='#C8BC7B 1px solid';
	window.status='';
}

function obr(idx) {
	if(o==null) {
		o=document.getElementById('obr');
		p=document.getElementById('photo');
		t=document.getElementById('textoverlay');
		cl=document.getElementById('controlleft');
		cr=document.getElementById('controlright');
		info=document.getElementById('infoicon');
		oinfoupdate=document.getElementById('infoupdate');
		orating=document.getElementById('rating');
	}

	img='galleries/'+pics[idx][0]+'/resized/'+pics[idx][1];
	w=pics[idx][2];
	h=pics[idx][3];
	inf=pics[idx][4];
	lastImg=idx;
	o.src='e.gif';
	o.style.display='none';

	var resize=0;
	var wh=window.innerHeight;
	var ww=window.innerWidth;
	var wy=window.scrollY;

	if(h+30>wh){
		var rat=(wh-30)/h;
		h=wh-30;
		w=w*rat;
		resize=1;
	}
	if(w+200>ww) {
		var rat=(ww-200)/w;
		w=ww-200;
		h=h*rat;
		resize=1;
	}

	var ot=(wh-h-30)/2;
	var ol=(ww-w-30)/2;

	p.style.height=wh;
	p.style.top=0;
	o.style.top=ot;
	o.style.left=ol;
	o.style.width=w;
	o.style.height=h;
	

	t.style.bottom=ot+22;
	t.style.right=ol+9;
	t.innerHTML=inf;
	document.getElementById('infotext').value=inf;
	
	
	cl.style.top=(wh-78)/2;
	cl.style.left=ol-81;
	cr.style.top=(wh-78)/2;
	cr.style.left=ol+10+28+w;

	orating.style.top=ot+16;
	orating.style.left=ol+17+w;

	p.style.display='inline';
	if(inf!='') t.style.display='inline';
	else t.style.display='none';
	if(idx>0) cl.style.display='inline';
	else cl.style.display='none';
	if(idx<pics.length-1) cr.style.display='inline';
	else cr.style.display='none';
	if(pics[lastImg][6]!=1) orating.style.display='inline';
	else orating.style.display='none';

	if(info!=null){
		info.style.top=ot+5;
		info.style.left=ol+36+w;
		info.style.display='inline';
	}

	oinfoupdate.style.top=ot+14;
	oinfoupdate.style.left=ol-235+w;
	oinfoupdate.style.display='none';
	

	o.src=img;
	o.style.display='inline';
	
	var ok=document.getElementById('ok'+pics[lastImg][5]);
	if(ok!=null) {
		ok.src='ok.png';
	}

}
function obr_close() {
	o.src='e.gif';
	o.style.display='none';
	p.style.display='none';
	t.style.display='none';
	cr.style.display='none';
	cl.style.display='none';
	if(info!=null) info.style.display='none';
	oinfoupdate.style.display='none';
	orating.style.display='none';
	lastImg=null;
}

function move(cnt) {
	if(lastImg!=null) {
		var idx=lastImg;
		var next=lastImg+cnt
		if(next>=pics.length) next=0;
		obr(next);
	}
}

function redraw() {
	if(lastImg!=null) {
		obr(lastImg);
	}
}

function scrollCheck(){
	if(lastImg!=null) obr_close();
}

function rate(pts) {
	dummy.src='rating.php?picid='+pics[lastImg][5]+'&rating='+pts;
	rating.style.display='none';
	pics[lastImg][6]=1;	
}

function cancel() {
	oinfoupdate.style.display='none';
}


