var content=document.getElementById('getwallcontentInner');var loadingdiv=document.getElementById('getloadingdiv');var loadingdivtitle=document.getElementById('getloadingdivtitle');var wallloc="";var wallpaperid=0;var resx,resy=0;var origx,origy=0;var advdownloadpopup=false;var boxwidth=0,boxheight=0;var x1,x2,y1,y2=0;var middiv,x1d,x2d,y1d,y2d;var x1s,x2s,y1s,y2s;var dottl,dottr,dotbl,dotbr;var thumbheight,thumbwidth=0;var boxar=1;var shrinkratio=1;var md=false;var md_active="";var lastmousex,lastmousey,mousex,mousey=0;var imgWall=new Image();var isDownloading=false;var downloadIter=0;var ns4=document.layers;var op5=(navigator.userAgent.indexOf("Opera 5")!=-1)||(navigator.userAgent.indexOf("Opera/5")!=-1);var op6=(navigator.userAgent.indexOf("Opera 6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1);var agt=navigator.userAgent.toLowerCase();var mac=(agt.indexOf("mac")!=-1);var ie=(agt.indexOf("msie")!=-1);var mac_ie=mac&&ie;function checkWallpaper(id){var ar=screen.width/screen.height;var sres=screen.width+"x"+screen.height;var det="";wallpaperid=id;if(ar==4/3||ar==1.25)
det="Standard";else if(ar==1.6)
det="Widescreen";else if(sres=="320x480")
det="iPhone";else if(sres=="480x272")
det="PSP";else if(sres=="1280x720")
det="720p";else if(sres=="1920x1080")
det="1080p";else
det="Unknown";document.getElementById('detres').innerHTML=screen.width+"x"+screen.height;document.getElementById('detar').innerHTML=det;if(overrideX&&overrideY){changeRes(overrideX+"x"+overrideY);return;}
changeRes(screen.width+"x"+screen.height);return;}
function loadWallpaper(){if(!resx)resx=screen.width;if(!resy)resy=screen.height;content.innerHTML="";loadingdivtitle.innerHTML="Retrieving image optimized for your computer...";loadingdiv.style.display="block";wallloc="http://www.desktopnexus.com/dl/inline/"+wallpaperid+"/"+resx+"x"+resy+"/"+wallpaperfilename+"?nocache="+Math.floor(Math.random()*999999);beginWallDownload(wallloc);return;}
function changeRes(newres){if(!newres)return;if(newres=="dloriginal"){window.location="http://www.desktopnexus.com/dl/"+wallpaperid+"/"+origx+"x"+origy+"/"+wallpaperfilename;return;}
if(newres=="iphone")newres="320x480";if(newres=="psp")newres="480x272";if(newres=="1080p")newres="1920x1080";if(newres=="720p")newres="1280x720";newres=newres.split('x');if(newres.length!=2)return;resx=newres[0];resy=newres[1];hideAdvDownloadPopup();document.getElementById('getloadingprogressbar').style.width="0px";content.innerHTML="";loadingdiv.style.display="block"
loadingdivtitle.innerHTML="Preparing wallpaper for retrieval...";ajaxPutGet('checkwallpaper',wallpaperid,resx+"x"+resy);return;}
function beginWallDownload(fn){isDownloading=true;downloadIter=0;wallImg=new Image();wallImg.border="0";if(resx==screen.width&&resy==screen.height)wallImg.style.width="100%";wallImg.src=fn;setTimeout("updateDownloadPB()",20);return;}
function updateDownloadPB(){if(isDownloading==false)return;if(wallImg.complete){document.getElementById('getloadingprogressbar').style.width="480px";loadingdiv.style.display="none";content.appendChild(wallImg);}else{downloadIter=downloadIter+1;document.getElementById('getloadingprogressbar').style.width=(480*(1-Math.pow(Math.E,-.02*downloadIter)))+"px";setTimeout("updateDownloadPB()",20);}}
function loadResize(){var str="";if(!resx)resx=screen.width;if(!resy)resy=screen.height;window.document.onmousemove=dlBodyMouseMove;window.document.onmouseup=dlBodyMouseUp;str+="<div class=\"ybox\"><div class=\"yboxInner\" style=\"font-size: 10pt; font-weight: normal\">";str+="<img src=\"http://cdn.desktopnexus.com/images/warning.gif\" border=\"0\" style=\"float: left; padding: 0 12px 6px 4px;\" /> ";str+="This wallpaper was originally a different shape (aspect ratio) than the download you've requested. It's okay though!  Desktop Nexus has developed a quick and easy tool for you to resize and crop the wallpaper to fit your screen. <a href=\"javascript:showCropInstructions();\" style=\"text-decoration: underline\">Click here</a> for further instructions.";str+="<div id=\"cropinstructionsdiv\"><div class=\"rbox\"><div class=\"rboxInner\">";str+="<h3>Aspect Ratio Conversion Tool Instructions</h3>";str+="In the conversion tool, you'll notice a box drawn in the middle of your wallpaper.  When the conversion process is done, anything inside this box will be the new wallpaper.  The shaded area outside this box will be cropped out and will not be part of the new wallpaper.  On each of the corners of the box, you'll notice small square dots.  Clicking on one of those squares and dragging your mouse will allow you to resize the box, however both sides will scale evenly, forcing it to maintain the new shape's ratio.  You can move the box itself by clicking your mouse inside it and dragging. When you're satisfied with the new wallpaper, click the 'Continue' button to perform the cropping and resizing, then automatically remaster the image and display it for you.";str+="<br /><div align=\"center\" style=\"padding: 12px 0;\"><img src=\"http://cdn.desktopnexus.com/images/accept.gif\" border=\"0\" align=\"top\" /> <a href=\"javascript: void(0);\" onclick=\"document.getElementById('cropinstructionsdiv').style.display='none';\" style=\"font-weight: bold\">Okay! Close this window.</a></div>";str+="</div></div></div>";str+="<div style=\"clear: both\"></div>";str+="</div></div>";str+="<div id=\"getcropdiv\">";str+="<div id=\"getcropheader\">Just one more step.&nbsp; Let's tweak this image to fit your screen!</div>";str+="<div id=\"getcropcontent\">";str+="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"700px\">";str+="<tr><td valign=\"top\" width=\"450px\">";str+="<div style=\"position: relative; width: 450px; border: 1px solid #000000;\">";str+="<img id=\"cropthumb\" src=\"http://static.desktopnexus.com/thumbnails/"+wallpaperid+"-bigthumbnail.jpg\" border=\"0\" />";str+="<div id=\"cropx1\" class=\"cropbox\">&nbsp;</div>";str+="<div id=\"cropx2\" class=\"cropbox\">&nbsp;</div>";str+="<div id=\"cropy1\" class=\"cropbox\">&nbsp;</div>";str+="<div id=\"cropy2\" class=\"cropbox\">&nbsp;</div>";str+="<div id=\"middlediv\"><div style=\"width: 100%; height: 100%;\"><span style=\"width: 100%; height: 100%; cursor: move;\"></span></div></div>";str+="<div id=\"cropdottl\" class=\"cropdot\">&nbsp;</div>";str+="<div id=\"cropdottr\" class=\"cropdot\">&nbsp;</div>";str+="<div id=\"cropdotbl\" class=\"cropdot\">&nbsp;</div>";str+="<div id=\"cropdotbr\" class=\"cropdot\">&nbsp;</div>";str+="</div>";str+="</td><td valign=\"top\" style=\"padding: 10px 0 0 40px\">";str+="<span id=\"x1status\" class=\"cropstatusbox\"></span>";str+="<span id=\"x2status\" class=\"cropstatusbox\"></span>";str+="<span id=\"y1status\" class=\"cropstatusbox\"></span>";str+="<span id=\"y2status\" class=\"cropstatusbox\"></span>";str+="<span id=\"ratiostatus\" class=\"cropstatusbox\"></span>";str+="<div style=\"padding: 8px 0 0 41px;\"><a id=\"docroplink\" href=\"javascript:doCrop();\"><img id=\"continuebutton\" src=\"http://cdn.desktopnexus.com/images/continue-onblue.gif\" border=\"0\" /></a></div>";str+="</td></tr>";str+="</table>";str+="</div>";str+="</div>";loadingdiv.style.display="none";content.innerHTML=str;thumbheight=getElementHeight('cropthumb');thumbwidth=getElementWidth('cropthumb');x1d=document.getElementById('cropx1');x2d=document.getElementById('cropx2');y1d=document.getElementById('cropy1');y2d=document.getElementById('cropy2');middiv=document.getElementById('middlediv');x1s=document.getElementById('x1status');x2s=document.getElementById('x2status');y1s=document.getElementById('y1status');y2s=document.getElementById('y2status');dottl=document.getElementById('cropdottl');dottr=document.getElementById('cropdottr');dotbl=document.getElementById('cropdotbl');dotbr=document.getElementById('cropdotbr');boxwidth=resx/origx*thumbwidth;boxheight=resy/origy*thumbheight;shrinkratio=1;if(boxwidth>thumbwidth){shrinkratio=thumbwidth/boxwidth;boxwidth*=shrinkratio;boxheight*=shrinkratio;}
if(boxheight>thumbheight){var shrinkr=thumbheight/boxheight;boxheight*=shrinkr;boxwidth*=shrinkr;}
boxheight=Math.round(boxheight);boxwidth=Math.round(boxwidth);boxar=boxwidth/boxheight;x1=Math.round((thumbwidth-boxwidth)/2);x2=x1+boxwidth;y1=Math.round((thumbheight-boxheight)/2);y2=y1+boxheight;middiv.style.border="1px solid #CC0000";middiv.style.position="absolute";middiv.style.display="block";middiv.style.cursor="move";middiv.onmousedown=middiv_down;dottl.style.cursor="nw-resize";dottr.style.cursor="ne-resize";dotbl.style.cursor="sw-resize";dotbr.style.cursor="se-resize";dottl.onmousedown=dot_down;dottr.onmousedown=dot_down;dotbl.onmousedown=dot_down;dotbr.onmousedown=dot_down;redrawCropBox();return;}
function redrawCropBox(){x1d.style.left="0px";x1d.style.top="0px";x1d.style.width=x1+"px";x1d.style.height=thumbheight;x2d.style.left=x2+"px";x2d.style.top="0px";x2d.style.width=(thumbwidth-x2)+"px";x2d.style.height=thumbheight;y1d.style.left=x1+"px";y1d.style.top="0px";y1d.style.width=(x2-x1)+"px";y1d.style.height=y1+"px";y2d.style.left=x1+"px";y2d.style.top=y2+"px";y2d.style.width=(x2-x1)+"px";y2d.style.height=(thumbheight-y2)+"px";middiv.style.left=x1+"px";middiv.style.top=y1+"px";middiv.style.width=(x2-x1)+"px";middiv.style.height=(y2-y1)+"px";dottl.style.left=x1+"px";dottl.style.top=y1+"px";dottr.style.left=(x2-7)+"px";dottr.style.top=y1+"px";dotbl.style.left=x1+"px";dotbl.style.top=(y2-7)+"px";dotbr.style.left=(x2-7)+"px";dotbr.style.top=(y2-7)+"px";x1s.innerHTML="X1: "+x1;x2s.innerHTML="X2: "+x2;y1s.innerHTML="Y1: "+y1;y2s.innerHTML="Y2: "+y2;document.getElementById('ratiostatus').innerHTML="Ratio: "+Math.round(((x2-x1)/(y2-y1))*100)/100;return;}
function middiv_down(e){if(!e)var e=window.event
getMouseXY(e);md=true;md_active="middiv";return;}
function dot_down(e){if(!e)var e=window.event
if(e.target)targ=e.target
else if(e.srcElement)targ=e.srcElement
if(targ.nodeType==3)
targ=targ.parentNode
getMouseXY(e);md=true;md_active=targ.id;return;}
function getMouseXY(e){var tempX,tempY=0;if(ie){tempX=event.clientX+document.body.scrollLeft
tempY=event.clientY+document.body.scrollTop}else{tempX=e.pageX
tempY=e.pageY}
if(tempX<0){tempX=0}
if(tempY<0){tempY=0}
mousex=tempX
mousey=tempY
return true}
function checkWallpaperRet(results){results=results.split("-");if(results.length!=3){loadError();return;}
origx=results[0];origy=results[1];if(results[2]=="good"){loadWallpaper();}else if(results[2]=="bad"){var previewimg=new Image();previewimg.src="http://static.desktopnexus.com/thumbnails/"+wallpaperid+"-bigthumbnail.jpg";setTimeout("loadResize();",1200);}else{loadError();}
return;}
function showCropInstructions(){document.getElementById('cropinstructionsdiv').style.display='block';return;}
function showInstructions(){var idiv=document.getElementById('dlinstructionsdiv');var ua=navigator.userAgent.toLowerCase();var str="";str+="<div class=\"bluebox\"><div class=\"blueboxInner\" style=\"padding: 8px\">";str+="<div style=\"position: relative\">";str+="<h3 style=\"color: #FFFFFF\"><img src=\"http://cdn.desktopnexus.com/images/lightbulb-onblue.gif\" border=\"0\" align=\"top\" /> How do I set this wallpaper as my desktop background?</h3>";str+="</div>";if(ua.indexOf('msie')!=-1){str+="<img src=\"http://cdn.desktopnexus.com/images/instructions-ie.gif\" style=\"float: left; border: 1px solid #000000; margin: 0 8px 8px 0;\" />";str+="<div style=\"position: relative\">";str+="Setting this image as your desktop wallpaper in Internet Explorer is easy.  Simply right-click on the below image and click the 'Set as Background' link from the menu that pops up.";str+="</div>";}else if(ua.indexOf('safari')!=-1){str+="<img src=\"http://cdn.desktopnexus.com/images/instructions-safari.gif\" style=\"float: left; border: 1px solid #000000; margin: 0 8px 8px 0;\" />";str+="Setting this image as your desktop wallpaper in Safari is a two step process.  First you need to save the image to you computer, then you need to tell your system to use that image as your new background.  To save the image to your computer, simply right-click on the below image and click the 'Save Image to the Desktop' link from the menu that pops up. ";str+="<img src=\"http://cdn.desktopnexus.com/images/instructions-safari2.gif\" style=\"float: right; border: 1px solid #000000; margin: 8px 0 8px 8px;\" /> ";str+="Now, go to your desktop and right-click on the background. In the menu that pops up, click the 'Change Desktop Background' link. In the window that pops up, navigate to your Desktop folder and simply click on the thumbnail of image you downloaded.";}else if(ua.indexOf('mozilla')!=-1){str+="<img src=\"http://cdn.desktopnexus.com/images/instructions-firefox.gif\" style=\"float: left; border: 1px solid #000000; margin: 0 8px 8px 0;\" />";str+="Setting this image as your desktop wallpaper in Mozilla / Firefox is easy.  Simply right-click on the below image and click the 'Set as Desktop Background...' link from the menu that pops up.";}else if(ua.indexOf('opera')!=-1){str+="<img src=\"http://cdn.desktopnexus.com/images/instructions-opera.gif\" style=\"float: left; border: 1px solid #000000; margin: 0 8px 8px 0;\" />";str+="Setting this image as your desktop wallpaper in Opera is easy.  Simply right-click on the below image and click the 'Use image on desktop' link from the menu that pops up.";}else{str+="<img src=\"http://cdn.desktopnexus.com/images/instructions-firefox.gif\" style=\"float: left; border: 1px solid #000000; margin: 0 8px 8px 0;\" />";str+="We couldn't detect your browser. Usually setting this image as your background involves right-clicking on it and choosing an option like 'Set as Wallpaper'.<br /><br />We'd appreciate you telling us about this.  Please use our <a href=\"http://www.desktopnexus.com/contact.php\">contact form</a> and tell us you were using the following browser when you saw this message: <strong>"+ua+"</strong><br /><br />Thanks!";}
str+="<br /><div align=\"center\" style=\"padding: 12px 0; position: relative;\"><img src=\"http://cdn.desktopnexus.com/images/blue-green-check.gif\" border=\"0\" align=\"top\" /> <a href=\"javascript: void(0);\" onclick=\"document.getElementById('dlinstructionsdiv').style.display='none';\" style=\"font-weight: bold; color: #FFFFFF;\">Okay! Close this window.</a></div>";str+="<div style=\"clear: both;\"></a>";str+="</div></div>";idiv.innerHTML=str;idiv.style.display='block';return;}
function loadError(){content.innerHTML="An unknown error has occured.";return;}
function showAdvDownloadPopup(){var pop=document.getElementById('advdownloadpopdiv');if(pop.innerHTML==""){pop.innerHTML="<div class=\"bluebox\"><div class=\"blueboxInner\"><strong>Loading...</strong></div></div>";getAjaxContent('advdownloadpopdiv','advdownloadpop');}
pop.style.display="block";advdownloadpopup=true;return;}
function hideAdvDownloadPopup(){document.getElementById('advdownloadpopdiv').style.display="none";advdownloadpopup=false;return;}
function resetCrop(){loadingdiv.style.display="none";content.innerHTML="<div style=\"padding: 20px; font-size: 13pt;\"><img src=\"http://cdn.desktopnexus.com/images/loading.gif\" border=\"0\" align=\"bottom\" /> Resetting aspect ratio conversion... </div>";hideAdvDownloadPopup();ajaxPutGet('resetcrop',wallpaperid,resx+"x"+resy);return;}
function resetCropRet(){changeRes(resx+"x"+resy);return;}
function getObjNN4(obj,name){var x=obj.layers;var foundLayer;for(var i=0;i<x.length;i++)
{if(x[i].id==name)
foundLayer=x[i];else if(x[i].layers.length)
var tmp=getObjNN4(x[i],name);if(tmp)foundLayer=tmp;}
return foundLayer;}
function getElementHeight(Elem){if(ns4){var elem=getObjNN4(document,Elem);return elem.clip.height;}else{if(document.getElementById){var elem=document.getElementById(Elem);}else if(document.all){var elem=document.all[Elem];}
if(op5){xPos=elem.style.pixelHeight;}else{xPos=elem.offsetHeight;}
return xPos;}}
function getElementWidth(Elem){if(ns4){var elem=getObjNN4(document,Elem);return elem.clip.width;}else{if(document.getElementById){var elem=document.getElementById(Elem);}else if(document.all){var elem=document.all[Elem];}
if(op5){xPos=elem.style.pixelWidth;}else{xPos=elem.offsetWidth;}
return xPos;}}
function validateCoords(){if(x2<=x1+80)x2=x1+80;if(y2<=y1+50)y2=y1+50;x2=x1+Math.round((y2-y1)*boxar);if(x1<0){x2+=0-x1;x1=0;}
if(x2>thumbwidth){x1-=x2-thumbwidth;if(x1<0)x1=0;x2=thumbwidth;}
if(y1<0){y2+=0-y1;y1=0;}
if(y2>thumbheight){y1-=y2-thumbheight;if(y1<0)y1=0;y2=thumbheight;}
y2=y1+Math.round((x2-x1)*(1/boxar));return;}
function doCrop(){if(x2-x1<150||y2-y1<150){alert("You have selected an area for cropping that is too small and doesn't show enough of the wallpaper.  Please enlarge the region and try again.");return;}
document.getElementById('continuebutton').src="http://cdn.desktopnexus.com/images/processing-onblue.gif";document.getElementById('docroplink').href="javascript:void(0);";document.getElementById('docroplink').blur();ajaxPutGet('docrop',wallpaperid,resx+"-"+resy+"-"+boxwidth+"-"+boxheight+"-"+x1+"-"+x2+"-"+y1+"-"+y2);return;}
function doCropRet(results){if(results!="done"){loadingdiv.style.display="none";content.innerHTML="<div style=\"padding: 20px; font-size: 14pt;\">Uh-oh! An unknown error has occured when cropping this image.<br /><br />Please <a href=\"http://www.desktopnexus.com/contact/\">contact us</a> and tell us wallpaper <u>ID "+wallpaperid+"</u> is having problems cropping to <u>"+resx+"x"+resy+"</u>.  We apologize for this inconvenience.</div>";return;}
changeRes(resx+"x"+resy);return;}
function dlBodyMouseClick(e){var el=(typeof event!=='undefined')?event.srcElement:e.target;while(el.tagName!="BODY"){if(el.id=="advdownloadpopdiv")return;if(el.id=="dlinstructionsdiv")return;if(el.id=="cropinstructionsdiv")return;el=el.parentNode;}
hideAdvDownloadPopup();document.getElementById('dlinstructionsdiv').style.display='none';if(document.getElementById('cropinstructionsdiv')!=null)
document.getElementById('cropinstructionsdiv').style.display='none';return;}
function dlBodyMouseUp(e){md=false;md_active="";return true;}
function dlBodyMouseMove(e){if(md){lastmousex=mousex;lastmousey=mousey;getMouseXY(e);var changex=mousex-lastmousex;var changey=mousey-lastmousey;if(changex>0&&(x2-x1)>thumbwidth)return;if(changey>0&&(y2-y1)>thumbheight)return;if(md_active=="middiv"){x1+=changex;x2+=changex;y1+=changey;y2+=changey;}else if(md_active=="cropdottl"){x1+=changex*boxar;y1+=changex;}else if(md_active=="cropdottr"){x2-=changex*boxar;y1-=changex;}else if(md_active=="cropdotbl"){x1+=changex*boxar;y2-=changex;}else if(md_active=="cropdotbr"){x2+=changex*boxar;y2+=changex;}
x1=Math.round(x1);x2=Math.round(x2);y1=Math.round(y1);y2=Math.round(y2);validateCoords();redrawCropBox();}
return;}
window.document.onclick=dlBodyMouseClick;
