if (window.innerHeight)
	{
		screenHeight = window.innerHeight;
		screenWidth = window.innerWidth;
	}
	else
	{
		screenHeight = document.body.offsetHeight;
		screenWidth = document.body.offsetWidth;
	}
		
	function doLight(st, obj, e)
	{
		
		var cloudimg=document.getElementById("cloudimg");
		var oCloud=document.getElementById("cloud");
		
		cloudimg.style.backgroundImage="url('/img/design/loading.gif')";
		
		oldPos=obj.style.backgroundPosition.split(" ");
		if(st == 'on')
		{
			obj.style.backgroundPosition=oldPos[0] + ' -28px';
			/*******
			* show cloud
			*******/
			
			
			//get image
			lastSlash=obj.href.lastIndexOf("/");
			file = obj.href.substr(0, lastSlash) + "/prw_" + obj.href.substr(lastSlash+1);
			
			//load image
			oImg=document.createElement("img");
			oImg.onload=function()
			{
				cloudimg.style.backgroundImage="url('" + oImg.src + "')";
			}
			oImg.src=file;
			
			//show cloud
			oCloud.style.display="block";
		}
		else
		{
			obj.style.backgroundPosition=oldPos[0] + ' 0px';	
			//cloud	
			oCloud.style.display="none";	
		}

	}
	
	function moveCloud(e)
	{
		
		var oCloud=document.getElementById("cloud");
		
		e = e || window.event;
		
		if (e.pageX || e.pageY) {
			x = e.pageX; y = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			x = e.clientX + document.body.scrollLeft; y = e.clientY + document.body.scrollTop;
		}
		
		//markers
		vertMarker=(screenHeight/2);
		horizMarker=screenWidth-250;
		
		if(x < horizMarker)
		{
			if(y<vertMarker)
			{
				direct="tl";
				cloudShift=new Array(15,15);
			}
			else
			{
				direct="bl";
				cloudShift=new Array(15,-200);
			}
		}
		else
		{
			if(y<vertMarker)
			{
				direct="tr";
				cloudShift=new Array(-200,15);
			}
			else
			{
				direct="br";
				cloudShift=new Array(-200,-200);
			}		
		}
		oCloud.style.left=(x+ cloudShift[0]) + "px";
		oCloud.style.top=(y + cloudShift[1]) + "px";

		//choose cloud corner
		oCloud.className=direct;
	}
	
	function doShow(obj)
	{
		doLight('off', obj);
		
		obj.parentNode.parentNode.style.border="1px solid #B00309";
		document.getElementById("overlay").style.display="block";
		
		i=0;
		t=setInterval("changeOverlayColor(i); i=i+0.05; if(i>0.7) {clearInterval(t);}", 5);
		
		oImg=document.createElement("IMG");
		oImg.onload=function()
		{
			oImgCnt=document.getElementById("imgbox");
			oImgCnt.height=oImg.height;
			oImgCnt.width=oImg.width;
			oImgCnt.style.marginTop="-" + (Math.round(oImg.height/2)+10) + "px";
			oImgCnt.style.marginLeft="-" + Math.round(oImg.width/2) + "px";
			oImgCnt.src=oImg.src;
			oImgCnt.style.display="block";
			
			//show gradient control
			document.getElementById("gradient").style.display='block';			
		}
		oImg.src=obj.href;
	}
	
	function doHide()
	{
		changeOverlayColor(0);
		document.getElementById("imgbox").style.display="none";		
		document.getElementById("overlay").style.display="none";
		document.getElementById("gradient").style.display='none';
	}

	var prev_tab=null;			//id of previous selected tab
	var gall_lib=new Array();	//cached gallery html code
	gall_lib[4]=render4();
	var curGid;					//current group ID
	
	function render4()
	{
		return '<div style="width: 488px; height: 285px; background: url(/img/gallery/4h/tolko-clients.jpg) no-repeat left top;"></div>';
		
	}
	
	function get_imgs(gid, force)
	{
		
		if(typeof force == "undefined") force=false;
		
		if(prev_tab != gid)
		{
			curGid=gid;
			//tab
			document.getElementById("tab" + gid).className+=' cur';
			
			if(document.getElementById("tabsep" + gid))
				document.getElementById("tabsep" + gid).className+=' cur_l';
			if(document.getElementById("tabsep" + (gid+1)))
				document.getElementById("tabsep" + (gid+1)).className+=' cur_r';
				
			if(prev_tab != null)
			{
				oPrevTab=document.getElementById("tab" + prev_tab);
				oPrevTab.className=oPrevTab.className.replace(' cur', '');
				
				if(document.getElementById("tabsep" + prev_tab))
				{
					oPrevTabSep=document.getElementById("tabsep" + prev_tab);
					oPrevTabSep.className=oPrevTabSep.className.replace(' cur_l', '');					
				}
				if(document.getElementById("tabsep" + (prev_tab+1)))
				{
					oPrevTabSep=document.getElementById("tabsep" + (prev_tab+1));
					oPrevTabSep.className=oPrevTabSep.className.replace(' cur_r', '');					
				}
			}
			prev_tab=gid;
			//cache
			if(!force && gall_lib[gid] != null)
			{
				document.getElementById("thumbs").innerHTML=gall_lib[gid];
				return false;
			}				
		}
		else if(!force)
		{
			return false;
		}
				
			
		//images
		
		if(!force && typeof gall_lib[gid] !== "undefined")
		{
			document.getElementById("thumbs").innerHTML=gall_lib[gid];
			return;
		}
			
		var req=new JsHttpRequest();
		req.onreadystatechange=function()
		{
	        //alert(req.readyState);
			if(req.readyState==4)
	        {
				if(req.responseJS == null)
				{
					return false;
				}
				
				if(req.responseJS.imageList == null || req.responseJS.imageList == false)
					total=0;
				else
				{
					total=req.responseJS.imageList.length;
					lastModDate = req.responseJS.lastModDate;
				}
				gall_lib[gid]="";
				for(i=1; i<=6; i++)
				{
					for(j=1; j<=8; j++)
					{
						ij=(i-1)*8+(j-1);
						if(ij >= total)
							gall_lib[gid]+="<div class=\"thumb\"><div class=\"thumbimg\">&nbsp;</div></div>";
						else
						{ 
							img=req.responseJS.imageList[ij];
							
							if(typeof admin == "undefined")
								var oD="<div></div>";
							else
								var oD="<div class=\"img_droper\" onclick=\"doDelete(" + img["id"] + ", event);\">x</div>";
								
							thumb="<div class=\"thumb\"><div style=\"position: relative;\"><a href=\"/img/gallery/" + gid + "/" + img["filename"] + "\" onmouseover=\"doLight('on', this, event);\" onmouseout=\"doLight('off', this);\" onmousemove=\"moveCloud(event)\" onclick=\"doShow(this); return false;\" id=\"thumb_" + img["id"] + "\"  class=\"thumbimg\" style=\"background: url('/img/gallery/" + gid + ".jpg?" + lastModDate + "') -" + (40*img["position"]) + "px 0px no-repeat\" target=\"_blank\"></a>" + oD + "</div></div>";
							gall_lib[gid]+=thumb;
						}
							
					}
				}
				document.getElementById("thumbs").innerHTML=gall_lib[gid];
				document.getElementById("thumbs").style.background='none';
	        }
	    }
	    req.open(null,'/gallery/getimagelist',true);
	    req.send({"gid": gid});
	    
		document.getElementById("thumbs").innerHTML='';
		document.getElementById("thumbs").style.background="url('/img/design/small_preloader.gif') no-repeat center center";
	}
	
	function changeOverlayColor(color)
	{
		var o=document.getElementById("overlay");
		if(typeof o.style.opacity=='string')
		{
			o.style.opacity=color;
		}
		else if(typeof o.style.MozOpacity=='string')
		{
			o.style.MozOpacity=color;
		}
		else if(typeof o.style.KhtmlOpacity=='string')
		{
			o.style.KhtmlOpacity=color;
		}
		else
		{
			if(o.filters['DXImageTransform.Microsoft.alpha'])
			{
				o.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+(color*100)+')';
			}
			else
			{
				o.style.filter = 'alpha(opacity='+(color*100)+')';
			}
		}	
	}