/* www.goby.com
 
@author Jacob at Goby
 @version 09/03/11
@svn goby_-150
*/

var BASE_PATH;var CSS_PATH;var JS_PATH;var FLASHMAP_PATH;var AJAX_PATH='';var GOOGLE_ANALYTIC_KEY;var GOOGLE_ANALYTIC_DOMAIN;var konsole={queue:[],log:function(args){this.queue.push(args)},dir:function(args){}};if(typeof window.console!='undefined'&&(typeof window.console.log=='function'||typeof window.console.log=='object')){konsole=window.console;}
(function(doc){var dd=doc.domain;var ds=dd.split('.');if("localhost.byledge.net"==doc.domain||"qa.goby.com"==doc.domain)
{}
else if(ds.length>2)
{try{doc.domain=ds.slice(-2).join('.');konsole.log('document.domain',dd,doc.domain);}catch(e){}}})(document);Page={};window.goby=window.goby||{embedded:false};var objects=[];var PAGE_ID;var PAGE_URL;var DEBUG_MODE;function Goby(){};Goby.prototype={get:function(object)
{if(this[object])
return this[object];else
{switch(object)
{case"searchbox":return document.searchboxHandler;break;case"results":return document.resultObject;break;case"ScriptLoader":return ScriptLoader;break;}
return null;}},objs:[],reportError:function(e)
{for(var i in e)
konsole.log(i,":",e[i]);},set:function(name,value)
{this[name]=value;return this[name];},loadPage:function(id,param1,param2,param3,param4,param5)
{return Goby.set('page',new Page[id](param1,param2,param3,param4,param5));},has:function(name)
{return(this[name]!=null?true:false);},reloadBookmarkLists:function(){},clearOutBookmarkLists:function(){},requireLogin:function($target,event,promptID)
{var callback=function(){setTimeout(function(){$target.click();},100)};if(event&&event.preventDefault!=null)
try{event.preventDefault();}catch(e){}
return this.promptLogin(callback,promptID);},conf:function(index)
{return this.config[index];},promptLogin:function(callback,promptID)
{if(this.get("customer"))
{return true;}
else
{var form=this.get("loginToolbar").displayLogin('popup',true,promptID);form.callback=callback;return false;}},addRules:function()
{var style=new StyleWrapper(0);style.insert("#state-set>ul>li>ul","display:none");style.insert("#description>span.more","display:none");},recurse:function(node)
{for(var i in node)
{konsole.log(i);this.recurse(node[i]);}
node=null;},_kill:function(obj)
{},_destruct:function()
{window._destruct();for(var i in this)
try{this[i]._destruct?this[i]._destruct():null}catch(e){}
while(objects.length>0)
{var obj=objects.pop();try
{if(obj._destruct)
{obj._destruct();}
else
obj=null;}
catch(e)
{obj=null;}}},configure:function()
{this.config=this.get('settings');},objects:[],initialize:function()
{this.configure();try
{GOOGLE_ANALYTIC_DOMAIN=this.conf('google.analytics.domain');GOOGLE_ANALYTIC_KEY=this.conf('google.analytics.key');PAGE_ID=Goby.has("pageInfo")?Goby.get("pageInfo").pageID:'default';PAGE_URL=Goby.has("pageInfo")?Goby.get("pageInfo").pageUrl:'default';DEBUG_MODE=Goby.has("debug")?Goby.get("debug"):false;Goby.set("PAGE_URL",Goby.get("pageInfo").pageUrl);}
catch(e)
{}
Goby.set("customer",Goby.get("customer")?new Profile(Goby.get("customer")):null);Goby.set("scriptLoader",new ImportScript());if(Goby.conf('facebook')&&Goby.conf('facebook').active)
window.Facebook=Goby.set('Facebook',new FacebookWrapper());else
konsole.log('not loaded.');Goby.set("MapLoader",MapLoader);this.addRules();$(window).unload(function(){Goby._destruct();});}}
var Goby=new Goby;function StyleWrapper(index)
{try
{this.style=document.styleSheets[0];}
catch(e)
{this.style=null;}}
StyleWrapper.prototype={insert:function(name,value)
{if(this.style==null)
return false;try
{if(this.style.deleteRule)
{var totalrules=this.style.cssRules?this.style.cssRules.length:this.style.rules.length;this.style.insertRule(name+"{"+value+"}",totalrules-1);}
else if(this.style.removeRule)
{this.style.addRule(name,value);}}
catch(e){}}}
var Class=function(params)
{var object=params.model?params.model(params):new Object;if(params.inherits!=null)
{var obj=params.inherits.prototype;for(var j in obj)
object[j]=obj[j];}
for(var i in params.methods)
object[i]=params.methods[i];for(var i in params.vars)
object[i]=params.vars[i];if(!params._destruct)
object._destruct=function(){Goby.objects[this.id]=null;for(var i in this){this[i]=null};}
if(params._construct)
object._construct=params._construct;object.__run=function(params,param1,param2,param3)
{this.id=Math.random();Goby.objects[this.id]=this;this._construct(params,param1,param2,param3);}
return object;};Class._Const=function(param0,param1,param2,param3){this.__run(param0,param1,param2,param3)};function flash(text)
{if(Goby.has("flash"))
$(Goby.get("flash")).remove();var bar=new FlashBar({color:'#2F4155',removebutton:false,text:text,speed:500,time:4000});document.body.appendChild(bar);bar.start();}
Page.Interface=function(params){this.__run(params);}
Page.Interface.prototype=Class({_construct:function(params){if(params&&params.widgets){this.widgets=params.widgets;}
this._display();},methods:{_display:function()
{$(document).ready(function(){if(Goby.has("scriptLoader"))
Goby.get("scriptLoader").loadQueuedScripts();var page=Goby.get('page');page.displaySearchbox();page.display();});},display:function()
{},displaySearchbox:function()
{if(Goby.conf('USE_LOGIN')){$("#login").each(function(index){if(index==0){Goby.set("loginToolbar",new LoginToolbar({container:this,customer:Goby.get("customer")}));}});}
$("a#feedbackLink").click(function(){var feed=new Feedback;feed.giveFeedback('2');});try
{Goby.set('searchbox',new Searchbox((document.forms.searchbox!=null?document.forms.searchbox:window.parent.document.forms.searchbox),{what:new WhatField(document.getElementById(browseMap.what.input)),where:new WhereField(document.getElementById(browseMap.where.input)),when:new WhenField(document.getElementById(browseMap.when.input))}));}
catch(e)
{Goby.reportError(e);}
_initExamples();}}});
