//*****************************************************************************
// Copyright 2007 - 2009 Starscale Inc.

var ibi=(function(){var Const={Version:"2.1",CacheScripts:true,AllowLog:true,AllowAssert:false};if(!Array.indexOf){Array.prototype.indexOf=function(obj){for(var i=0;i<this.length;i++){if(this[i]==obj){return i;}}
return-1;}}
return{Phix:{},log:function(message){if((typeof message)=='boolean'){Const.AllowLog=message;return;}
if(!Const.AllowLog)return;if(window.console){window.console.log(message);}else{alert(message);}},assertNamespace:function(namespace){var parts=namespace.split('.');if(parts[0]=='ibi'){parts.shift();}
var hash=ibi;for(var i=0;i<parts.length;++i){if(!hash[parts[i]]){hash[parts[i]]={};}
hash=hash[parts[i]];}},toggleAssert:function(bool){if(bool==undefined)bool=true;Const.AllowAssert=bool;},assert:function(variable,msg){if(Const.AllowAssert&&(variable==undefined||variable==null||variable==false)){if(msg){throw msg;}else{throw"ibi.assert fired";}}},isArray:function(obj){if(typeOf(obj)=='object'){if(typeof(testVar.length)=='number'){return true;}}
return false;},Scripts:{Mode:{Serial:0,Async:1},load:function(targets,callback,isRecurse){if(targets.Loaded){$(document).ready(callback);return;}
callback=callback||function(){};if(!isRecurse){var mycallback=function(){targets.Loaded=true;$(document).ready(callback);}}else{mycallback=callback;}
var mine=targets.scripts.slice(0);if(targets.mode==ibi.Scripts.Mode.Serial){var serialCallback=function(){if(mine.length==0){mycallback();}else{if(typeof mine[0]=='string'){var sc=mine.shift();if(sc==undefined){ibi.log("No script");}
ibi.Scripts.getScript(sc,serialCallback,Const.CacheScripts);}else{var sc=mine.shift();if(sc==undefined){ibi.log("No script");}
ibi.Scripts.load(sc,serialCallback,true);}}}
serialCallback();}else{var remaining=mine.length;var asyncCallback=function(){remaining--;if(remaining==0){mycallback();}};for(var i=0;i<mine.length;++i){if(typeof mine[i]=="string"){ibi.Scripts.getScript(mine[i],asyncCallback,Const.CacheScripts);}else{ibi.Scripts.load(mine[i],asyncCallback,true);}}}},getScript:function(url,callback,cache){$.ajax({url:url,dataType:'script',success:callback,cache:cache||false});}},UI:{initButton:function(button){button.addClass('ibi-button ui-state-default ui-corner-all');button.hover(function(){if(!$(this).is('.ui-state-disabled')){$(this).addClass("ui-state-hover");}},function(){if(!$(this).is('.ui-state-disabled')){$(this).removeClass("ui-state-hover");}}).mousedown(function(){if($(this).is(".ui-state-disabled"))return;$(this).parents('.ibi-buttonset-single:first').find(".ibi-button.ui-state-active").removeClass("ui-state-active");if($(this).is('.ui-state-active.ibi-button-toggleable, .ibi-buttonset-multi .ui-state-active')){$(this).removeClass("ui-state-active");}
else{$(this).addClass("ui-state-active");}}).mouseup(function(){if(!$(this).is('.ibi-button-toggleable, .ibi-buttonset-single .ibi-button,  .ibi-buttonset-multi .ibi-button')){$(this).removeClass("ui-state-active");}});},dialog:function(divId,url,onload,options){var showProg=options.showProgress||true;if(showProg){options.cssClass=options.cssClass||'dialogProgress';}
$('#'+divId).remove();var str="<div id='"+divId+"'>";if(showProg){str+="<div id='"+divId+"Progress' class='"
+options.cssClass+"'></div>";}
str+="</div>";$('body').append(str);if(!options.title){options.title="<br/>";}
onloadFunc=function(responseText,textStatus){if(textStatus!='success'){if(showProg){$('#'+divId+'Progress').hide();var div=$('#'+divId);div.html(options.errorText||"Unable to load content.");div.show();}}else{onload();}};options.open=function(){$(this).load(url,onloadFunc);};var div=$('#'+divId);div.dialog(options);},addStyle:function(url){var id=url.replace(/[\/\.]/g,'');var style=$("#"+id)[0];if(!style){$(document.createElement('link')).attr({id:id,type:'text/css',href:url,rel:'stylesheet',media:'screen'}).appendTo($('head')[0]);}},enableDialogButtons:function(dialog){$(dialog).next().children("button").removeAttr("disabled").removeClass("ui-state-disabled").addClass("ui-state-default");},disableDialogButtons:function(dialog){$(dialog).next().children("button").attr('disabled','disabled').addClass("ui-state-disabled").removeClass("ui-state-default");}},Template:{templateRegEx:/%\((?:([A-Za-z0-9_]+)|([A-Za-z0-9_\.]+))\)/g,parse:function(tmpl,namespace){if(!tmpl){throw"Empty template in ibi.Template.parse";}
var getValue=function(ignored,simple,complex)
{if(simple){return namespace[simple];}
var names=complex.split(".");var nested=namespace;for(var i=0,length=names.length;i<length;++i){nested=nested[names[i]];}
return nested;}
return tmpl.replace(ibi.Template.templateRegEx,getValue);}},assertId:function(id){var re=/^#/;if(!id.match(re)){return"#"+id;}
return id;},parseInt:function(str,radix){radix=radix||10;return parseInt(str,radix);},getUniqueId:function(){return(new Date()).getTime().toString()+Math.floor(Math.random()*10000).toString();},updateElement:function(element,html,ignoreScripts){html=(typeof(html)=='undefined'?'':html.toString());if(ignoreScripts){$(element).innerHTML=html;}else{$(element).innerHTML=html.stripScripts();setTimeout(function(){html.evalScripts()},10);}
return element;},updateXHTMLElement:function(element,xml,ignoreScripts){if(Prototype.Browser.IE){element.update(xml,ignoreScripts);return element;}
else{try{var parser=new DOMParser();var content=ignoreScripts?xml:xml.stripScripts();var domSegment=parser.parseFromString(content,'application\/xhtml+xml');domSegment=document.importNode(domSegment.documentElement,true);while(element.firstChild){element.removeChild(element.firstChild);}
element.appendChild(domSegment);if(!ignoreScripts){setTimeout(function(){xml.evalScripts();},10);}
return element;}catch(e){element.update(xml,ignoreScripts);return element;}}}}})();