//goatslacker's JS Turbocharged Framework

var IE = document.all?true:false; var errorDivTimeOut; var timeZone; var vServer = "http://" + location.hostname + "/";

function fade(io,div) {
    if (io == "in") { fadein(div,100); }
    else if (io == "out") { fadeout(div,0); $(div).style.display='block';}
}

function fadeout(div,ppi) {
    ppi = ppi + 10;
    document.getElementById(div).style.opacity = ppi/100;
    if (ppi < 100) setTimeout('fadeout("'+div+'",'+ppi+')',5);
}

function fadein(div,ppi) {
    ppi = ppi - 10;
    document.getElementById(div).style.opacity = ppi/100;

    if (ppi <= 0) {
        document.getElementById(div).style.display = 'none';
    } else {
        setTimeout('fadein("'+div+'",'+ppi+')',5);  }
}

    var lboxOpacity = 0.0; 
    var lboxTimer;

    function setOpacity(element_id, opacity) { 
        element = document.getElementById(element_id); 
        opacity = (opacity == 1) ? 0.99999 : opacity; 
        element.style.opacity = opacity; 
        element.style.filter = "alpha(opacity:"+opacity*100+")"; 
    }

    function timedFade(element){ 
        lboxTimer = setTimeout("triggerFade('"+element+"', "+lboxOpacity+")", 10); 
    }

    function triggerFade(element, this_opacity){ 
        if(this_opacity <= .8){ 
            setOpacity(element, this_opacity); 
            timedFade(element); 
            lboxOpacity += 0.05; 
        }else{ 
            clearTimeout(lboxTimer); 
        } 
    }

    function lboxAjax() {
        $('ifrmscr').innerHTML = http.responseText;
    }

    function closeBox() {
            $('ll1ll1').parentNode.removeChild($('ll1ll1')); 
            $('l111ll1l1').parentNode.removeChild($('l111ll1l1')); 
            lboxOpacity = 0.0; 
    }

     function lightbox() {
        var src;
        var useAjax;
        
        this.show = create;
        this.create = create;
        this.destroy = destroy;

        function create() {

            var maindiv = document.createElement('div'); 
            maindiv.id = "l111ll1l1";
      	    maindiv.setAttribute('style', 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:9999999;color:#fff;background-color:#000;');
            maindiv.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:9999999;color:#fff;background-color:#000;';
            var wrapdiv = document.createElement('div'); 
            wrapdiv.id = "ll1ll1";
            wrapdiv.setAttribute('style','position:fixed;top:0;left:0;width:100%;height:100%;z-index:10000000;padding-top:10%;');
            wrapdiv.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:10000000;padding-top:10%;';
            wrapdiv.setAttribute('align','center');
            var loader = document.createElement('div'); 
            loader.id = "loader";
      	    loader.setAttribute('style', 'position:fixed;top:50%;left:50%;width:75px;height:75px;margin:-37px 0 0 -37px;z-index:9999999;');
      	    loader.style.cssText = 'position:fixed;top:50%;left:50%;width:75px;height:75px;margin:-37px 0 0 -37px;z-index:9999999;';
            loader.innerHTML = '<img src="'+vServer+'image/32-1.gif" alt="loader" />';
            var ifr = document.createElement('div'); 
            ifr.setAttribute('id', 'ifrmscr'); 
            ifr.setAttribute('name', 'ifflpocter'); 
      
            //Load lightbox content using ajax
            var ajax = new http_request();
            ajax.post('',this.src,lboxAjax);
            //if (this.useAjax == true) 

            maindiv.style.opacity = 0.0; 
            document.body.appendChild(maindiv); 
            maindiv.appendChild(wrapdiv); 
            maindiv.appendChild(loader); 
            wrapdiv.appendChild(ifr); 
            timedFade("l111ll1l1"); 
        }

        function destroy() {    
            $('ll1ll1').parentNode.removeChild($('ll1ll1')); 
            $('l111ll1l1').parentNode.removeChild($('l111ll1l1')); 
            lboxOpacity = 0.0; 
        }
    }

function tb_change(n,o,f) {
    var f = n.id.split('-');
    var g = f[0].split('_');
    var first = (f[1] == 0)? ' first' : '';

    $(g[0]+'-0').setAttribute('class','first');
    $(g[0]+'-0').setAttribute('className','first');

    for (var a=1; a<o; a++) {
         $(g[0]+'-'+a).setAttribute('class','');
         $(f[0]+'-'+a).setAttribute('class','');
         $(g[0]+'-'+a).setAttribute('className','');
         $(f[0]+'-'+a).setAttribute('className','');
    }
 
    $(g[0]+'-'+f[1]).setAttribute('class','selected'+first);
    $(g[0]+'-'+f[1]).setAttribute('className','selected'+first);
    n.setAttribute('class','selected'+first);
    n.setAttribute('className','selected'+first);

    //if (f) return f();
}

if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
document.onmouseup = stopDnd;
document.onmousedown = selectDnd;
document.onselectstart = selectDnd;
document.oncontextmenu = context;

var drag = new Array();
var mouse = new Array();
var cmenu = '';
function stopDnd() {
    drag[0] = '';
    if (drag[1]) drag[1]();
}
function selectDnd() {
    if (drag[0]) return false;
}
function getMouseXY(e) {
  if (IE) { 
    mouse[0] = event.clientX + document.body.scrollLeft; 
    mouse[1] = event.clientY + document.body.scrollTop;
  } else { 
    mouse[0] = e.pageX; 
    mouse[1] = e.pageY; 
  }  

  if (mouse[0] < 0) mouse[0] = 0;
  if (mouse[1] < 0) mouse[1] = 0;

  if (drag[0]) {
    return drag[0]();
  }
}
function context() {
    if (cmenu) return cmenu();
}
function drag(e) {
    what.style.left = e.pageX;
    what.style.top = e.pageY;
}
function switchs(e,n,o) { //switchs( THIS, num_of_divs, Function() )
    if (e) { var div = e.id;
    var f = div.split('-');
    for (var a=0; a<n; a++) {
        $(f[0]+'-'+a).setAttribute('class','');
        $(f[0]+'-'+a).setAttribute('className','');
    }
    e.setAttribute('class','selected');
    e.setAttribute('className','selected');
    if (o) return o();
    }
}
function sortable() {

}

