/**
 * 
 * Author: Robert Vadai <robert.vadai@28design.com>
 * Copyright: Copyright (c) 2010 - 2011, Inflight Productions Ltd.
 * Version: 1.0.2
 * 
 * Description: IFPlitebox is a Litebox clone only to load external HTML content (aka iframes).
 * 
 * Requirements: jQuery 1.4.2 or newer
 * 
 * Usage example:
 * 
 * 		new IFPlitebox("klmife", 1000, 585, 10, 10, "http://www.mywebsite.net", "myClassName").show();
 * 
 * Changelog:
 *
 */
var IFPlitebox=function(g,e,a,d,c,f,b){if("undefined"==typeof(jQuery)){throw"jQuery library is not loaded"}this.theme=g;this.uri=f;this.width=e;this.height=a;this.horizontalBorderWidth=d;this.verticalBorderWidth=c;this.cssClass=b;this.VIEWPORT_ALL=1;this.VIEWPORT_WIDTH=2;this.VIEWPORT_HEIGHT=3};IFPlitebox.prototype.getViewportSize=function(c){var d;var b;if("undefined"!=typeof(window.top.innerWidth)){d=window.top.innerWidth;b=window.top.innerHeight}else{if("undefined"!=typeof(window.top.document.documentElement)&&"undefined"!=typeof(window.top.document.documentElement.clientWidth)&&0!=window.top.document.documentElement.clientWidth){d=window.top.document.documentElement.clientWidth;b=window.top.document.documentElement.clientHeight}else{d=window.top.document.getElementsByTagName("body")[0].clientWidth;b=window.top.document.getElementsByTagName("body")[0].clientHeight}}if(this.VIEWPORT_ALL==c){var a=new Array();a.push(d);a.push(b);return a}else{if(this.VIEWPORT_WIDTH==c){return d}else{if(this.VIEWPORT_HEIGHT==c){return b}else{return null}}}};IFPlitebox.close=function(){var b=window.top.document.getElementById("IFPlitebox_container");var a=window.top.document.getElementById("IFPlitebox_canvas");if("undefined"!=typeof(b)&&null!=b&&"undefined"!=typeof(a)&&null!=a){b.parentNode.removeChild(b);a.parentNode.removeChild(a)}};IFPlitebox.prototype.close=function(){IFPlitebox.close()};IFPlitebox.prototype.show=function(){var u=this.getViewportSize(this.VIEWPORT_WIDTH);var f=this.getViewportSize(this.VIEWPORT_HEIGHT);if(null!=document.domain&&window.top.document.domain==document.domain&&f>this.height&&u>this.width){var l=function(D){D.css("float","left")};var z=null;var c=document.getElementsByTagName("head")[0].innerHTML.match(/src="(.*)ifplitebox(.*)"/g);if(c.length>0){z=c[0].substr(5,c[0].search("ifplitebox")+5)+"/theme/"}if(null==z){throw"Theme URL can't be set"}var h=$(document.createElement("link"));h.attr({rel:"stylesheet",type:"text/css",href:z+this.theme+"/style.css"});$(window.top.document.getElementsByTagName("head")[0]).append(h);var a=$(document.createElement("div"));a.css("clear","both");var C=a.clone(false);var B=a.clone(false);var b=$(document.createElement("div"));b.addClass("topLeft");b.html("&nbsp;");l(b);var y=$(document.createElement("div"));y.addClass("top");y.html("&nbsp;");y.css("width",this.width+"px");l(y);var x=$(document.createElement("div"));x.addClass("topRight");x.html("&nbsp;");l(x);var i=$(document.createElement("div"));i.addClass("middleLeft");i.html("&nbsp;");i.css("width",this.horizontalBorderWidth+"px");i.css("height",this.height+"px");l(i);var p=$(document.createElement("div"));p.addClass("box1");var o=$(document.createElement("div"));o.addClass("box2");var m=$(document.createElement("div"));m.addClass("loading");m.css("width",this.width+"px");m.css("height",this.height+"px");l(m);m.append(p);m.append(o);var t=null;if(/MSIE/i.test(navigator.userAgent)){t=$(document.createElement("iframe"));t.attr({width:this.width,height:this.height,src:this.uri,frameborder:0,marginwidth:0,marginheight:0})}else{t=$(document.createElement("object"));t.attr({type:"text/html",width:this.width,height:this.height,data:this.uri})}t.hide();var w=this;t.ready(function(){t.css("margin","-"+(w.height+w.verticalBorderWidth)+"px 0 0 "+w.horizontalBorderWidth+"px");l(t);m.css("visibility","hidden");t.show()});var k=$(document.createElement("div"));k.addClass("middleRight");k.html("&nbsp;");k.attr("style","width: "+this.horizontalBorderWidth+"px; height: "+this.height+"px;");l(k);var r=$(document.createElement("div"));r.addClass("bottomLeft");r.html("&nbsp;");l(r);var A=$(document.createElement("div"));A.addClass("bottom");A.html("&nbsp;");A.attr("style","width: "+this.width+"px;");l(A);var n=$(document.createElement("div"));n.addClass("bottomRight");n.html("&nbsp;");l(n);var q=$(document.createElement("div"));var d=20;if(null!=f){d=Math.floor((f-this.height)/2)}q.attr({id:"IFPlitebox_area",style:"width: "+(this.width+2*this.horizontalBorderWidth)+"px; margin: "+d+"px auto 0 auto;"});var j=document.createElement("span");j.innerHTML="Close";var e=$(document.createElement("a"));e.attr({id:"IFPlitebox_Close",style:"cursor: pointer;"});e.click(function(){IFPlitebox.close()});e.append(j);q.append(b);q.append(y);q.append(x);q.append(a);q.append(i);q.append(m);q.append(k);q.append(C);q.append(r);q.append(A);q.append(n);q.append(B);q.append(e);q.append(t);var s=$(document.createElement("div"));s.attr("id","IFPlitebox_container");s.css("position","fixed");s.css("top",0);s.css("left",0);s.css("width","100%");s.css("z-index",1000);if(null!=this.cssClass){s.addClass(this.cssClass)}s.append(q);var g=$(document.createElement("div"));g.attr("id","IFPlitebox_canvas");g.css("position","fixed");g.css("top",0);g.css("left",0);g.css("width","100%");g.css("height","10000px");g.css("background","#000");g.css("opacity",0.8);g.css("z-index",999);top.window.document.body.style.margin=0;top.window.document.body.style.padding=0;$(top.window.document.body).append(s);$(top.window.document.body).append(g);var v=e.offset();if(v.top<0){e.css({position:"fixed",marginTop:"0px",marginLeft:(this.width+(this.horizontalBorderWidth*2))+"px",top:(t.offset().top-this.verticalBorderWidth)+"px"})}}else{window.open(this.uri,"IFPlitebox_window","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,width="+this.width+",height="+this.height)}};
