if(typeof(LiteBoxLive) === "undefined") {
  (function( window, undefined ) {
    var liteboxlive = {
      version : function(){alert(0.1)},
      defaults : {
        width:"940",
        height:"540",
        color:"000000",
        border:"4",
        start:"333333",
        end:"111111",
        opacity:"0.7",
        href:"about:blank",
        referrer:document.location.href
        },
      target:"",
      hash: function(){
        //firefox bug auto decodes location.hash so get it this way
        return (document.location.href.split("#")[1] || "")
      },
      location: "",      
      isReady : false,
      load : function(){
    		if (document.addEventListener) {
    			document.addEventListener( "DOMContentLoaded", liteboxlive.ready, false );
    			window.addEventListener( "load", liteboxlive.ready, false );    
    		}else if ( document.attachEvent ) {
    			document.attachEvent("onreadystatechange",liteboxlive.ready);	
    			window.attachEvent( "onload", liteboxlive.ready);
    		}
    		setTimeout(liteboxlive.ready,1000);
      },
      ready :function(){
        if(!document.body || !document.links){return setTimeout(liteboxlive.ready,10);}
        if(liteboxlive.isReady){return;}else{liteboxlive.isReady = true;}
                        
        var links = document.links;
                
        for (l = 0; l < links.length; l++){
          var rel=links[l].rel;
          if(rel.indexOf("liteboxlive")==0 && links[l].href){
            links[l].onclick = liteboxlive.click;
          }
        }  
        
        
        //detect hash change for non-scripted links
        liteboxlive.location = liteboxlive.hash();
        
        setInterval(function(){
          if(liteboxlive.location!=liteboxlive.hash()){ 
            liteboxlive.location = liteboxlive.hash();
            liteboxlive.launch();  
          }
        },1000);
        liteboxlive.launch();  
      },
      launch : function(){
        //launch if url hash is requesting box
        if(liteboxlive.hash().indexOf("liteboxlive")==0){
          liteboxlive.show(liteboxlive.parse(liteboxlive.hash()));
        }      
      },
      parse : function(s){
          //s=liteboxlive:target::key:value
          var c = {};         
          var s = s.split("::");
          //alert(s);

          for(var k=0;k<s.length;k++){
            var v = s[k].split(":");
            if(v.length>1){              
              if(v[0]=="liteboxlive"){
                liteboxlive.target = decodeURIComponent(v[1]);
              }else{
                c[v[0]]=decodeURIComponent(v[1]);
              }
            }
          }
          
          return c;
          
      },
      encode : function(o){
        var s = "liteboxlive";
        if(liteboxlive.target!=""){
          s=s+":"+liteboxlive.target;
        }
        for(k in o){
          s = s + "::" + k + ":" + encodeURIComponent(o[k]);
        }  
        return s;
      },
      click : function(){

        if(this.rel.indexOf("liteboxlive")==0 && this.href){
          var c = liteboxlive.parse(this.rel);
          c["href"]=this.href;     
          liteboxlive.show(c);
          return false;      
        }
      },
      html_css : "",
      body_css : "",
      
      show : function(c){
        liteboxlive.hide();

        liteboxlive.body_css = document.body.style.cssText;
        liteboxlive.html_css = document.getElementsByTagName("html")[0].style.cssText; //IE6Strict!

        document.body.style.overflow = "hidden";
        document.getElementsByTagName("html")[0].style.overflow = "hidden";
        
        var o = {};
        for (var p in liteboxlive.defaults){
          if(c[p] != undefined){
            o[p] = c[p];
          }else{
            o[p] = liteboxlive.defaults[p];
          }
        }
        //iframe can read this to detect config and to launch live & set our location so frame dont reload
        document.location.hash = liteboxlive.location = liteboxlive.encode(o);
               
        var CSS_RESET = "margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;line-height:1;list-style:none;quotes:none;content:none;outline:0;text-decoration:none;border-collapse:collapse;border-spacing:0;";
        var c = ""; //concatinate css as string before setting or ie fails
                
        liteboxlive.container = document.createElement("DIV");
        c = CSS_RESET;
        c = c + "z-index:9999;top:0;left:0;width:100%;height:100%;position:fixed;zoom:1;overflow:hidden;"; 
        c = c + "position:expression(\"absolute\");top:expression(eval(document.body.scrollTop));left:expression(eval(document.body.scrollLeft));";
        c = c + "width:expression(eval(document.documentElement.clientWidth>0?document.documentElement.clientWidth:document.body.clientWidth));height:expression(eval(document.documentElement.clientHeight>0?document.documentElement.clientHeight:document.body.clientHeight));";

        liteboxlive.container.style.cssText = c;
           
        document.body.appendChild(liteboxlive.container); 

        var width = parseInt(o.width)+(o.border*2);
        var height = parseInt(o.height)+(o.border*2);
        
        var bg = document.createElement("DIV");
        c = CSS_RESET;
        c = c + "top:0px;left:0;width:100%;height:100%;position:absolute;zoom:1;";
        c = c + "background-image:-moz-linear-gradient(top, #"+o.start+", #"+o.end+");";
        c = c + "background-image:-webkit-gradient(linear,left top,left bottom,color-stop(0, #"+o.start+"),color-stop(1, #"+o.end+"));";
        c = c + "background-color:#"+o.end+";opacity:"+o.opacity+";";        
        c = c + "-ms-filter: \"progid:DXImageTransform.Microsoft.gradient(startColorStr='#"+o.start+"', EndColorStr='#"+o.end+"') progid:DXImageTransform.Microsoft.Alpha(Opacity="+Math.round(parseFloat(o.opacity)*100)+")\";";
        c = c + "filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#"+o.start+"', EndColorStr='#"+o.end+"') filter: alpha(opacity="+Math.round(parseFloat(o.opacity)*100)+");";
        bg.style.cssText = c;
        liteboxlive.container.appendChild(bg);

        var fg = document.createElement("DIV");
        c = CSS_RESET;
        c = c + "cursor:pointer;cursor:not-allowed;top:0px;left:0;width:100%;height:100%;text-align: center;position:absolute;zoom:1;overflow:auto;";
        fg.style.cssText = c;
        fg.onclick = liteboxlive.hide;
        liteboxlive.container.appendChild(fg);
        
        var cg = document.createElement("DIV");
        c = CSS_RESET;
        //cg.style.cssText = cg.style.cssText + "position:relative;top:50%;margin:auto;margin-top:-"+height/2+"px;margin-bottom:"+height/2+"px;width:"+width+"px;height:"+height+"px;background-color:#"+o.color+";overflow:hidden;";
        c = c + "cursor:default;position:static;margin:35px auto;width:"+width+"px;height:"+height+"px;background-color:#"+o.color+";overflow:hidden;zoom:1;";
        c = c + "-moz-border-radius: 2px; -webkit-border-radius: 2px;border-radius: 2px;-moz-box-shadow: 0px 0px 15px #000;-webkit-box-shadow: 0px 0px 15px #000;box-shadow: 0px 0px 15px #000;";
        cg.style.cssText = c;
        cg.onclick = function(e){
          if(!e){var e = window.event;e.cancelBubble = true;}
        	if (e.stopPropagation){e.stopPropagation();}
          return false;
          };
        fg.appendChild(cg);
                
        var pg = document.createElement("DIV");
        c = CSS_RESET;
        c = c + "position:relative;padding:"+o.border+"px;";
        pg.style.cssText = c;
        cg.appendChild(pg);
        
        var ig = document.createElement("IFRAME");
        c = CSS_RESET;
        c = c + "position:relative;width:"+o.width+"px;height:"+o.height+"px;background:#000000;";        
        ig.style.cssText = c;
        ig.setAttribute("src", o.href);
        ig.setAttribute("frameBorder", 0);
        
        pg.appendChild(ig);
        
        var xg = document.createElement("DIV");
        xg.innerHTML = "X";
        c = CSS_RESET;
        c = c + "position:absolute;right:0px;top:0px;width:20px;height:20px;background:#ff0000;color:#ffffff;overflow:hidden;";
        c = c + "cursor:pointer;font-family:Helvetica,sans-serif;font-size:14px;font-weight:bold;text-align:center;vertical-align:middel;line-height:20px;";
        xg.style.cssText = c;
        xg.onclick = liteboxlive.hide;
        pg.appendChild(xg);
        
      },
      hide : function(){      
        document.location.hash = "";
        if(liteboxlive.container){
          //need to remove expressions from css before we remove or ie errors 
          liteboxlive.container.style.cssText = "display:none;";
          document.body.removeChild(liteboxlive.container); 
          delete liteboxlive.container;
        }
        document.body.style.cssText = liteboxlive.body_css;
        document.getElementsByTagName("html")[0].style.cssText = liteboxlive.html_css;
      } 
    };
    liteboxlive.load();
    //register class
    window.LiteBoxLive = liteboxlive;
  })(window);
}



