/* IBC Helper module: Last updated by AndyP on 17/11/2009 */

if(typeof Namespace=="undefined") var Namespace={};
if(!Namespace.Manager) Namespace.Manager={};
Namespace.Manager={
	Register:function(a){
		if(a.length>0){
			var b=a.substring(0,a.lastIndexOf("."));
			this.Register(b);
			eval("if(!window."+a+") window."+a+"={};");
		}
	}
};

Namespace.Manager.Register("IBC.helper");

IBC.helper.init=function(){
	IBC.helper.isIE=/*@cc_on!@*/false;
	IBC.helper.isIE6=false /*@cc_on || @_jscript_version < 5.7 @*/;
	IBC.helper.isIE7=false /*@cc_on || @_jscript_version >= 5.7 @*/;
	IBC.helper.jsRoot="/site/custom_scripts/js/";
	if(!IBC.helper.isIE||IBC.helper.isIE6||IBC.helper.isIE7){
		try{
			document.observe("dom:loaded",function(){
				IBC.helper.imaps();
				IBC.helper.waste();
				IBC.helper.visit();
				IBC.helper.slide();
				IBC.helper.flv();
			});

			window.onunload=function(){
				IBC.helper.hash.get("listeners").invoke("stopObserving");
				try{
					google.maps.Unload();
					IBC.helper=null;
					IBC.imaps=null;
				}catch(z){}
			};

			IBC.helper.head=document.getElementsByTagName("head")[0];
			IBC.helper.hash=new Hash();
			IBC.helper.hash.set("listeners",new Array());
			IBC.helper.hash.get("listeners").push(document);
		}catch(z){}
	}
};

IBC.helper.imaps=function(){
	var a=new RegExp("http://maps.google.com/maps");
	var b=new RegExp("http://maps.google.com/staticmap");
	var c=d=0;
	var e,f,g,h;

	IBC.helper.imaps.load=function(){
		IBC.imaps.init();
	};

	$$("script").each(function(e){
		if(a.test(e.readAttribute("src"))){
			c++;
		}
	});
	$$("div.i_ba img").each(function(f){
		if(b.test(f.readAttribute("src"))){
			if(d==0){
				IBC.helper.hash.set("smaps",new Array());
			}
			IBC.helper.hash.get("smaps").push(f);
			d++;
		}
	});
	g=Math.floor((Math.random())*9999999);
	h="IBC.helper.imaps.js"+g;
	eval(h+'=function(){if(google.maps.BrowserIsCompatible()){IBC.helper.loadJS(IBC.helper.jsRoot+"imaps.js",IBC.helper.imaps.load);}};');
	if(d>0){
		if(c>0){
			eval(h+'();');
		}else{
			IBC.helper.loadJS("http://maps.google.com/maps?file=api&v=2.151&sensor=false&key=ABQIAAAAN3yJqdQwO4PmxTKEFiAuohQ4s1maSTXJWHJB0hJw3QSxFgjCfhQkTSTgcR2htcZYLJ5fXmbKtCP4gQ&async=2&callback="+h);
		}
	}
};

IBC.helper.waste=function(){
	if($("i_ca")){
		IBC.helper.loadJS(IBC.helper.jsRoot+"wsaver.js");
	}
};

IBC.helper.visit=function(){
	if($("i_da")){
		IBC.helper.loadJS(IBC.helper.jsRoot+"vipswich.js");
	}
};

IBC.helper.slide=function(){
	if($("i_ea")){
		IBC.helper.loadJS(IBC.helper.jsRoot+"slide.js");
	}
};

IBC.helper.flv=function(){
	if($$("div.i_flp").length>0 || $$("div.audio").length>0){
		IBC.helper.flv.swf=function(){
			IBC.helper.loadJS(IBC.helper.jsRoot+"swf.js");
		};

		IBC.helper.loadJS(IBC.helper.jsRoot+"swfobject.js",IBC.helper.flv.swf);
	}
};

IBC.helper.loadJS=function(a,b){
	var c=document.createElement("script");
	c.type="text/javascript";
	if(c.readyState){
		c.onreadystatechange=function(){
			if(c.readyState=="loaded"||c.readyState=="complete"){
				c.onreadystatechange=null;
				if(b){
					b();
				}
			}
		};
	}else{
		c.onload=function(){
			if(b){
				b();
			}
		};
	}
	c.src=a;
	IBC.helper.head.appendChild(c);
};

IBC.helper.init();
