// Web Design Scale
//
// file created in 2009/12/18 11:00:23.
// LastUpdated :2009/12/18 16:10:14.
// author iNo
//

(function () {

/* DragResize.js {{{ */
var DragResize=(function(){var O=window,W=document,P="addEventListener",N="offset",K="client",H="scroll",B="min",M="Left",X="Top",I="Width",S="Height",a="drag",E="resize",C="Handle",L="style",Y="ignoreTags",T=null;var R=W.body,D=W.documentElement;var Q=function(c,b){return function(){return c.apply(b,arguments)}},Z=function(c,e,b,d){var f=Q(b,d);c[P]?c[P](e,f,false):c.attachEvent("on"+e,f);return{$0:c,$1:e,$2:f}},G=function(b){b.$0[P]?b.$0.removeEventListener(b.$1,b.$2,false):b.$0.detachEvent("on"+b.$1,b.$2)},A=function(b){b.stopPropagation&&b.stopPropagation();b.preventDefault&&b.preventDefault();b.cancelBubble=true;b.returnValue=false},V=function(b){return typeof b==="string"?W.getElementById(b):b},F=(typeof O.pageXOffset==="number"?function(){return{x:O.pageXOffset,y:O.pageYOffset}}:(D&&D[K+I]?function(){return{x:D[H+M],y:D[H+X]}}:function(){return{x:R[H+M],y:R[H+X]}})),U=(O.innerWidth?function(){return{x:O.innerWidth,y:O.innerHeight}}:(D&&D[K+I]?function(){return{x:D[K+I],y:D[K+S]}}:function(){return{x:R[N+I],y:R[K+S]}})),J=function(c,e){e=e||{};var d=this;e[E+C]=V(e[E+C]);d.$3=(c=V(c));d.$4=e[B+I];d.$5=e[B+S];d[H]=e[H];d.$6=e.onclick;d.$7=e.scope;d.$8={};d.$9=[];if((e[a+C]=V(e[a+C]))||e[E+C]!=c){d.$a=e[a+C]||c;d.$9.push(Z(d.$a,"mousedown",d.$b,d));d.$9.push(Z(d.$a,"click",d.$c,d))}if(d.$a!=c||(e[E+C]&&e[E+C]!=d.$a)){d.$d=e[E+C]||c;d.$9.push(Z(d.$d,"mousedown",d.$e,d));d.$9.push(Z(d.$d,"click",d.$c,d))}var b=e[Y];if(typeof b==="string"){b=[b]}if(b){for(var f=0;f<b.length;++f){d.$8[b[f].toUpperCase()]=true}} };J[B+I]=100;J[B+S]=100;J.$f=T;J.$g=!!O.ActiveXObject;J.$h=function(b){var c=J.$f;if(c){if(J.$g&&!(document.documentMode&&document.documentMode>=8)&&!(b.button&1)){J.$i();return}c.$j=b.clientX;c.$k=b.clientY;J.$g&&A(b)}};J.$l=function(d){var e=J.$f,b=F();var c=e.$m;if(e&&typeof c.$6==="function"&&e.$n+e.$o==d.clientX+b.x&&e.$p+e.$q==d.clientY+b.y){c.$6.call(c.$7,d)}J.$i()};J.$i=function(){var b=J.$f;b&&b.$r&&clearInterval(b.$r);J.$f=T};J.prototype={$b:function(d){var c=this;if(c.$s(d)){return}A(d);var e=J.$f=c.$t(d,c.$u),b=c.$3;e.$v=b[N+M];e.$w=b[N+X];e.$x=0;e.$y=0;e.$z=D[H+I]-b[N+I];e.$A=D[H+S]-b[N+S]},$u:function(){this.$B(function(d,c,i,g,j){c[L].left=i+"px";c[L].top=g+"px";if(this[H]){var e=U(),k=i+c[N+I],b=g+c[N+S],h=j.x,f=j.y;i<h?(h=i):(k>(h+e.x)&&(h=k-e.x));g<f?(f=g):(b>(f+e.y)&&(f=b-e.y));(h!=j.x||f!=j.y)&&O[H](h,f)}})},$e:function(e){var c=this;if(c.$s(e)){return}A(e);var g=J.$f=c.$t(e,c.$C),b=c.$3,d=(typeof c.$4==="number"?c.$4:J[B+I]),f=(typeof c.$5==="number"?c.$5:J[B+S]);g.$v=b[N+M]+b[N+I];g.$w=b[N+X]+b[N+S];g.$D=b[N+I]-b[K+I];g.$E=b[N+S]-b[K+S];g.$x=b[N+M]+g.$D+d;g.$y=b[N+X]+g.$E+f;g.$z=D[H+I];g.$A=b[L].position!="absolute"?65536:D[H+S]},$C:function(){this.$B(function(c,b,j,g,k){b[L].width=(j-b[N+M]-c.$D)+"px";b[L].height=(g-b[N+X]-c.$E)+"px";if(this[H]){var e=U(),d=b[N+M],h=b[N+X],i=k.x,f=k.y;d<i&&(i=d);j>(i+e.x)&&(i=j-e.x);h<f&&(f=h);g>(f+e.y)&&(f=g-e.y);(i!=k.x||f!=k.y)&&O[H](i,f)}})},$c:function(b){if(!this.$s(b)){A(b)}},$s:function(c){var b=c.target||c.srcElement;while(b){if(b.nodeType==1&&this.$8[b.tagName.toUpperCase()]){return b}b=b.parentNode}return null},$t:function(f,h){A(f);J.$i();var c=this.$3,b=F(),e=f.clientX,d=f.clientY,i=b.x,g=b.y;return{$m:this,$r:setInterval(Q(h,this),30),$n:e,$p:d,$j:e,$k:d,$F:e,$G:d,$o:i,$q:g,$H:i,$I:g,$J:i,$K:g}},$B:function(e){var f=J.$f,c=F();if(f.$j!=f.$F||f.$k!=f.$G||f.$H!=c.x||f.$I!=c.y){var d=this.$3,b=Math.min(Math.max(f.$v+f.$j-f.$n+c.x-f.$o,f.$x),f.$z),g=Math.min(Math.max(f.$w+f.$k-f.$p+c.y-f.$q,f.$y),f.$A);e.call(this,f,d,b,g,c);f.$F=f.$j;f.$G=f.$k;f.$H=c.x;f.$I=c.y}},detach:function(){var b=this;J.$f&&J.$f.$m==b&&J.$i();while(b.$9.length>0){G(b.$9.pop())}b.$3=b.$a=b.$d=T}};Z(W,"mouseup",J.$l,J);Z(W,"mousemove",J.$h,J);return J})();
/* }}}*/

    var ID = 'SCALE-SCRIPT-' + (new Date()).getTime().toString();
    var OPACITY = 0.5;
    var Z_INDEX = 2147483647;
    var MAX_OPACITY = 0.8;
    var MIN_OPACITY = 0.2;
    var INTERVAL_OPACITY = 0.1;

    var body = document.body;
    var scale = document.createElement('DIV');
    var label = document.createElement('DIV');
    var handle = document.createElement('DIV');
    var x = 0;
    var y = window.scrollY;
    var bgColor = ['black', 'white'];
    var fgColor = ['white', 'black'];
    var cIndex = 0;

    scale.id = ID;
    scale.style.position = 'absolute';
    scale.style.top = y + 'px';
    scale.style.left = x + 'px';
    scale.style.zIndex = Z_INDEX;
    scale.style.width = '500px';
    scale.style.height = '100px';
    scale.style.overflow = 'hidden';
    scale.style.color = fgColor[cIndex];
    scale.style.backgroundColor = bgColor[cIndex];
    scale.style.opacity = OPACITY;
    scale.style.cursor = 'move';
    var displayCallback = function() {
        return function() {
            var pos = 'left:' + scale.style.left + ', top:' + scale.style.top;
            var size = 'width:' + scale.style.width + ', height:' + scale.style.height;
            scale.title = pos + ', ' + size;
            label.innerHTML = pos + '<br />' + size;
        };
    };
    scale.addEventListener('mouseup', displayCallback(), false);
    var setStyleCallback = function() {
        return function() {
            var o = scale.style.opacity;
            var c = scale.style.backgroundColor;
            scale.style.opacity = o > MIN_OPACITY ? o - INTERVAL_OPACITY : MAX_OPACITY;
            if (o <= MIN_OPACITY) {
                cIndex = cIndex == 0 ? 1 : 0;
                scale.style.color = fgColor[cIndex];
                scale.style.backgroundColor = bgColor[cIndex];
                label.style.color = fgColor[cIndex];
                handle.style.backgroundColor = fgColor[cIndex];
            }
        };
    };
    scale.addEventListener('dblclick', setStyleCallback(), false);

    label.style.position = 'absolute';
    label.style.top = '2px';
    label.style.left = '2px';
    label.style.overflow = 'hidden';
    label.style.color = fgColor[cIndex];
    label.style.fontFamily = 'monospace';
    label.style.width = '100%';
    label.style.textAlign = 'center';

    handle.style.position = 'absolute';
    handle.style.width = '15px';
    handle.style.height = '15px';
    handle.style.bottom = '2px';
    handle.style.right = '2px';
    handle.style.backgroundColor = fgColor[cIndex];
    handle.style.cursor = 'nw-resize';

    new DragResize(scale, {
        resizeHandle : handle,
        minWidth : 19,
        minHeight : 19
    });

    scale.appendChild(label);
    scale.appendChild(handle);
    body.appendChild(scale);

})();

/*
vim:fdl=0 fdm=marker:ts=4 sw=4 sts=0:
*/

