var full,clickCounter,cycling;
var stav=new Array(0,0,0)
function add_format(i){
	var t=document.getElementById('format'+i);
	var add=document.getElementById('addmessage');
	var f;	
	if(t.alt.charAt(1)!='/'){
		stav.unshift(i);
		f=t.alt.substr(0,1);
		f+='/'+t.alt.substr(1,t.alt.length);
		t.style.backgroundColor='#888888';
		add.text.value+=t.alt;
		t.alt=f;
									 }
									 else{
										if(i==stav[0]){
											stav.shift();
											f=t.alt.substr(0,1);
											f+=t.alt.substr(2,t.alt.length);	
											t.style.backgroundColor='#DCDCDC';
											add.text.value+=t.alt;
											t.alt=f;
																	}
																	else{window.alert('Zvýraznění musí být ukončováno v opačném pořadí, než bylo použito!');}
											 }
	add.text.focus(); 
										 }
function add_smile(t){
	document.getElementById('addmessage').text.value+=t;
										 }
function zobraz(id){
	var elem=document.getElementById(id);
	elem.style.visibility='visible';
								 }
function schovej(id)
{
	var elem=document.getElementById(id);
	elem.style.visibility='hidden';
	
}
function overeni(slovo){
	var a=window.confirm('Opravdu chcete tento článek '+slovo+'?');
	if(!a){
		return false;
				};
									};
 function hlasovano(ip){
		window.alert('Z IP adresy '+ip+' již bylo hlasováno');
											 };									
function init()
{
	var elem=document.getElementById('galery-cont');
	var imgs=elem.getElementsByTagName('img')
	for(i=0;i<imgs.length;i++)
	{
		imgs[i].style.position='relative';
	}
	full=1;
	enlarged=0;
};


var imElem,enlarged;
function full_image(el,dir,imId,w,h,wf,hf){

		if(el==null)
			elem=document.getElementById('foto');
		else
			elem=el;
		imElem=elem;
			//var obal=document.getElementById('kontejner');
	var ScrollTop = document.body.scrollTop;

	if (ScrollTop == 0)
	{
    	if (window.pageYOffset)
        	ScrollTop = window.pageYOffset;
   		else
        	ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	
	if(full==1){
		if(elem.style.position=='relative' && enlarged==0)
		{
			elem.src='./galery/nahled.php?adr='+dir+'&obr='+imId+'';
			elem.style.opacity=0.0;
			elem.style.position='absolute';
			elem.style.left='10%';
			elem.style.top=(ScrollTop!=0?(ScrollTop-100):5)+'px';
			elem.style.zIndex='10000';
			//obal.style.position='absolute';
			cycling=setInterval('enlargeIm('+wf+','+hf+')',20);
			enlarged=1;
		}
		else{
			elem.src='./galery/galfce.php?adr='+dir+'&obr='+imId;
			elem.width=w;
			elem.height=h;
			elem.style.position='relative';
			elem.style.left='auto';
			elem.style.top='auto';
			elem.style.zIndex=0;
			//obal.style.position='relative';
			enlarged=0;
				}
							}
											};
											
											 /*: './galery/nahled.php?adr=".$_GET['adr']."&amp;obr=".$_GET['obr']."'*/
function enlargeIm(wf,hf)
{
	var offset=hf/wf;

		if(imElem.width<wf)
			imElem.width+=20;
		if(imElem.height<hf)
			imElem.height+=parseInt(20*offset);
		if(parseFloat(imElem.style.opacity)<=1.0)
			imElem.style.opacity=parseFloat(imElem.style.opacity)+0.07;
			
		//alert(imElem.style.opacity);
		if(imElem.width>=wf && imElem.height>=hf)
		{
			clearInterval(cycling);
			imElem.style.opacity=1;
		}
		
}



var cont=0;
var actTop=0;
var actLeft=0;
var smElem;
var stepT=15;
var stepL;
var stop=0;
var stopL=0;
var smooth;										 
function moveLeft()
{
	smElem.style.width=actLeft+"px";
	actLeft+=stepL;
	if(actLeft>=stopL)
	{
		clearInterval(smooth);
		smooth=setInterval("moveDown()",20);
	}
}
function moveRight()
{
	smElem.style.width=actLeft+"px";
	actLeft-=stepL;
	if(actLeft<=5)	
	{
		clearInterval(smooth);
		smElem.style.visibility='hidden';
		cont=1;
		actLeft=0;
		actTop=0;
		smElem.style.opacity=1;
	}

}function moveDown()
{
	smElem.style.height=actTop+"px";
	if(smElem.style.opacity<0.9)
	{
		smElem.style.opacity=parseFloat(smElem.style.opacity)+0.05;
	}
	actTop+=stepT;
	if(actTop-15>=stop)
	{
		clearInterval(smooth);
		smElem.style.height=stop+"px";
		smElem.style.opacity=1;
	}

}
function moveUp()
{
	smElem.style.height=actTop+"px";
	actTop-=stepT;
	if(smElem.style.opacity>0.4)
	{
		smElem.style.opacity=parseFloat(smElem.style.opacity)-0.05;
	}
	if(actTop<=0)	
	{
		clearInterval(smooth);
		smooth=setInterval("moveRight()",20);
	}

}
cont=1;
function smoothStart(id)
{
	clearInterval(smooth);
	stepT=10;
	stepL=10;
	smElem=document.getElementById(id);
	if(stop==0)
		stop=smElem.offsetHeight;
	if(stopL==0)
		stopL=smElem.offsetWidth;
	smElem.style.height="5px";
	smElem.style.width="0px";
	smElem.style.visibility='visible';
	smElem.style.opacity=0.2;
	smooth=setInterval("moveLeft()",20);
}
function smoothClose()
{
	clearInterval(smooth);
	stepT=stop/10;
	smooth=setInterval("moveUp()",20);
}
