var pre_imgs=new Array();
var imgobj = new Image();
function preload_galery(id){
	if(typeof(pre_imgs[id])=='undefined'){
		pre_imgs[id]=new Array();
		pre_imgs[id][0] = new Image();
		pre_imgs[id][0].src = root_url+image_dir+imgs[seka[id]].org+'/'+imgs[seka[id]].th;
		pre_imgs[id][1] = new Image();
		pre_imgs[id][1].src = root_url+image_dir+imgs[seka[id]].org+'/'+imgs[seka[id]].prev;
	}
}
var this_img=0;
function show_galery(id,t){
	document.images.prew_img.src=imgs[id][2].src;
	if(document.getElementById('act')){
		document.getElementById('act').removeAttribute("id");
	}
	t.setAttribute("id",'act');
	this_img=id;
}

function zoomCurent(){
	if(!slades){
		if(imgs[seka[this_img]].big && imgs[seka[this_img]].big > 0){
			popFrame(root_url+image_dir+imgs[seka[this_img]].org+'/'+imgs[seka[this_img]].big);
		}
		else
		{
			popFrame(root_url+image_dir+imgs[seka[this_img]].org);
		}
	}
}
function downloadCurent(){
	if(!slades && imgs[seka[this_img]].org && download_dir){
		location.href=root_url+download_dir+imgs[seka[this_img]].org;
	}
}

var slades=false;

function slade_show(t){
	if(t.checked){
		slades=true;
		if(document.getElementById('navig_photo')){
			document.getElementById('navig_photo').style.display = 'none';
		}
		setTimeout("show_slades();",(slades_interval*1000));
	}
	else{
		slades=false;
	}
}

function show_slades(){
	if(slades && (this_img+1)<seka.length){
		navigation(1);
		setTimeout("show_slades();",(slades_interval*1000));
	}
	else{
		slades=false;
		document.getElementById('sl_sw').checked=false;
		if(document.getElementById('navig_photo')){
			document.getElementById('navig_photo').style.display = 'inline';
		}
	}
}

function nvgs(sk){
	if(!slades){
		navigation(sk);
	}
}

function saveimgobj(th)
{
	imgobj = th;
	
}

function nvgsvideo(sk){
	if(!slades){
		/*if(!document.images.prew_img)
		{
			var containerobj = document.getElementById('videoplayercontent');
			containerobj.innerHTML = '';
			containerobj.appendChild(imgobj);
		}*/
		
		videonavigation(sk);
		AC_FL_RunContent(
  'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
  'width', '370',
  'height', '298',
  'src', gimg_dir+'muflv?film=',
  'quality', 'high',
  'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
  'align', 'middle',
  'play', 'true',
  'loop', 'true',
  'scale', 'showall',
  'wmode','transparent',
  'devicefont', 'false',
  'id', 'muflv',
  'bgcolor', '#ffffff',
  'name', 'muflv',
  'menu', 'true',
  'allowFullScreen', 'true',
  'allowScriptAccess','sameDomain',
  'movie', gimg_dir+'muflv?film=',
  'salign', '',
  'objectid', 'videoplayercontent');
	}
}

function videonavigation(sk)
{
	this_img=(((this_img+sk)>-1 && (this_img+sk)<seka.length)?this_img+sk:this_img);
	document.images.back2.src=(((this_img-2)>-1)?root_url+image_dir+imgs[seka[this_img-2]].org+'/'+imgs[seka[this_img-2]].th:spgif);
	if((this_img-2)>-1){preload_galery(this_img-2);}
	document.images.back1.src=(((this_img-1)>-1)?root_url+image_dir+imgs[seka[this_img-1]].org+'/'+imgs[seka[this_img-1]].th:spgif);
	if((this_img-1)>-1){preload_galery(this_img-1);}
	document.images.curent.src=root_url+image_dir+imgs[seka[this_img]].org+'/'+imgs[seka[this_img]].th;
	/*document.images.prew_img.src=root_url+image_dir+imgs[seka[this_img]].org+'/'+imgs[seka[this_img]].prev;*/
	document.getElementById('photo_info').innerHTML=imgs[seka[this_img]].info;
	document.images.fow1.src=(((this_img+1)<seka.length)?root_url+image_dir+imgs[seka[this_img+1]].org+'/'+imgs[seka[this_img+1]].th:spgif);
	if((this_img+1)<seka.length){preload_galery(this_img+1);}
	document.images.fow2.src=(((this_img+2)<seka.length)?root_url+image_dir+imgs[seka[this_img+2]].org+'/'+imgs[seka[this_img+2]].th:spgif);
	if((this_img+2)<seka.length){preload_galery(this_img+2);}
}

function navigation(sk){
	this_img=(((this_img+sk)>-1 && (this_img+sk)<seka.length)?this_img+sk:this_img);
	document.images.back2.src=(((this_img-2)>-1)?root_url+image_dir+imgs[seka[this_img-2]].org+'/'+imgs[seka[this_img-2]].th:spgif);
	if((this_img-2)>-1){preload_galery(this_img-2);}
	document.images.back1.src=(((this_img-1)>-1)?root_url+image_dir+imgs[seka[this_img-1]].org+'/'+imgs[seka[this_img-1]].th:spgif);
	if((this_img-1)>-1){preload_galery(this_img-1);}
	document.images.curent.src=root_url+image_dir+imgs[seka[this_img]].org+'/'+imgs[seka[this_img]].th;
	document.images.prew_img.src=root_url+image_dir+imgs[seka[this_img]].org+'/'+imgs[seka[this_img]].prev;
	document.getElementById('photo_info').innerHTML=imgs[seka[this_img]].info;
	document.images.fow1.src=(((this_img+1)<seka.length)?root_url+image_dir+imgs[seka[this_img+1]].org+'/'+imgs[seka[this_img+1]].th:spgif);
	if((this_img+1)<seka.length){preload_galery(this_img+1);}
	document.images.fow2.src=(((this_img+2)<seka.length)?root_url+image_dir+imgs[seka[this_img+2]].org+'/'+imgs[seka[this_img+2]].th:spgif);
	if((this_img+2)<seka.length){preload_galery(this_img+2);}
}

function loadNavig(sk){
	navigation(sk);
	if(document.getElementById('navig_photo')){
		document.getElementById('navig_photo').style.display = 'inline';
	}
}

function loadVideoNavig(sk){
	nvgsvideo(sk);
	if(document.getElementById('navig_photo')){
		document.getElementById('navig_photo').style.display = 'inline';
	}
	
}
/*  POPUP FRAME */
if(!brd){
var brd=new Object();
brd.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
brd.isGecko = navigator.userAgent.indexOf('Gecko') != -1;
brd.isSafari = navigator.userAgent.indexOf('Safari') != -1;
brd.isMac = navigator.userAgent.indexOf('Mac') != -1;
brd.isMSIE5_0 = brd.isMSIE && ((navigator.userAgent.indexOf('MSIE 5') != -1) || (navigator.userAgent.indexOf('MSIE 6') != -1));
}
var pimage = null;
var pimagetimmer;
var pimageMargin=5;
var pop=null;
var bgdiv = null;
var idiv = null;

var use_frame=false;
var bgframe=new Object();
bgframe.isset=false;

function popFrame(img){
	pimage = new Image();
	pimage.src = img;
	hideContent();
	createFrame()
	popLoader();
	if(brd.isGecko){
		pimage.onload = function(){
			initImage();
		};
	}
	else{
		loadImageEnd();
	}
}

function loadImageEnd(){
	if(pimage.src && !pimage.complete){
		pimagetimmer=setTimeout("loadImageEnd()", 100);
	}
	else{
		clearTimeout(pimagetimmer);
		initImage();
	}
}

function createFrame(){
	var div = document.createElement("div");
	var width = 10;
	var height = 10;
	div.style.position = "absolute";

	div.style.backgroundColor = "white";
	div.style.display = "none";
	div.style.border = '1px solid #999';
	document.body.appendChild(div);
	div.innerHTML = div.innerHTML;
	div.style.margin="0px";
	div.style.padding=pimageMargin+"px";
	
	var image = new Image();
	image.align="center";
	div.appendChild(image);
	
	pop=div;
	/*pop.onclick=function (){
			//pClose();
		}*/
	pop.onmouseover = function(){onPop();}
	pop.onmouseout = function(){outPop();}
	div.style.display = "block";
	hideFrame();
	pop._image = image;
	pop._image.onclick = function(){pClose();};
	
	resizeFrame(width, height);
}

function resizeFrame(w, h){
	if(pop){
		var div_pos = calcCenter(w, h);
		pop.setAttribute("width", w);
		pop.setAttribute("height", h);
		pop.style.left = div_pos[0] + "px";
		pop.style.top = div_pos[1] + "px";
		pop.style.width = w + "px";
		pop.style.height = h + "px";
	}
}

function popLoader(){
	idiv = document.createElement("div");
	idiv.style.position = "absolute";
	idiv.style.left = "100px";
	idiv.style.top = "100px";
	idiv.style.width = "180px";
	//idiv.style.height = "30px";
	idiv.style.paddingTop = "10px";
	idiv.style.paddingBottom = "10px";
	idiv.style.backgroundColor = "#fff";
	idiv.className = 'opa7';
	var img = new Image();
	img.src = loadgif;
	img.align = "left";
	img.hspace = 10;
	idiv.appendChild(img);
	idiv.onclick=function (){
			pClose();
		}
	
	var ltext = document.createElement("p");
	
	ltext.innerHTML = loading_txt;//'Loading ...';
	idiv.appendChild(ltext);
	document.body.appendChild(idiv);
	var idiv_pos = calcCenter(idiv.offsetWidth, idiv.offsetHeight);
	idiv.style.left = idiv_pos[0]+"px";
	idiv.style.top = idiv_pos[1]+"px";
}

function initImage(){
	if(pop && pop._image && pimage){
		pimage.align="center";
		pop._image.src=pimage.src;
		
		if(brd.isGecko){
			var width = parseInt(pimage.naturalWidth);
			var height = parseInt(pimage.naturalHeight);
		}
		else{
			var width = parseInt(pimage.width);
			var height = parseInt(pimage.height);
		}
		resizeFrame(width, height);
		
		//pimage.onclick = function(){pClose()};
		addNavigation();
		addInfo();
		remLoader();
		unhideFrame();
		unhideImage();
		pimage = null;
	}
}

function remLoader(){
	if(idiv){
		document.body.removeChild(idiv);
		idiv=null;
	}
}

function unhideFrame(){
	if(pop){
		pop.className = 'opa10';
	}
}
function hideFrame(){
	if(pop){
		pop.className = 'opa5';
	}
}

function hideImage(){
	if(pop._image){
		pop._image.className = 'opaimg';
	}
}
function unhideImage(){
	if(pop._image){
		pop._image.className = 'opa10';
	}
}

function reopenCurent(){
	var imgsrc='';
	
	if(!slades){
		if(imgs[seka[this_img]].big && imgs[seka[this_img]].big > 0){
			imgsrc = root_url+image_dir+imgs[seka[this_img]].org+'/'+imgs[seka[this_img]].big;
		}
		else
		{
			imgsrc = root_url+image_dir+imgs[seka[this_img]].org;
		}
	}
	pimage = new Image();
	pimage.src = imgsrc;
	if(brd.isGecko){
		pimage.onload = function(){
			initImage();
		};
	}
	else{
		loadImageEnd();
	}
}

function pClose(){
	if(pop){
		if(pop._back){
			document.body.removeChild(pop._back);
		}
		if(pop._next){
			document.body.removeChild(pop._next);
		}
		if(pop._info){
			document.body.removeChild(pop._info);
		}
		if(pop._count){
			document.body.removeChild(pop._count);
		}
		document.body.removeChild(pop);
		pop=null;
	}
	if(bgdiv){
		document.body.removeChild(bgdiv);
		bgdiv=null;
		unSetBgFrame();
	}
	if(idiv){
		document.body.removeChild(idiv);
		idiv=null;
	}
}

function createImageContent(){
	if(pop){
		pimage.allign="center";
		pop.appendChild(pimage);
		pimage.onclick = function(){pClose()};
		addNavigation();
	}
}

function hideContent(){
	if(!bgframe.isset){
		initBgFrame();
	}
	var div = document.createElement("div");
	div.style.position = "absolute";
	div.style.left = "0px";
	div.style.top = "0px";
	div.style.width = "100%";
	div.style.height = document.body.scrollHeight+"px";
	div.style.backgroundColor = "#333";
	if(brd.isMSIE){
		div.style.filter = "alpha(opacity = 70)";
	}
	else{
		div.style.opacity = 0.7;
	}
	div.onclick = function(){
		pClose();
	};
	
	document.body.appendChild(div);
	bgdiv = div;
	setBgFrame(0, 0, bgdiv.offsetWidth, bgdiv.offsetHeight);
}

function calcCenter(w,h){
	var top = 0;
	var left = 0;
	top = (((screen.availHeight-168) - h) / 2) + document.documentElement.scrollTop;
	left = ((screen.availWidth - w) / 2) + document.documentElement.scrollLeft;
	return [left, top];
}

function addNavigation(){
	var h = parseInt(pop.offsetHeight);
	var w = parseInt(pop.offsetWidth);
	var t = parseInt(pop.offsetTop);
	var l = parseInt(pop.offsetLeft);
	
	var dw = 64;
	var dh = 64;
	if((this_img-1)>-1){
		if(!pop._back){
			var dvs = document.createElement('div');
			document.body.appendChild(dvs);
			//dvs.style.backgroundColor='#fff';
			dvs.innerHTML = '<img src="'+gimg_dir+'p_back.png" border="0" alt="" style="cursor:pointer;"/>';
			dvs.innerHTML = dvs.innerHTML;
			dvs.style.margin='0px';
			dvs.style.display = 'block';
			dvs.style.width = dw + 'px';
			dvs.style.height = dh + 'px';
			dvs.style.position = 'absolute';
			dvs.className = 'opa0';
			dvs.onmouseover = function(){ this.className='opaNav';};
			dvs.onmouseout = function(){ this.className = 'opa0';};
			pop._back = dvs;
		}
		pop._back.style.top = Math.round(t+((h-dh)/2))+'px';
		pop._back.style.left = (l+pimageMargin)+'px';
		pop._back.onclick = function(){zoomNext(-1);};
	}
	else{
		if(pop._back){
			document.body.removeChild(pop._back);
		}
		pop._back = null;
	}
	
	if((this_img+1)<seka.length){
		if(!pop._next){
			var dvs2 = document.createElement('div');
			document.body.appendChild(dvs2);
			//dvs2.style.backgroundColor='#fff';
			dvs2.innerHTML = '<img src="'+gimg_dir+'p_next.png" border="0" alt="" style="cursor:pointer;"/>';
			dvs2.innerHTML = dvs2.innerHTML;
			dvs2.style.margin='0px';
			dvs2.style.display = 'block';
			dvs2.style.width = dw + 'px';
			dvs2.style.height = dh + 'px';
			dvs2.style.position = 'absolute';
			dvs2.className = 'opa0';
			dvs2.onmouseover = function(){ this.className='opaNav';};
			dvs2.onmouseout = function(){ this.className = 'opa0';};
			pop._next = dvs2;
		}
		pop._next.style.top = Math.round(t+((h-dh)/2))+'px';
		pop._next.style.left = (l - pimageMargin + w - dw)+'px';
		pop._next.onclick = function(){ zoomNext(1);};
	}
	else{
		if(pop._next){
			document.body.removeChild(pop._next);
		}
		pop._next = null;
	}
}

function zoomNext(sk){
	if(!idiv){
		hideImage();
		popLoader();
		nvgs(sk);
		reopenCurent();
	}
}

function onPop(){
	if(pop._next){
		pop._next.className='onpop';
		pop._next.onmouseout = function(){ this.className = 'onpop';};
	}
	if(pop._back){
		pop._back.className='onpop';
		pop._back.onmouseout = function(){ this.className = 'onpop';};
	}
	if(pop._info){
		pop._info.className='opaInfo';
		pop._info.onmouseout = function(){ this.className = 'opaInfo';};
	}
	if(pop._count){
		pop._count.className='opaCountOnpop';
		pop._count.onmouseout = function(){ this.className = 'opaCountOnpop';};
	}
}

function outPop(){
	if(pop._next){
		pop._next.className='opa0';
		pop._next.onmouseout = function(){ this.className = 'opa0';};
	}
	if(pop._back){
		pop._back.className='opa0';
		pop._back.onmouseout = function(){ this.className = 'opa0';};
	}
	if(pop._info){
		pop._info.className='opa0';
		pop._info.onmouseout = function(){ this.className = 'opa0';};
	}
	if(pop._count){
		pop._count.className='opa0';
		pop._count.onmouseout = function(){ this.className = 'opa0';};
	}
}

function addInfo(){
	if(pop){
		
		var h = parseInt(pop.offsetHeight);
		var w = parseInt(pop.offsetWidth);
		var t = parseInt(pop.offsetTop);
		var l = parseInt(pop.offsetLeft);
		
		if(imgs[seka[this_img]].info !=''){
			if(!pop._info){
				var dvs = document.createElement('div');
				document.body.appendChild(dvs);
				dvs.style.backgroundColor='#fff';
				dvs.innerHTML = '';
				dvs.innerHTML = dvs.innerHTML;
				dvs.style.margin='0px';
				dvs.style.padding='5px';
				dvs.style.display = 'block';
				dvs.style.cursor = 'default';
				dvs.align='center';
				dvs.style.position = 'absolute';
				dvs.className = 'opa0';
				dvs.onmouseover = function(){ this.className='opaInfo';};
				dvs.onmouseout = function(){ this.className = 'opa0';};
				
				pop._info = dvs;
			}
			pop._info.style.width = (w-(pimageMargin*2)-10) + 'px';
			pop._info.innerHTML = imgs[seka[this_img]].info;
			var dh = parseInt(pop._info.offsetHeight);
			pop._info.style.top = (t+h-dh-pimageMargin)+'px';
			pop._info.style.left = (l+pimageMargin)+'px';
		}
		else{
			if(pop._info){
				document.body.removeChild(pop._info);
			}
			pop._info = null;
		}
		if(!pop._count){
			var dvs2 = document.createElement('div');
			document.body.appendChild(dvs2);
			dvs2.style.backgroundColor='#fff';
			dvs2.innerHTML = '';
			dvs2.innerHTML = dvs2.innerHTML;
			dvs2.style.margin='0px';
			dvs2.style.padding='5px';
			dvs2.style.display = 'block';
			dvs2.style.cursor = 'default';
			dvs2.style.fontWeight = 'bold';
			dvs2.align='center';
			dvs2.style.position = 'absolute';
			dvs2.className = 'opa0';
			dvs2.onmouseover = function(){ onPop();};
			dvs2.onmouseout = function(){ outPop();};
			
			pop._count = dvs2;
		}
		pop._count.innerHTML = (this_img+1)+' / '+seka.length;
		var dw = parseInt(pop._count.offsetWidth);
		pop._count.style.top = (t+pimageMargin)+'px';
		pop._count.style.left = (l+w+pimageMargin-dw-10)+'px';
	}
}

function setBgFrame(left, top, width, height){
	if(use_frame && bgframe.isset){
		bgframe.style.left=left;
		bgframe.style.top=top;
		bgframe.style.width=width;
		bgframe.style.height=height;
		bgframe.style.visibility='visible';
	}
}

function unSetBgFrame(){
	if(use_frame && bgframe.isset){
		bgframe.style.left='0';
		bgframe.style.top='0';
		bgframe.style.visibility='hidden';
	}
}

function initBgFrame(){
	if(brd.isMSIE5_0){
		use_frame=true;
		bgframe=document.createElement('iframe');
		bgframe.style.position='absolute';
		bgframe.style.visibility='hidden';
		bgframe.style.left='0';
		bgframe.style.top='0';
		bgframe.style.border='none';
		bgframe.scrolling="no";
		bgframe.frameBorder="0px";
		bgframe.style.width='10';
		bgframe.style.height='10';
		bgframe.style.filter = "alpha(opacity = 0)";
		//bgframe.style.zIndex='9';
		bgframe.isset=true;
		document.body.appendChild(bgframe);
	}
	else{
		bgframe.isset=true;
	}
}

function playCurrent()
{
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '370',
		'height', '298',
  		'src', 'muflv',
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
  		'id', 'muflv',
		'bgcolor', '#ffffff',
  		'name', 'muflv',
		'menu', 'true',
		'allowFullScreen', 'true',
		'allowScriptAccess','sameDomain',
  		'movie', 'muflv?film=stumbras.flv',
		'salign', '',
  'objectid', 'videoplayercontent'
			); //end AC code
	}
}

