var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
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;
	}

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function $(id) {
	return document.getElementById(id);
}

/*Array.prototype.push = function(value) {
	this[this.length] = value;
	return this.length;
}
*/
function doane(event) {
	e = event ? event : window.event;
	if(is_ie) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}

function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	while((obj = obj.offsetParent) != null) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset };
}


var zoomobj = Array();var zoomadjust;var zoomstatus = 1;
function clearimgb(){
	var ps=document.getElementById("content").getElementsByTagName("IMG")
for(s=0;s<ps.length;s++){
	ps[s].style.borderBottom="0"
	}
	}
function zoom(fotoid,iw,ih,zimg,pid,purl) {
//var objHTML = document.getElementsByTagName("html").item(0);
//objHTML.style.overflow="hidden"
//document.body.scroll="no"
clearimgb()
var obj=document.getElementById(fotoid)
obj.style.borderBottom="5px solid #E60046"
var arrayPageSize = getPageSize();
	if(!zoomstatus) {
		window.open(zimg, '', '');
		return;
	}
	if(!zimg) {
		zimg = obj.src;
		
	}
	if(!$('zoomimglayer_bg')) {
		div = document.createElement('div');
		div.id = 'zoomimglayer_bg';
		div.style.position = 'absolute';
		div.style.left = div.style.top = '0px';
		div.style.width = '100%';
		div.style.height = arrayPageSize[1]+ 'px';
		div.style.background = '#000 url(../images/blackdot.gif)';
		div.style.display = 'block';
		div.style.zIndex="10"
		div.style.cursor="pointer"
		div.onclick=zoomclose;
		div.title=" click 'X' to close it.  "
		div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
		div.style.opacity = 0.6;
		
		$('append_parent').appendChild(div);
			//fadeIn("zoomimglayer_bg",0.8)
		div = document.createElement('div');
		div.id = 'zoomimglayer';
		div.style.position = 'absolute';
		div.className = 'popupmenu_popup';
		div.style.padding = 0;
		$('append_parent').appendChild(div);
	}
	else{
	$("zoomimglayer_bg").style.display="block"
		
	}
//FadeIn("zoomimglayer_bg",80)
	zoomobj['srcinfo'] = fetchOffset(obj);
	zoomobj['srcobj'] = obj;
	zoomobj['zimg'] = zimg;
	if(document.all){
zoomobj['zurl']=escape("/photos/"+purl.split("/")[4])}
else{
zoomobj['zurl']="/photos/"+purl.split("/")[4]
	}
	ig=zoomobj['zimg'].split("/")
	$('zoomimglayer').style.display = '';
	$('zoomimglayer').style.left = zoomobj['srcinfo']['left'] + 'px';
	$('zoomimglayer').style.top = zoomobj['srcinfo']['top'] + 'px';
	$('zoomimglayer').style.width = zoomobj['srcobj'].width + 'px';
	$('zoomimglayer').style.height = zoomobj['srcobj'].height + 'px';
	$('zoomimglayer').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=70,finishOpacity=70,style=0)';
	$('zoomimglayer').style.opacity = 0.7;
	$('zoomimglayer').style.zIndex = 999;
	zoomobj['bzimg']=ig[0]+'//'+ig[2]+'/b_'+ig[3]+'/b_'+ig[4]
	$('zoomimglayer').innerHTML = '<table width="100%" height="100%" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle" style="color:#fff;background:#a63941;font-weight:bold"><div style="position:absolute;top:2px;right:3px"><a href="javascript:void(0)" onclick=zoomclose() style="color:#fff">X</a></div>loading...<img src=/images/loading.gif></td></tr></table><div style="position:absolute;top:-100000px;visibility:hidden;overflow:hidden"><img onload="zoomimgresize(this,'+pid+','+iw+','+ih+',\''+zoomobj['zurl']+'\')" src="' + zoomobj['bzimg']+'"></div>';

}

var zoomdragstart = new Array();
var zoomclick = 0;
function zoomdrag(e, op) {
	if(op == 1) {
		zoomclick = 1;
		zoomdragstart = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
		zoomdragstart[2] = parseInt($('zoomimglayer').style.left);
		zoomdragstart[3] = parseInt($('zoomimglayer').style.top);
		doane(e);
	} else if(op == 2 && zoomdragstart[0]) {
		zoomclick = 0;
		var zoomdragnow = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
		$('zoomimglayer').style.left = (zoomdragstart[2] + zoomdragnow[0] - zoomdragstart[0]) + 'px';
		$('zoomimglayer').style.top = (zoomdragstart[3] + zoomdragnow[1] - zoomdragstart[1]) + 'px';
		doane(e);
	} else if(op == 3) {
		//if(zoomclick) zoomclose();
		zoomdragstart = [];
		doane(e);
	}
}
function gurl(u){
	if(u.indexOf("b_")>0){
		uu=u
	}
	else{
re = /m_/g; 
g=u.replace(re,"")
ig=g.split("/")
uu=ig[0]+'//'+ig[2]+'/b_'+ig[3]+'/b_'+ig[4]
}
return uu
}
function getppid(qu){
qre = /p/g; 
qg=qu.replace(qre,"")
return qg
}
function iload(){
document.getElementById("iload").innerHTML=""
fadeIn("zoomimg",0) 
}

function getnp(pid,t){
clearimgb()
//obj.style.borderBottom="5px solid #E60046"
document.getElementById("iload").innerHTML="<img src=/images/loading.gif align=absmiddle> Loading......  "

document.getElementById("zoomimg").style.filter = "alpha(opacity:40)";
document.getElementById("zoomimg").style.KHTMLOpacity = 0.4;
document.getElementById("zoomimg").style.MozOpacity = 0.4;
document.getElementById("zoomimg").style.opacity = 0.4;

var aa=document.getElementById("content").getElementsByTagName("IMG")
psrc=document.getElementById("zoomimg").src

p1=psrc.split("_")
for(i=0;i<aa.length;i++){

	if(aa[i].src.indexOf(p1[2])>0){
		if(i!=0){
			if(i==aa.length-1){
			ppsrc=gurl(aa[i-1].src)
			ppid=getppid(aa[i-1].id)
			nnsrc=gurl(aa[0].src)
			if(t=="p"){document.getElementById("pwh").innerHTML="Size :"+aa[i-1].alt.split(",")[0]}
			if(t=="n"){document.getElementById("pwh").innerHTML="Size :"+aa[0].alt.split(",")[0]}
			nnid=getppid(aa[0].id)
			}else{
			ppsrc=gurl(aa[i-1].src)
			
			ppid=getppid(aa[i-1].id)
			nnsrc=gurl(aa[i+1].src)
			if(t=="p"){document.getElementById("pwh").innerHTML="Size :"+aa[i-1].alt.split(",")[0]}
			if(t=="n"){document.getElementById("pwh").innerHTML="Size :"+aa[i+1].alt.split(",")[0]}
			nnid=getppid(aa[i+1].id)
			}
		}
		else{
		ppsrc=gurl(aa[aa.length-1].src)
		
		ppid=getppid(aa[aa.length-1].id)
		nnsrc=gurl(aa[i+1].src)
		if(t=="p"){document.getElementById("pwh").innerHTML="Size :"+aa[aa.length-1].alt.split(",")[0]}
		if(t=="n"){document.getElementById("pwh").innerHTML="Size :"+aa[i+1].alt.split(",")[0]
	nnid=getppid(aa[i+1].id)}
		}
		document.getElementById("zoomimg").onload=new Function("iload()")
		if(t=="p"){document.getElementById("zoomimg").src=ppsrc
if(document.all){
puurl=escape("/photos/"+document.getElementById("p"+ppid).parentNode.href.split("/")[4])
}
else{
puurl="/photos/"+document.getElementById("p"+ppid).parentNode.href.split("/")[4]
	}
document.getElementById("phref").href=puurl
document.getElementById("thref").href=puurl
document.getElementById("fotolink").href=puurl
document.getElementById("p"+ppid).style.borderBottom="5px solid #E60046"}
else{document.getElementById("zoomimg").src=nnsrc
	if(document.all){
nuurl=escape("/photos/"+document.getElementById("p"+nnid).parentNode.href.split("/")[4])}
else{
	nuurl="/photos/"+document.getElementById("p"+nnid).parentNode.href.split("/")[4]
	}
document.getElementById("phref").href=nuurl
document.getElementById("thref").href=nuurl
document.getElementById("fotolink").href=nuurl
document.getElementById("p"+nnid).style.borderBottom="5px solid #E60046"}
		
		break;
	}
}
}
function zoomST(c,pid,pw,ph,pu) {
	if($('zoomimglayer').style.display == '') {
		$('zoomimglayer').style.left = (parseInt($('zoomimglayer').style.left) + zoomobj['x']) + 'px';
		$('zoomimglayer').style.top = (parseInt($('zoomimglayer').style.top) + zoomobj['y']) + 'px';
		$('zoomimglayer').style.width = (parseInt($('zoomimglayer').style.width) + zoomobj['w']) + 'px';
		$('zoomimglayer').style.height = (parseInt($('zoomimglayer').style.height)+ zoomobj['h']) + 'px';
		var opacity = c * 20;
		$('zoomimglayer').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ',finishOpacity=100,style=0)';
		$('zoomimglayer').style.opacity = opacity / 100;
		c++;
		if(c <= 5) {
			setTimeout('zoomST(' + c + ','+pid+','+pw+','+ph+',\''+pu+'\')', 5);
		} else {
			zoomadjust = 1;
			$('zoomimglayer').style.filter = '';
			$('zoomimglayer_bg').style.display = '';
			$('zoomimglayer').innerHTML = '<table cellspacing="0" cellpadding="0"><tr><td align="right" id="zoomimgbox"><div id="xx" style="z-index:20;position:absolute;right:8px;bottom:5px;display:none" onmouseover="clearclosewin()" onmouseout="hiddenit()" ><ul id="tt"><li><a href="javascript:void(0)" onclick="zoomclose()" class="close mar" title="close"><h2>Close</h2></a></li><li><a href="'+pu+'" class="open mar" title="Zoom" target="_blank" id="phref"><h2>Zoom</h2></a></li><li><a href="javascript:getnp(\'p'+pid+'\',\'p\');"  class="left mar" title="Prev"><h2>Prev</h2></a></li><li><a href="javascript:getnp(\'p'+pid+'\',\'n\');" class="right mar" title="Next"><h2>Next</h2></a></li></ul></div><div class="toolbar" id="tbo" style="z-index:21"><b id="iload" style="color:#a63941;"></b><b id="pwh">Size :'+pw+'X'+ph+' </b>  &nbsp; <a href="'+pu+'" target="_blank" id="thref" onclick="setTimeout(\'zoomclose()\',\'50\')">Zoom</a> | <a href="javascript:void(0)" onclick="zoomclose()"><b style="font-size:14px;font-family:vardana">X</b></a> </div><a href="'+pu+'" target="_blank" id="fotolink" onclick="setTimeout(\'zoomclose()\',\'50\')"><img id="zoomimg" style="cursor: pointer; margin: 5px;" src="' + zoomobj['bzimg'] + '"  onmouseover="showit()" onmouseout="hiddenit()"></a></td></tr></table>';
			$('zoomimglayer').style.overflow = 'visible';
			$('zoomimglayer').style.width = $('zoomimglayer').style.height = 'auto';
			if(is_ie){
				$('zoomimglayer').onmousewheel = zoomimgadjust;
			} else {
				$('zoomimglayer').addEventListener("DOMMouseScroll", zoomimgadjust, false);
			}
		}
	}
}

function zoomimgresize(obj,pid,iw,ih,iu) {
	zoomobj['zimginfo'] = [obj.width, obj.height];
	var r = obj.width / obj.height;
	var w = document.body.clientWidth * 0.90;
	w = obj.width > w ? w : obj.width;
	var h = w / r;
	var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
	if(h > clientHeight) {
	//h = clientHeight
		h = clientHeight;
		w = h * r;
	}
	var l = (document.body.clientWidth - w) / 2;
	var t = h < clientHeight ? (clientHeight - h) / 2 : 0;
	t += + scrollTop;
	zoomobj['x'] = (l - zoomobj['srcinfo']['left']) / 5;
	zoomobj['y'] = (t - zoomobj['srcinfo']['top']) / 5;
	zoomobj['w'] = (w - zoomobj['srcobj'].width) / 5;
	zoomobj['h'] = (h - zoomobj['srcobj'].height) / 5;
	$('zoomimglayer').style.filter = '';
	$('zoomimglayer').innerHTML = '';
	setTimeout('zoomST(1,'+pid+','+iw+','+ih+',\''+iu+'\')', 5);
}

function zoomimgadjust(e, a) {
	if(!a) {
		if(!e) e = window.event;
		if(e.altKey || e.shiftKey || e.ctrlKey) return;
		var l = parseInt($('zoomimglayer').style.left);
		var t = parseInt($('zoomimglayer').style.top);
		if(e.wheelDelta <= 0 || e.detail > 0) {
			if($('zoomimg').width <= 400 || $('zoomimg').height <= 400) {
				doane(e);return;
			}
			$('zoomimg').width -= zoomobj['zimginfo'][0] / 10;
			$('zoomimg').height -= zoomobj['zimginfo'][1] / 10;
			l += zoomobj['zimginfo'][0] / 20;
			t += zoomobj['zimginfo'][1] / 20;
		} else {
			if($('zoomimg').width >= zoomobj['zimginfo'][0]) {
				zoomimgadjust(e, 1);return;
			}
			$('zoomimg').width += zoomobj['zimginfo'][0] / 10;
			$('zoomimg').height += zoomobj['zimginfo'][1] / 10;
			l -= zoomobj['zimginfo'][0] / 20;
			t -= zoomobj['zimginfo'][1] / 20;
		}
	} else {
		var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
		$('zoomimg').width = zoomobj['zimginfo'][0];$('zoomimg').height = zoomobj['zimginfo'][1];
		var l = (document.body.clientWidth - $('zoomimg').clientWidth) / 2;l = l > 0 ? l : 0;
		var t = (clientHeight - $('zoomimg').clientHeight) / 2 + scrollTop;t = t > 0 ? t : 0;
	}
	$('zoomimglayer').style.left = l + 'px';
	$('zoomimglayer').style.top = t + 'px';
	$('zoomimglayer_bg').style.height = t + $('zoomimglayer').clientHeight > $('zoomimglayer_bg').clientHeight ? (t + $('zoomimglayer').clientHeight) + 'px' : $('zoomimglayer_bg').style.height;
	doane(e);
}

function zoomclose() {
	
	$('zoomimglayer').innerHTML = '';
	$('zoomimglayer').style.display = 'none';
	ff=document.getElementById("zoomimglayer_bg")
	$('zoomimglayer_bg').style.display = 'none';
}

function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){ zoomclose(); }
}
function listenKey () {	document.onkeypress = getKey; }
listenKey();

function showit(){
clearclosewin( ); 
if(document.getElementById("xx")){
document.getElementById("xx").style.display="block"
}
}
function clearclosewin( ){if (typeof dodo!="undefined")clearTimeout(dodo); }
function hiddenit (){closewinwait( ); }
function closewinwait( ){dodo=setTimeout("closewin()",0764);}
function closewin( ){if(document.getElementById("xx")){document.getElementById("xx").style.display='none';}}

function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 5;
			fotofade=setTimeout("fadeIn('"+objId+"',"+opacity+")", 5);
		}
	}
}
var opa=0
function FadeIn(objId,opacity) {

	if (document.getElementById) {
		obj = document.getElementById(objId);
		
		if (opa !=opacity) {
			setOpacity(obj, opa);
			opa += 20;
			setTimeout("FadeIn('"+objId+"',"+opacity+")", 5);
		}
	}
}

function FadeOut(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity !=0) {
			setOpacity(obj, opacity);
			opacity= opacity-20;
			FO=setTimeout("FadeOut('"+objId+"',"+opacity+")", 5);
		}
		else{
			opa=0
			obj.style.display="none"
			clearTimeout(FO)
			}
	}
}
function setOpacity(obj, opacity) {

	opacity = (opacity == 100)?99.999:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
}

function getPage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.open('GET', url, true)
page_request.send(null)
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
}
function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function moveBF(pid){
	fid=document.getElementById(pid)
	cc=fid.height-200
	if(fid.offsetTop+cc>0){
	fid.style.marginTop=(fid.offsetTop-5)+"px"
	MF=setTimeout("moveBF('"+pid+"')",10)
}
}
function MoveBF(pid){
	fid=document.getElementById(pid)
	if(fid.offsetTop<-10){
		fid.style.marginTop=(fid.offsetTop+5)+"px"
		if (typeof MF!="undefined")clearTimeout(MF);
		mf=setTimeout("MoveBF('"+pid+"')",10)
		}
	}

function FotoSlide(){
	var ps=document.getElementById("content").getElementsByTagName("IMG")
	//alert(ps[0].id)
	for(s=0;s<ps.length;s++){
	if(ps[s].style.borderBottom=="5px solid #E60046"){
		zoom(ps[s].id,ps[s].title.split("X")[0],ps[s].title.split("X")[1],ps[s].src.replace(/m_/g,""),ps[s].id.replace("p",""),ps[s].parentNode.href);
		}
	else{
		zoom(ps[1].id,ps[1].title.split("X")[0],ps[1].title.split("X")[1],ps[1].src.replace(/m_/g,""),ps[1].id.replace("p",""),ps[1].parentNode.href);
		}
	}
}

var ww=window.screen.width;var wh=window.screen.height;
function checksc(){
	if(confirm("Your desktop screen : "+ww+"X"+wh+"\n, are you view the size wallpapers?")){
		
		top.location.href="/pages/"+ww+"X"+wh+"-size-1"
		
		}
	}
function checkscreen(){
	document.write("<a href='javascript:checksc()'>> Check Desktop Screen</a>")
	}