// XRay script for use with IE
// Copyright (C) Blumentals Software 2008
// Some portions adapted from: http://www.hunlock.com/blogs/Javascript_Drag_and_Drop
// Some portions adapted from Quirksmode http://quirksmode.org
// Some portions adapted from http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
// Some portions Copyright Ben Nadel @ KinkySolutions.com 2006
// Some portions contributed by various other developers
// Packed with: http://dean.edwards.name/packer/

var savedTarget=null;var orgCursor=null;var dragOK=false;var dragXoffset=0;var dragYoffset=0;
function moveHandler(e){if(e==null){e=window.event}if(e.button<=1&&dragOK){savedTarget.style.left=e.clientX-dragXoffset+'px';savedTarget.style.top=e.clientY-dragYoffset+'px';return false}}
function cleanup(e){document.onmousemove=null;document.onmouseup=onNeedXRay;savedTarget.style.cursor="move";dragOK=false;didDrag=true}
function dragHandler(e){if(e==null){e=window.event}var a=e.target!=null?e.target:e.srcElement;orgCursor=a.style.cursor;if(isInspector(a)){a=document.getElementById("XRInspector");savedTarget=a;a.style.cursor="move";dragOK=true;dragXoffset=e.clientX-a.offsetLeft;dragYoffset=e.clientY-a.offsetTop;document.onmousemove=moveHandler;document.onmouseup=cleanup;return false}else{hideAll()}}
function getOffsetCoords(a){if(a.currentStyle)if(a.currentStyle.position=='relative')a.style.zoom='100%';var b=0;var c=0;if(a.offsetParent){b=a.offsetLeft;c=a.offsetTop;while(a=a.offsetParent){if(a.currentStyle)if(a.currentStyle.position=='relative')a.style.zoom='100%';b+=a.offsetLeft;c+=a.offsetTop}}return[b,c]}
function getCssProperty(a,b){if(!document.defaultView){b=cssToName(b)}if(a.currentStyle){var y=a.currentStyle[b]}else if(window.getComputedStyle){var y=document.defaultView.getComputedStyle(a,null).getPropertyValue(b)}else{var c=document.defaultView.getComputedStyle(a,null);y=c.getPropertyValue(b)}return y}
function cssToName(a){if(a.indexOf('-')!=0){var b=new Array();b=a.split('-')}var c=b[0];for(var i=1;i<b.length;i++){var d=b[i].substring(0,1).toUpperCase();c=c+d+b[i].substring(1,b[i].length)}if(c=="float")c='styleFloat';return c}
function toIntVal(a){if(a=='medium')return 4;if(a=='thin')return 2;if(a=='thick')return 6;var b=a.substr(0,a.length-2).valueOf();if(isNaN(b)){return 0}else{return parseInt(b)}}
function getClientSize(){var a=0;var b=0;if(typeof(window.innerWidth)=='number'){a=window.innerWidth;b=window.innerHeight}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){a=document.documentElement.clientWidth;b=document.documentElement.clientHeight}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){a=document.body.clientWidth;b=document.body.clientHeight}return[b,a]}
function getClientWidth(){ss=getClientSize();ww=ss[1];return ww}
function getClientHeight(){if(document.body.scrollHeight)return document.body.scrollHeight;else return document.documentElement.offsetHeight}
function makeOrGetElem(a){var b=document.getElementById(a);if(!b){var b=document.createElement('div');document.body.appendChild(b);b.id=a;b.onmousedown=hideAll}return b}
function findNextSibling(a){if(a){for(a=a.nextSibling;(a&&a.nodeType==3);a=a.nextSibling){}}if(!a)return(a);if(a.nodeName=="SCRIPT")return;if(a.id=="XRBaseDiv")return;return(a)}
function findPreviousSibling(a){for(a=a.previousSibling;(a&&a.nodeType==3);a=a.previousSibling){}return(a)}
function findFirstChild(a){var b=a.childNodes;if(!b)return a;if(a.nodeName=='HTML')return document.body;for(var i=0;i<b.length;i++){var c=b[i];if(c.nodeName!=="#text")break}if(!c)return a;if(c.nodeName=="SCRIPT")return a;if(c.nodeName=="#text")return a;return c}
function isInspector(a){if(a.id=="XRInspector")return true;if(a.parentNode){while(a=a.parentNode){if(a.id=="XRInspector")return true}}}
function hideAll(){hideOverlays();hideHints();hideInspector()}
function makeOverlays(){var a=document.createElement('div');document.body.appendChild(a);a.id='XRBaseDiv';a.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRTopDiv';b.onmousedown=hideAll;b.innerHTML="<!-- empty -->";var b=document.createElement('div');a.appendChild(b);b.id='XRLeftDiv';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRBottomDiv';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRRightDiv';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRTopMargin';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRLeftMargin';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRBottomMargin';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRRightMargin';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRTopPadding';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRLeftPadding';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRBottomPadding';b.onmousedown=hideAll;var b=document.createElement('div');a.appendChild(b);b.id='XRRightPadding';b.onmousedown=hideAll}
function hideOverlays(){var a=null;a=document.getElementById("XRBaseDiv");a.style.visibility='hidden';a=document.getElementById("XRTopDiv");a.style.visibility='hidden';a=document.getElementById("XRLeftDiv");a.style.visibility='hidden';a=document.getElementById("XRBottomDiv");a.style.visibility='hidden';a=document.getElementById("XRRightDiv");a.style.visibility='hidden';a=document.getElementById("XRTopMargin");a.style.visibility='hidden';a=document.getElementById("XRLeftMargin");a.style.visibility='hidden';a=document.getElementById("XRBottomMargin");a.style.visibility='hidden';a=document.getElementById("XRRightMargin");a.style.visibility='hidden';a=document.getElementById("XRTopPadding");a.style.visibility='hidden';a=document.getElementById("XRLeftPadding");a.style.visibility='hidden';a=document.getElementById("XRBottomPadding");a.style.visibility='hidden';a=document.getElementById("XRRightPadding");a.style.visibility='hidden'}
function setHintStyle(a){a.style.position='absolute';a.style.border='1px solid #FFFFFF';a.style.backgroundColor='#3399FF';a.style.color='#FFFFFF';a.style.fontFamily='Tahoma';a.style.fontSize='9pt';a.style.padding='2px'}
function makeHints(){var a=document.createElement('div');document.body.appendChild(a);a.id='XRWidthBox';setHintStyle(a);a.onmousedown=hideAll;var a=document.createElement('div');document.body.appendChild(a);a.id='XRHeightBox';setHintStyle(a);a.onmousedown=hideAll;var a=document.createElement('div');document.body.appendChild(a);a.id='XRPosBox';setHintStyle(a);a.onmousedown=hideAll}
function hideHints(){var a=null;a=document.getElementById("XRWidthBox");a.style.visibility='hidden';a=document.getElementById("XRHeightBox");a.style.visibility='hidden';a=document.getElementById("XRPosBox");a.style.visibility='hidden'}
function makeInspector(){var a=document.createElement('div');document.body.appendChild(a);a.id='XRInspector';a.style.position="absolute";a.style.fontFamily="Tahoma";a.style.fontSize="8pt";a.style.color="#333333";a.style.display="inline";a.style.textAlign="left";a.style.border="solid 1px #CCCCCC";a.style.backgroundColor="#E8F3FF";a.style.left=10;a.style.top=10;a.style.width=180;a.style.visibility="hidden";a.style.cursor="move";a.style.zindex="1111";a.onmousedown=hideAll}
function hideInspector(){var a=document.getElementById("XRInspector");a.style.visibility='hidden'}
function showInspector(a){var b=document.getElementById("XRInspector");b.style.visibility='visible';var c='<div style="padding: 5px; color: white; background-color: #3399FF"><b>XRay Inspector</b> [drag & drop]</div>';c=c+'<div style="padding: 5px"><b>element:</b> '+a.tagName+'<br>';if(a.className!='')c=c+'<b>class:</b> '+a.className+'<br>';if(a.id!='')c=c+'<b>id:</b> '+a.id+'<br>';c=c+'<b>width:</b> '+getCssProperty(a,'width')+' ('+a.offsetWidth+'px)<br>';c=c+'<b>height:</b> '+getCssProperty(a,'height')+' ('+a.offsetHeight+'px)<br>';c=c+'<b>position:</b> '+getCssProperty(a,'position')+'<br>';c=c+'<b>float:</b> '+getCssProperty(a,'float')+'<br>';c=c+'<hr style="color: #CCCCCC; height: 1px">';c=c+'<div style="width: 160px;">';c=c+'<div style="text-align: center; width: 80px; float: left">';c=c+'<b>margin</b><br>';c=c+'top: '+getCssProperty(a,'margin-top')+'<br>';c=c+'right: '+getCssProperty(a,'margin-right')+'<br>';c=c+'bottom: '+getCssProperty(a,'margin-bottom')+'<br>';c=c+'left: '+getCssProperty(a,'margin-left')+'<br>';c=c+'</div>';c=c+'<div style="text-align: center; width: 80px; float: left">';c=c+'<b>padding</b><br>';c=c+'top: '+getCssProperty(a,'padding-top')+'<br>';c=c+'right: '+getCssProperty(a,'padding-right')+'<br>';c=c+'bottom: '+getCssProperty(a,'padding-bottom')+'<br>';c=c+'left: '+getCssProperty(a,'padding-left')+'<br>';c=c+'</div>';c=c+'</div>';if(a.style.cssText!=''){c=c+'<hr style="color: #CCCCCC; height: 1px">';c=c+'<b>style code:</b><br>'+a.style.cssText.toLowerCase()+'<br>'}b.innerHTML=c+'</div>'}
function showWHint(a){var b=document.getElementById("XRWidthBox");b.style.visibility='visible';var c=getOffsetCoords(a);var d=a.offsetWidth;var e=c[0]+(d/2)-(b.offsetWidth/2);var f=a.offsetHeight+c[1]+10;if(e<0)e=50;if(e>window.innerWidth)e=window.innerWidth-b.offsetWidth-10;if(f<0)f=10;b.style.left=e+'px';b.style.top=f+'px';b.innerHTML=getCssProperty(a,'width')}
function showHHint(a){var b=document.getElementById("XRHeightBox");b.style.visibility='visible';var c=getOffsetCoords(a);var d=a.offsetHeight;var e=c[0]-(b.offsetWidth)-10;var f=c[1]+(d/2)-(b.offsetHeight/2);if(e<0)e=10;if(e>window.innerWidth)e=window.innerWidth-b.offsetWidth-10;if(f<0)f=10;b.style.left=e+'px';b.style.top=f+'px';b.innerHTML=getCssProperty(a,'height')}
function showPosHint(a){var b=document.getElementById("XRPosBox");b.style.visibility='visible';var c=getOffsetCoords(a);var d=c[0]-(b.offsetWidth/2);var e=c[1]-(b.offsetHeight)-10;if(d<0)d=50;if(d>window.innerWidth)d=window.innerWidth-b.offsetWidth-10;if(e<0)e=10;b.style.left=d+'px';b.style.top=e+'px';b.innerHTML=c[1]+"px"+", "+c[0]+"px"}
function setMainOverlay(a,b,c,d){var e=makeOrGetElem('XRBaseDiv');e.style.visibility='visible';e.style.left='0px';e.style.top='0px';if(a<0)a=0;if(d<0)d=0;if(a>0){var f=makeOrGetElem('XRTopDiv');f.style.position='absolute';f.style.left='0px';f.style.top='0px';f.style.width=getClientWidth();f.style.height=a+"px";f.style.visibility='visible';f.style.backgroundColor='#000000';f.style.fontSize=0;f.style.lineHeight=0;f.style.filter='alpha(opacity=50)'}if(getClientHeight()-(a+d)>0){var g=getClientHeight()-(a+d)}else{g=0}if(g>0){var h=makeOrGetElem('XRBottomDiv');h.style.position='absolute';h.style.left='0px';h.style.height=g+'px';h.style.top=d+a+"px";h.style.width=getClientWidth();h.style.visibility='visible';h.style.backgroundColor='#000000';h.style.fontSize=0;h.style.lineHeight=0;h.style.filter='alpha(opacity=50)'}if((d>0)&&(b>0)){var i=makeOrGetElem('XRLeftDiv');i.style.position='absolute';i.style.left='0px';i.style.top=a+"px";i.style.width=b+"px";i.style.height=d+'px';i.style.visibility='visible';i.style.backgroundColor='#000000';i.style.fontSize=0;i.style.lineHeight=0;i.style.filter='alpha(opacity=50)';var j=makeOrGetElem('XRRightDiv');j.style.position='absolute';j.style.left=b+c+'px';j.style.top=a+"px";if((getClientWidth()-c)>0){var k=getClientWidth()-c+'px'}else{k=0}j.style.width=k;j.style.height=d+'px';j.style.visibility='visible';j.style.backgroundColor='#000000';j.style.fontSize=0;j.style.lineHeight=0;j.style.filter='alpha(opacity=50)'}}
function setOverlay(a,b,c,d,e,f){if((d<1)||(e<1))return;if(b<0)b=0;var g=makeOrGetElem(a);g.style.position='absolute';g.style.visibility='visible';g.style.left=c+'px';g.style.top=b+'px';g.style.width=e+'px';g.style.height=d+"px";g.style.backgroundColor=f;g.style.fontSize=0;g.style.lineHeight=0;g.style.filter='alpha(opacity=50)'}
function doXRay(a){if(!a)return;xrayedElement=a;hideAll();var b=getOffsetCoords(a);var c=parseInt(b[1]);var d=parseInt(b[0]);var e=a.offsetWidth.valueOf();var f=a.offsetHeight.valueOf();var g=toIntVal(getCssProperty(a,'margin-top'));var h=toIntVal(getCssProperty(a,'margin-bottom'));var i=toIntVal(getCssProperty(a,'margin-left'));var j=toIntVal(getCssProperty(a,'margin-right'));var k=toIntVal(getCssProperty(a,'padding-top'));var l=toIntVal(getCssProperty(a,'padding-bottom'));var m=toIntVal(getCssProperty(a,'padding-left'));var n=toIntVal(getCssProperty(a,'padding-right'));var o=e+i+j;var p=f+g+h;setMainOverlay(c-g,d-i,o,p);setOverlay('XRTopMargin',c-g,d-i,g,o,'#0066FF');setOverlay('XRLeftMargin',c,d-i,f,i,'#0066FF');setOverlay('XRBottomMargin',c+f,d-i,h,o,'#0066FF');setOverlay('XRRightMargin',c,d+e,f,j,'#0066FF');setOverlay('XRTopPadding',c,d,k,e,'#FF6600');setOverlay('XRLeftPadding',c+k,d,f-k-l,m,'#FF6600');setOverlay('XRBottomPadding',c+f-l,d,l,e,'#FF6600');setOverlay('XRRightPadding',c+k,d+e-n,f-k-l,n,'#FF6600');showInspector(a);showWHint(a);showHHint(a);showPosHint(a)}
function onNeedXRay(e){if(!e)var e=window.event;var a=null;if(e.target)a=e.target;else if(e.srcElement)a=e.srcElement;while(a.nodeName=='#text')a=a.parentNode;if(isInspector(a))return false;doXRay(a);return false}
function onKeyPress(e){var a;if(window.event)a=window.event.keyCode;else if(e)a=e.which;switch(a){case 37:if(findPreviousSibling(xrayedElement))doXRay(findPreviousSibling(xrayedElement));return false;break;case 39:if(findNextSibling(xrayedElement))doXRay(findNextSibling(xrayedElement));return false;break;case 38:if(xrayedElement.parentNode){while(xrayedElement.parentNode.nodeName=='#text')xrayedElement=xrayedElement.parentNode;if(!(xrayedElement.nodeName=='HTML'))doXRay(xrayedElement.parentNode);return false}break;case 40:if(findFirstChild(xrayedElement))doXRay(findFirstChild(xrayedElement));return false;break;default:return true}}
function enableXRay(){makeOverlays();makeHints();makeInspector();document.onclick=onNeedXRay;document.onmouseup=onNeedXRay;document.onkeydown=onKeyPress;document.onmousedown=dragHandler;var a=document.getElementById("XRInspector");a.onmousedown=dragHandler;window.onresize=hideAll;return true}
var xrayedElement;
enableXRay();