/*
 * JX 0.31
 * Copyright(c) 2008, Santosh Rajan
 * Author - Santosh Rajan
 * Email - santrajan@gmail.com
 * License - MIT, GPL
 */

var JX={extend:function(C,E,D){var B=function(){};B.prototype=E.prototype;C.prototype=new B();C.prototype.constructor=C;C.superclass=E.prototype;for(var A in D){C.prototype[A]=D[A]}},setScope:function(B,A){return function(){return B.apply(A,arguments)}},namespace:function(){var C,D;for(var B=0;B<arguments.length;B++){C=window;D=arguments[B].split(".");for(var A in D){C=C[D[A]]=C[D[A]]?C[D[A]]:{}}}},isObject:function(A){return(A&&A.constructor&&A.constructor==Object.prototype.constructor&&!A.nodeName)?true:false},isArray:function(A){return/array/gi.test(A.constructor)?true:false},jxTypes:{component:"JX.Component",container:"JX.Container",columncontainer:"JX.ColumnContainer",panel:"JX.Panel",frame:"JX.Frame",roundcornerbox:"JX.RoundCornerBox"}};JX.Component=function(){if(JX.isObject(arguments[0])){var A=arguments[0];A.jxtype=A.jxtype?A.jxtype:"div";A.jxtype=JX.jxTypes[A.jxtype]?"div":A.jxtype;JX.Component.superclass.init.call(this,document.createElement(A.jxtype));this.applyConfig(A)}else{if(arguments.length>0){JX.Component.superclass.init.apply(this,arguments)}else{JX.Component.superclass.init.call(this,document.createElement("div"))}}};JX.extend(JX.Component,jQuery,{applyConfig:function(config){this.css({overflow:"hidden"});for(var key in config){var a=JX.isArray(config[key])?config[key]:[config[key]];for(var i=0;i<a.length;i++){if(config.scopeThis){a[i]=(typeof a[i]=="function")?JX.setScope(a[i],this):a[i]}}eval("this."+key+".apply(this, a)")}},jxtype:function(A){this._jxtype=A},fitWidth:function(A){this._fitWidth=A;return this},fitHeight:function(A){this._fitHeight=A;return this},scopeThis:function(A){this._scope=A},setLoadIndicator:function(B,A,C){this.children().each(function(){$(this).remove()});this.append(new JX.Component({jxtype:"image",attr:{src:B},css:{position:"relative",top:parseInt(this.height()/2-C/2)+"px",left:parseInt(this.width()/2-A/2)+"px"}}))},removeLoadIndicator:function(){this.children().each(function(){$(this).remove()})},spacingHeight:function(){var A=0,B;A+=isNaN(B=parseInt(this.css("borderTopHeight")))?0:B;A+=isNaN(B=parseInt(this.css("borderBottomHeight")))?0:B;A+=isNaN(B=parseInt(this.css("paddingTop")))?0:B;A+=isNaN(B=parseInt(this.css("paddingBottom")))?0:B;return A},spacingWidth:function(){var A=0,B;A+=isNaN(B=parseInt(this.css("borderLeftWidth")))?0:B;A+=isNaN(B=parseInt(this.css("borderRightWidth")))?0:B;A+=isNaN(B=parseInt(this.css("paddingLeft")))?0:B;A+=isNaN(B=parseInt(this.css("paddingRight")))?0:B;return A}});JX.Container=function(){this._items=[];JX.Container.superclass.constructor.apply(this,arguments)};JX.extend(JX.Container,JX.Component,{applyConfig:function(config){JX.Container.superclass.applyConfig.apply(this,arguments);var c=this.citems?this.citems:[],item,obj;for(var i=0;i<c.length;i++){item=c[i];if(JX.isObject(item)){item.jxtype=item.jxtype?item.jxtype:"div";if(JX.jxTypes[item.jxtype]){eval("obj = new "+JX.jxTypes[item.jxtype]+"(item)")}else{obj=new JX.Component(item)}}else{obj=item}this.append(obj)}},append:function(A){JX.Container.superclass.append.apply(this,arguments);if(A instanceof JX.Component){this._items.push(A)}return this},items:function(){this.citems=Array.prototype.slice.call(arguments)},doLayout:function(){var D=this.height(),A,C;for(var B=0;B<this._items.length;B++){C=this._items[B];if(C._fitWidth){C.width(this.width()-C.spacingWidth())}if(C._fitHeight){A=C;D-=C.spacingHeight()}else{D-=C.outerHeight()}}if(A){A.height(D)}for(var B in this._items){C=this._items[B];if(C.doLayout){JX.setScope(C.doLayout,C)()}}return this},getItems:function(){return this._items},trigger:function(){JX.Container.superclass.trigger.apply(this,arguments);if(this._items){for(var A=0;A<this._items.length;A++){this._items[A].trigger.apply(this._items[A],arguments)}}}});JX.Viewport=function(){JX.Viewport.superclass.constructor.call(this,document.body);this.children().each(function(){$(this).hide()});this.css({padding:"0px",margin:"0px"});this.setSize();$(window).resize(JX.setScope(this.setSize,this));if(JX.isObject(arguments[0])){this.applyConfig(arguments[0]);this.setSize()}};JX.extend(JX.Viewport,JX.Container,{setSize:function(){this.height($(window).height());this.width($(window).width());this.doLayout()}});JX.ColumnContainer=function(){if(arguments.length>0){JX.ColumnContainer.superclass.constructor.apply(this,arguments)}else{JX.ColumnContainer.superclass.constructor.call(this,{})}};JX.extend(JX.ColumnContainer,JX.Container,{applyConfig:function(A){$('<table border="0px" cellspacing="0px" cellpadding="0px"><tr></tr></table>').appendTo(this);JX.ColumnContainer.superclass.applyConfig.apply(this,arguments)},append:function(A){$("tr:first",this).append($(document.createElement("td")).append(A));if(A instanceof JX.Component){this._items.push(A)}return this},doLayout:function(){var A=this.height(),B,E;var D=this.width();for(var C=0;C<this._items.length;C++){E=this._items[C];if(E._fitHeight){E.height(A-E.spacingHeight())}if(E._fitWidth){B=E;D-=E.spacingWidth()}else{D-=E.outerWidth()}}if(B){B.width(D)}for(var C=0;C<this._items.length;C++){E=this._items[C];if(E.doLayout){JX.setScope(E.doLayout,E)()}}return this}});JX.Panel=function(A){JX.Panel.superclass.constructor.apply(this,arguments);if(this._title){JX.Panel.superclass.append.call(this,this._title)}if(this._body){JX.Panel.superclass.append.call(this,this._body)}};JX.extend(JX.Panel,JX.Container,{append:function(A){this._body.append(A);return this},title:function(A){this._title=new JX.Component(A)},body:function(A){this._body=new JX.Container(A)},getItems:function(){return this._body._items},text:function(A){this._body.text(A);return this},html:function(A){this._body.html(A);return this}});JX.Frame=function(B){this._body=new JX.Container({});JX.Frame.superclass.constructor.apply(this,arguments);var A=function(C,E,D){return new JX.ColumnContainer().append(C).append(E).append(D)};JX.Frame.superclass.append.call(this,A(this._topLeft,this._topCenter,this._topRight));JX.Frame.superclass.append.call(this,A(this._middleLeft,this._body,this._middleRight));JX.Frame.superclass.append.call(this,A(this._bottomLeft,this._bottomCenter,this._bottomRight));this._items[1].fitHeight(true).fitWidth(true)};JX.extend(JX.Frame,JX.Container,{topLeft:function(A){this._topLeft=new JX.Component(A)},topCenter:function(A){this._topCenter=new JX.Component(A)},topRight:function(A){this._topRight=new JX.Component(A)},middleLeft:function(A){this._middleLeft=new JX.Component(A)},body:function(A){this._body.applyConfig(A)},middleRight:function(A){this._middleRight=new JX.Component(A)},bottomLeft:function(A){this._bottomLeft=new JX.Component(A)},bottomCenter:function(A){this._bottomCenter=new JX.Component(A)},bottomRight:function(A){this._bottomRight=new JX.Component(A)},append:function(A){this._body.append(A);return this},getItems:function(){return this._body._items},text:function(A){this._body.text(A);return this},html:function(A){this._body.html(A);return this}});JX.RoundCornerBox=function(E){var D=E.imagepath;delete E.imagepath;var A=E.radius;delete E.radius;var C=E.backgroundColor;delete E.backgroundColor;var B=jQuery.extend({topLeft:{width:A,height:A,css:{background:"url("+D+") no-repeat top left"}},topCenter:{height:A,fitWidth:true,css:{background:C}},topRight:{width:A,height:A,css:{background:"url("+D+") no-repeat top right"}},middleLeft:{width:A,fitHeight:true,css:{background:C}},middleRight:{width:A,fitHeight:true,css:{background:C}},bottomLeft:{width:A,height:A,css:{background:"url("+D+") no-repeat bottom left"}},bottomCenter:{height:A,fitWidth:true,css:{background:C}},bottomRight:{width:A,height:A,css:{background:"url("+D+") no-repeat bottom right"}}},E);JX.RoundCornerBox.superclass.constructor.call(this,B)};JX.extend(JX.RoundCornerBox,JX.Frame)