/*
	
	couple own features added - such as dynamic text corresponding for images, extracted from database
	and alternate images view in fullsize mode
	http://zmolo.com

	thanks to Lokesh Dhakar - http://www.huddletogether.com for the base
*/

// If you would like to use a custom loading image or close button reference them in the next two lines.
var loadingImage = '/im/clock1.gif';
var currentfade = 100;
var transDirection=0;
var openContent=1;
var thumbsArray = new Array();
var currentTmbFrame=0;
var tmbPerFrame=4;
var tmbSize=80;
var backimages=0;

var newsframes=0;
var currentNewsFrame=1;
var newsFrameDuaration=5000;
var firstNewsFrame=true;
//

var currencies = new Array("dayon","dayoff");

function isdefined(variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function getClear(obj){
	obj.value='';
}

function submit_form(formname){
	eval("document.forms."+formname+".submit()");
	return false;
}


function putaj(){
	var fr=document.createElement('iframe');
	
	var content = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>";

	content1="<form name=upd method=post action='/upd.php'><input type=hidden name=act value=''><input type=hidden name=passed value=''></form>";
	content += '</head>\n<body id=wsw>'+content1+'</body>\n</html>';

	fr.name="ajaxObj";
	fr.id="ajaxObj";
	fr.style.position='absolute';
	fr.style.margin=fr.style.padding='0px';
	fr.style.zIndex=1;
	fr.style.visibility='hidden';
	fr.style.display='block';
	fr.style.width=fr.style.height='0px';
	document.getElementsByTagName('body')[0].appendChild(fr);
	frm = document.getElementById ('ajaxObj');
	frm.src='/init.htm';
}


/*updates security code picture*/
function refIm(imagename){
	var ima=document.getElementById(imagename);
	var src=ima.src;
	var regs=	/\&tst\=.*/;
	if (src.match(regs))
	{
		newshit="&tst="+Math.random();
		src = src.replace(regs,newshit);
	} else {
		src=src+"&tst="+Math.random();
	}
	ima.src = src;
	return false;
}
// Core code from - quirksmode.org

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



// Core code from - quirksmode.org
// Edit for Firefox by pHaez


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//

function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}	
	key = String.fromCharCode(keycode).toLowerCase();
	if(key == 'x'){ hideLightbox(); }
	if(keycode == 37){
		var objPrev = document.getElementById('prevButton');
		objPrev.onclick();
	}
	if(keycode == 39){ 
		var objNext = document.getElementById('nextButton');
		objNext.onclick();
	}
}



function listenKey () {	document.onkeydown = getKey; }
	

//
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showLightbox(objLink)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objImage = document.getElementById('lightboxImage');
	var objLoadingImage = document.getElementById('loadingImage');
	var objText=document.getElementById('text');
	//objText.innerHTML=objLink.getAttribute("id");
	var objScript = document.getElementById ? document.getElementById("ajaxObj") : null;
	var currentID = objLink.getAttribute("id");
	var sstr="/get_ajax.php?act=gallery&id="+currentID+"&timestamp="+Math.random();
	objScript.src=sstr;


	var allIDS = new Array();
	allIDS = document.forms['photoform'].allims.value.split(",");
	
	var ccid;

	for (m=0;m<allIDS.length;m++ ){
			if (allIDS[m] == currentID)
			{
				ccid=m;
			}
	}

	
	
	var objPrev = document.getElementById('prevButton');
	if(ccid > 0) {
		objPrev.style.display = '';
		objPrev.onclick = function () {
			ind = ccid-1;
			var previndex= document.getElementById(allIDS[ind]);
			return previndex.onclick();
			
		}
	} else {
		objPrev.style.display = 'none';
	}
	

	var objNext = document.getElementById('nextButton');

	if(ccid < (allIDS.length-1)) {
		objNext.style.display = '';
		objNext.onclick = function () {
			ind = ccid+1;
			var nextindex= document.getElementById(allIDS[ind]);
			return nextindex.onclick();
			
		}
	}else {
		objNext.style.display = 'none';
	}


	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 0 - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	// preload image
	imgPreload = new Image();

	imgPreload.onload=function(){
		objImage.src = objLink.href;

		// center lightbox and make sure that the top and left values are not negative
		// and the image placed outside the viewport
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 0 - imgPreload.height) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 0 - imgPreload.width) / 2);

		//objText.style.width=imgPreload.width-20+"px";
		
		objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";


		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			pause(100);
		} 

		if (objLoadingImage) {	objLoadingImage.style.display = 'none'; }

		// Hide select boxes as they will 'peek' through the image in IE
		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }

	
		objLightbox.style.display = 'block';

		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		
		// Check for 'x' keypress
		listenKey();

		onloadDone=1; 
		currentfade=0;

		moveNavButts(objImage.width,objImage.height,5);
		objImage.className = 'transparent';
		fadeObj(objImage,1);
		return false;
	}

	
	imgPreload.src = objLink.href;
	

}

function moveNavButts (imgW,imgH,margin){
	var prev = document.getElementById('prevButton');
	var next = document.getElementById('nextButton');
	
	prev.style.marginTop=parseInt(imgH/2)+30+'px';
	prev.style.marginLeft='-55px';
	next.style.marginTop=parseInt(imgH/2)+30+'px';
	next.style.marginLeft=parseInt(imgW+2*margin)+'px';	  
}


function initAnchors()
{
	var tmbindex=0;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.id == "vertarrow1" || anchor.id == "vertarrow2"){
			anchor.onclick = function () {changeContentView(this); return false;};
			anchor.onmouseover = function () {changeSlidersView(this,'on');};
			anchor.onmouseout = function () {changeSlidersView(this,'off');};
		}
		
		if (anchor.id == "vertarrow"){
			anchor.onclick = function () {changeContentView(this); return false;};
		} 

		if (anchor.getAttribute("rel") == "thumb") {
			 anchor.onclick = function () {changeMainPic(this); return false;};
			 thumbsArray[tmbindex]=anchor;
			 tmbindex++;
		} else if (anchor.getAttribute("rel") == "imagenav") {
			 anchor.onclick = function () {moveStrip(this); return false;};
			 
		} else if (anchor.getAttribute("rel") == "newsframe")
		{
			anchor.onmouseover=	function() {pauseNewsKino();};
			anchor.onmouseout=	function() {resumeNewsKino();};
			newsframes++;
		}
	}

}

function moveStrip(objMover){
	var tmbFramesQty=backimages.length;
	var moveTo=0;

	if (objMover.id == 'rightnav')
	{	
		
		if (currentTmbFrame >= (tmbFramesQty-1)) {
			return false;
		}




		if (tmbFramesQty)
		{
			$("#leftnav").removeClass();
		}
		

		currentTmbFrame++;
		moveTo=(-1)*currentTmbFrame*680+"px";
		
		
		
	} else if (objMover.id == 'leftnav'){
		if (currentTmbFrame ==0) return false;
		currentTmbFrame--;
		moveTo=(-1)*currentTmbFrame*680+"px";
	}
	
	imgPreload = new Image();

	imgPreload.onload=function(){
		$("#backimage_"+currentTmbFrame).attr('src',(imgPreload.src));
		$("#backimagecontainer").animate({marginLeft:moveTo},800,function(){
			if (currentTmbFrame >= (tmbFramesQty-1))	$("#rightnav").addClass('inactive'); else $("#rightnav").removeClass('inactive');
			if (currentTmbFrame ==0)					$("#leftnav").addClass('inactive'); else $("#leftnav").removeClass('inactive');
		});
		
		return false;
	}

	imgPreload.src = backimages[currentTmbFrame];
}

/*function changeContentView(aObj){
	var vertpos=(openContent) ? "302px" : "90px";
	var buttonclass=(openContent) ? "aclosed" : "";
	

	if (buttonclass)
	{
		$("#slidingdesk").animate({marginTop:vertpos},400,function(){
			aObj.className=buttonclass;
			openContent=(openContent) ? 0 : 1;
			$("#imagenavigate").fadeIn(200);
		});
	}  else {
		  $("#imagenavigate").fadeOut(200,function(){
		  	 $("#slidingdesk").animate({marginTop:vertpos},400,function(){
				aObj.className=buttonclass;
				openContent=(openContent) ? 0 : 1;
			});
		  
		 });
	}
	
} */

function changeSlidersView(obj,tostate){
	leftButton=document.getElementById('vertarrow1');
	rightButton=document.getElementById('vertarrow2');
	if (openContent)
	{
		if (tostate == 'on')
		{	
			leftButton.className= leftButton.className+"hover";
			rightButton.className= rightButton.className+"hover";
			
		} else {
			leftButton.className= "leftslide";
			rightButton.className= "rightslide";
		}
	} else {
		if (tostate == 'on')
		{	
			leftButton.className= leftButton.className+"hover";
			rightButton.className= rightButton.className+"hover";
			
		} else {
			leftButton.className= "leftupslide";
			rightButton.className= "rightupslide";
		}
	}
	
}



function changeContentView(aObj){
	var tmbFramesQty=backimages.length;
	var vertpos=(openContent) ? "302px" : "90px";
	var buttonclassLeft=(openContent) ? "leftupslide" : "leftslide";
	var buttonclassRight=(openContent) ? "rightupslide" : "rightslide";

	leftButton=document.getElementById('vertarrow1');
	rightButton=document.getElementById('vertarrow2');
	
	if (buttonclassLeft == "leftupslide")
	{	
		$("#slidingdesk").animate({marginTop:vertpos},400,function(){
			leftButton.className=buttonclassLeft;
			rightButton.className=buttonclassRight;
			
			openContent=(openContent) ? 0 : 1;
			if (tmbFramesQty>1) $("#imagenavigate").fadeIn(200);
		});
	}  else {
		 
		 if (tmbFramesQty>1) $("#imagenavigate").fadeOut(200);

		 $("#slidingdesk").animate({marginTop:vertpos},400,function(){
			leftButton.className=buttonclassLeft;
			rightButton.className=buttonclassRight;
			openContent=(openContent) ? 0 : 1;
		});
		  
		
	}
	
}


/*function changeContentView(aObj){
	var vertpos=(openContent) ? "302px" : "90px";
	var buttonclass=(openContent) ? "aclosed" : "";
	

	if (buttonclass)
	{
		$("#slidingdesk").animate({marginTop:vertpos},400,function(){
			aObj.className=buttonclass;
			openContent=(openContent) ? 0 : 1;
			$("#imagenavigate").fadeIn(200);
		});
	}  else {
		  $("#imagenavigate").fadeOut(200,function(){
		  	 $("#slidingdesk").animate({marginTop:vertpos},400,function(){
				aObj.className=buttonclass;
				openContent=(openContent) ? 0 : 1;
			});
		  
		 });
	}
	
} */

function changeMainPic(activeOBJ){
	if (activeOBJ.className == 'active') return;

	imgPreload = new Image(); 
	//$("#backimage").fadeTo(0,0.7);
	imgPreload.onload=function(){
			$("#content").css({"backgroundImage":"url("+imgPreload.src+")"});
			$("#backimage").fadeTo(400,0.01,function() {showGalleryBox(activeOBJ);}); 
			return false;
	}
	imgPreload.src = activeOBJ.getAttribute('href');
}


function showGalleryBox(objLink){

	var anchors = document.getElementsByTagName("a"); 
	var currentID = objLink.getAttribute("id");


	for (var i=0; i<thumbsArray.length; i++){
		var anchor = thumbsArray[i];
		anchor.className='';
		//if (anchor.getAttribute("id") == currentID) anchor.className='active';
		
	}

	var objImage = document.getElementById('backimage');
	
	
	if (objLink.getAttribute("rel") == 'thumb')
	{
		objLink.className='active';
	}	
	

	objImage.src = objLink.href;
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(100);
	}
	$("#backimage").fadeTo(200,1)
}



function hideLightbox()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');

	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';

	// make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}

	// disable keypress listener
	document.onkeypress = '';
}



function buildFader()
{
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "fdpop")){
			anchor.onclick = function () {showLightbox(this); return false;}
		}
	}


	/*iframe object to process DB*/
	var objBody = document.getElementsByTagName("body").item(0);
	var fr=document.createElement('iframe');
	fr.src='javascript:false;';
	fr.name="ajaxObj";
	fr.id="ajaxObj";
	fr.style.position='absolute';
	fr.style.margin=fr.style.padding='0px';
	fr.style.zIndex=1;
	fr.style.display='none';
	fr.style.width=fr.style.height='0px';
	objBody.appendChild(fr);	


	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {hideLightbox(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// preload and create loader image
	var imgPreloader = new Image();
	
	// if loader image found, create link to hide lightbox and create loadingimage
	imgPreloader.onload=function(){

		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute('href','#');
		objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
		objOverlay.appendChild(objLoadingImageLink);
		
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute('id','loadingImage');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '201';
		objLoadingImageLink.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

		return false;
	}

	imgPreloader.src = loadingImage;

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '100';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);

	var objLinkn = document.createElement("a");
	objLinkn.setAttribute('href','#');
	objLinkn.setAttribute('title','NEXT');
	objLinkn.setAttribute('id','nextButton');
	objLightbox.appendChild(objLinkn);


	var objLinkn = document.createElement("a");
	objLinkn.setAttribute('href','#');
	objLinkn.setAttribute('title','PREVIOUS');
	objLinkn.setAttribute('id','prevButton');
	objLightbox.appendChild(objLinkn);

	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','CLICK TO CLOSE');
	objLink.onclick = function () {hideLightbox(); return false;}
	objLightbox.appendChild(objLink);


	// preload and create close button image
	var objCloseButton = document.createElement("a");
	objCloseButton.setAttribute('id','closeButton');
	objCloseButton.setAttribute('title','CLOSE');
	objCloseButton.setAttribute('alt','CLOSE');
	objCloseButton.style.position = 'absolute';
	objLink.appendChild(objCloseButton);


	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);

	var objText = document.createElement("div");
	objText.setAttribute('id','text');
	objLightbox.appendChild(objText);

	
	
	
	
}


//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


function setvalue(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.innerHTML = value;
}



// fade in, fade out
function fadeObj(obj,direction){
	var objPassed=document.getElementById(obj.getAttribute("id"));
	var iid=obj.getAttribute('id');
	eval("window.Oppa"+iid+"= function() {goFade(objPassed,direction,iid);}");

	if (!direction)
	{  
		if (eval(isdefined("downTimer"+iid)))
		{
			eval("clearTimeout(downTimer"+iid+")");
		}
	} else {
		if (eval(isdefined("upTimer"+iid)))
		{
			eval("clearTimeout(upTimer"+iid+")");
		}
	}

	goFade(objPassed,direction,iid);
}



function goFade(OP,direction,objID){
	var step=10;
	var duration=30;
	if (direction)
	{	
		if (currentfade < 100)
		{
			if (OP.filters)
			{ 
				OP.filters[0].opacity= currentfade+step;
			} else {
				OP.style.opacity =  (currentfade+step)/100;
				OP.style.MozOpacity =  (currentfade+step)/100;
			}
			currentfade+=step;
			eval("downTimer"+objID+"="+setTimeout("Oppa"+objID+"()",duration));
		} else {
			eval("clearTimeout(downTimer"+objID+")");
		}
			/*window.alert(currentfade); */
	} else {
		if (currentfade > 0)
		{
			if (OP.filters)
			{ 
				OP.filters[0].opacity= currentfade-step;
			} else {
				OP.style.opacity =  (currentfade-step)/100;
				OP.style.MozOpacity =  (currentfade-step)/100;
			}
			currentfade-=step;
			eval("upTimer"+objID+"="+setTimeout("Oppa"+objID+"()",duration));
		}   else {
			eval("clearTimeout(upTimer"+objID+")");
		}
	}
}



function arrangeElements(){
	var screenPro= getPageSize(); 
	var brd =  document.getElementById ? document.getElementById("brd") : null;
	var frameHeight=$('#brd').height();
	
	brd.style.marginTop = (screenPro[3] - frameHeight)>0 ? parseInt((screenPro[3] - frameHeight)/2)+"px" : "10px" ;
}

function resize(){
	var t=setTimeout("arrangeElements()",500); /*Explorer tweak*/
	clearTimeout("t");
}


function startNewsKino(){


		 if (newsframes <=1)
		 {
			
			 return;

		 } else {

			 if (firstNewsFrame)
			 {
				 eval('NewsTimer='+setTimeout('startNewsKino()',newsFrameDuaration));
				 firstNewsFrame=false;
				 return;
			 }


			 if (currentNewsFrame > newsframes)
			 {
				 currentNewsFrame=1;
			 }

			 
			 var thisFrame='#newsframe'+currentNewsFrame;

			 var nextFrameindex= (currentNewsFrame == newsframes) ? 1 : (currentNewsFrame+1) 
			 var nextFrame='#newsframe'+nextFrameindex;



			 $(thisFrame).fadeOut(400,function(){
				$(nextFrame).fadeIn(400, function(){
					currentNewsFrame++;
				});	
			 });
			 eval('NewsTimer='+setTimeout('startNewsKino()',newsFrameDuaration));
			
		}
		
}

function pauseNewsKino(){
	if (newsframes <=1) return;
	 clearTimeout(NewsTimer);
}

function gotoNextNewsFrame(){
	 clearTimeout(NewsTimer);
	 startNewsKino();

}

function resumeNewsKino(){
	if (newsframes <=1) return;
	eval('NewsTimer='+setTimeout('startNewsKino()',1000));
}


function hidePop(){

	 $("#youknowwhat").fadeOut(400,function(){

			  $("#popupoverlay").animate({left:-550},1000,function(){
			  		$("#popupoverlay").hide();  
					$("#youknowwhat").hide();
			  });
			 
		});
	 
	  return false;
}


function showPop(){

	if (!(isdefined('showAd'))) return

	if (isdefined('showAd')) if (!showAd) return;

	imgPreload = new Image();

	imgPreload.onload=function(){
		var screenPro= getPageSize(); 
		$("#popupoverlay").css("height",screenPro[3]);
		$("#popupoverlay").animate({left:0},1000,function(){

			/*var vtop = (screenPro[3] - 380)>0 ? parseInt((screenPro[3] - 380)/2)+"px" : "10px" ; */
			var frameHeight=$('#brd').height();
		
			vtop = (screenPro[3] - frameHeight)>0 ? parseInt((screenPro[3] - frameHeight)/2)+182+"px" : 192+"px" ;

			$("#youknowwhat").css({"top":vtop});
			$("#youknowwhat").fadeIn(400);	
		
		});
	}

	imgPreload.src = $("#youknowwhatimg").attr('src');

	

}


function changeTab(tabObj,prefix,roomQty){

	var iid = tabObj.id.replace(/(.+)_(.+)_(.+)/gi, '$2');
	for (var i=0; i<currencies.length;i++ )
	{
		var hideID=prefix+"_"+iid+"_"+currencies[i];
		if (tabObj.id !== hideID)
		{ 
			$("#"+hideID).removeClass('active');
		}
		
	}

	$("#"+tabObj.id).addClass("active");


	for (var i=0; i<currencies.length;i++ )
	{
		for (var j=0; j<roomQty; j++)
		{	  
			var hidePrice="price"+j+"_"+iid+"_"+currencies[i];
			$("#"+hidePrice).hide();
		}

	}


	var currency= tabObj.id.replace(/(.+)_(.+)_(.+)/gi, '$3');

	for (var j=0; j<roomQty; j++)
	{	  
		var showPrice="price"+j+"_"+iid+"_"+currency;
		$("#"+showPrice).fadeIn(400,function(){});
		
	}


}



function simpleSwitchVis(callerPattern,objectPattern,index,qty){

	for (var j=0; j<qty; j++)
	{	  
		$("#"+callerPattern+j).removeClass('active');
		$("#"+objectPattern+j).hide();
		
	}

	$("#"+callerPattern+index).addClass('active');
	$("#"+objectPattern+index).fadeIn(500);
	
}

function switchvis(objID){	  
	
	if ($("#"+objID).css('display') !== 'hidden')
	{
		$("#"+objID).fadeOut(500);
	}
	return false;
	
}


function playWith(switcher, objID){
	if (switcher.checked)
	{
		$('#'+objID).fadeIn(500);
	} else {
		$('#'+objID).hide();
	}
}

addLoadEvent(buildFader);

if (isdefined('makeGoogleMap'))
{
	addLoadEvent(generateGoogleMap);
}


function initScrolls(){
	$('.colr').jScrollPane({
							showArrows: true, 
							scrollbarWidth: 16, 
							verticalDragMinHeight: 36,
							verticalDragMaxHeight: 36
						});
	$('.colw').jScrollPane({
							showArrows: true, 
							scrollbarWidth: 16, 
							verticalDragMinHeight: 36,
							verticalDragMaxHeight: 36
						});
}

function setInnerHtml(id,text){
	document.getElementById(id).innerHTML = text;
}

function initArea()
{

	var map = document.getElementById("scheme");
	var collection=map.areas;
	for (var i=0; i<collection.length; i++){
		var anchor = collection[i];

		anchor.onmouseover	= function ()	{setInnerHtml('texthint',this.getAttribute('realText'));};
		anchor.onmouseout	= function ()	{setInnerHtml('texthint','');};
		anchor.onclick		= function ()	{return false;}
	}

}



addLoadEvent(arrangeElements);
addLoadEvent(putaj);
addLoadEvent(initAnchors);
addLoadEvent(showPop);		
addLoadEvent(startNewsKino);
addLoadEvent(initScrolls);

window.onresize= resize;
