function LoadPage (page) {
	var strSubmit="";
	strSubmit+="page="+page;
	
	new Ajax.Request('pages.php', {
		method: 'post',
		parameters: strSubmit, 
		onSuccess: function(transport) {					
			$("left_page").innerHTML=transport.responseText;
		},
		onFailure: function () {					
			
		}
	});		
}

function LoadImages (cat,page) {
	var strSubmit="cat="+cat+"&page="+page;
		
	new Ajax.Request('images.php', {
		method: 'post',
		parameters: strSubmit, 
		onSuccess: function(transport) {															
			$('rigth').innerHTML=transport.responseText;			
		},
		onFailure: function () {					
			alert(strResponse);
		}
	});	
	
	return false;
}

function EnlargeYP (id,nolink) {		
	var arrayPageSize = getPageSize();
	
	//BACK
	$("cnt").insert({after: "<div id=\"wOver_overlay\" style=\"display: none;\"></div>"});	

	$("wOver_overlay").style.width=arrayPageSize[0]+"px";
	$("wOver_overlay").style.height=arrayPageSize[1]+"px";	
	new Effect.Appear('wOver_overlay', { duration: 0.2, from: 0.0, to: 0.6 });
	
	//CNT
	$("cnt").insert({top: "<div id=\"wOver\" style=\"display:none;\"><div id=\"wOverContainer\"><img src=\"/images/loader.gif\" /></div></div>"});
	SetCntPos(16,16,true);
	$("wOver").show();	
	
	//GET INFO
	var strSubmit="";
	strSubmit+="action=GETZOOM&id_img="+id;
	
	new Ajax.Request('index.php', {
		method: 'post',
		parameters: strSubmit, 
		onSuccess: function(transport) {					
			txt=transport.responseText;
			if (txt[0]=="#")
				PrintError (txt);
			else
				PrintZoom(txt,nolink);
		},
		onFailure: function () {					
			alert(strResponse);
		}
	});		
}

function SetCntPos (_width,_height,_small) {
	$("wOverContainer").style.width=_width+"px";
	if (_height==null)
		$("wOverContainer").style.height="auto";
	else
		$("wOverContainer").style.height=_height+"px";
	$("wOverContainer").style.margin="0px auto"
	
	var arrayPageScroll = getPageScroll();
	var _wTop = arrayPageScroll[1] + (arrayPageSize[3] / (_small!=null?2:10));
	var _wLeft = arrayPageScroll[0];
	if (_small!=null) {	
		$("wOver").style.top=_wTop+"px";		
	} else {		
		if (window.XMLHttpRequest) //TEMP detect new browser
			$("wOver").style.top=(arrayPageScroll[1]+30)+"px";
		else
			$("wOver").style.top=30+"px";
	}
	$("wOver").style.left=_wLeft+"px";
}

function PrintZoom (jtxt,nolink) {
		$("wOver").hide();
		$$("#wOverContainer img")[0].remove();
		
		var data="";
		var cnt="";
		if (!jtxt.isJSON())
		{			
			PrintError("#1138 error !JSON<br />"+jtxt);
			return
		}
		data=jtxt.evalJSON();
		
		cnt ="<div class=\"zoomCnt\">";
		cnt+="<a href=\"javascript:void(0);\" onclick=\"CloseZoom ()\">close window</a><br />";
		cnt+="<img src=\""+data.image+"\" width=\""+data._w+"\" height=\""+data._h+"\" /><br />";
		if (nolink==undefined) {		
			cnt+="<a href=\"javascript:void(0);\" onclick=\"AddtoLB('"+data.id+"')\">add to lightbox</a><br />";
		}
		cnt+="<a href=\"javascript:void(0);\" onclick=\"window.open('/download.php?img="+data.img+"&medium=Y','_wdwnMNG','height=150,width=300')\">download small size</a><br />";
			if (data.big!="")
				cnt+="<a href=\"javascript:void(0);\" onclick=\"window.open('/download.php?img="+data.img+"','_wdwnMNG','height=150,width=300')\">download full size ("+data.bigSize+")</a><br />";
		cnt+="<br /><strong>"+data.title+"</strong><br />";
		if (data.desc!="")
			cnt+=data.desc+"<br /><br />";
		cnt+="</div>";
		
		SetCntPos((parseInt(data._w)+40),null);
		$("wOverContainer").insert({top: cnt});		
		
		new Effect.Appear("wOver", { duration: 0.2, 
																 from: 0.0, 
																 to: 1, 
																 afterFinish: function () { //set bg new height
																 		var newPageSize = getPageSize();
																		$("wOver_overlay").style.height=newPageSize[1]+"px";	
																}});		
		
}

function PrintError (txt) {
		$("wOver").hide();
		$("wOverContainer").innerHTML="";
		
		var cnt="";
		cnt ="<div class=\"zoomCnt\">";
		cnt+="<strong style=\"color:#cc0000;\">"+txt+"</strong><br /><br />";
		cnt+="<center><a href=\"javascript:void(0);\" onclick=\"CloseZoom ()\">close window</a></center>";
		cnt+="</div>";

		SetCntPos(350,null);
		$("wOverContainer").insert({top: cnt});
		
		new Effect.Appear("wOver", { duration: 0.2, from: 0.0, to: 1 });
}

function CloseZoom () {
	$("wOver_overlay").remove();
	$("wOver").remove();	
}


// -----------------------------------------------------------------------------------
// getPageSize() from lightbox by Lokesh Dhakar
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

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

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

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

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