String.prototype.stripHtml=function(){return this.replace(/<(?:.|\s)*?>/g,"");};
String.prototype.stripSpaces=function(){var str=this.replace(/\t/g," ");return str.replace(/\s{2,}/g," ");};
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');};
//Object.prototype.hasClass=function(st){return(this.className.indexOf(st)>-1?true:false);};
//Object.prototype.addClass=function(st){this.className+=' '+st;};
//Object.prototype.remClass=function(st){this.className=this.className.replace(new RegExp(' '+st+'\\b'),'');};
el=function(id){return document.getElementById(id);};

// addDOMLoadEvent
addDOMLoadEvent=(function(){var load_events=[],load_timer,script,done,exec,old_onload,init=function(){done=true;clearInterval(load_timer);while(exec=load_events.shift())
exec();if(script)script.onreadystatechange='';};return function(func){if(done)return func();if(!load_events[0]){if(document.addEventListener)
document.addEventListener("DOMContentLoaded",init,false);if(/WebKit/i.test(navigator.userAgent)){load_timer=setInterval(function(){if(/loaded|complete/.test(document.readyState))
init();},10);}old_onload=window.onload;window.onload=function(){init();if(old_onload)old_onload();};}load_events.push(func);}})();

// ajaxObject
function ajaxObj(url,vars,callback){var that=this;var updating=false;this.send=function(){if(updating==true){return false;}
updating=true;var AJAX=null;if(window.XMLHttpRequest){AJAX=new XMLHttpRequest();}else{AJAX=new ActiveXObject("Microsoft.XMLHTTP");}
if(AJAX==null){alert("Your browser doesn't support AJAX.");return false;}else{AJAX.onreadystatechange=function(){if(AJAX.readyState==4||AJAX.readyState=="complete"){callback(AJAX.responseText);delete AJAX;updating=false;}}
var timestamp=new Date();var uri=urlCall+'?'+vars+'&timestamp='+(timestamp*1);AJAX.open("GET",uri,true);AJAX.send(null);return true;}}
var urlCall=url;};

// Cookies
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}else var expires="";document.cookie=name+"="+value+expires+"; path=/";};function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}return null;};function eraseCookie(name){createCookie(name,"",-1);};

// Include google analytics onload
var ga_key = "UA-6018714-1";
load_ga = function(){var gaJsHost  = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");var s = document.createElement('script');s.src = gaJsHost + "google-analytics.com/ga.js";s.type = "text/javascript";document.getElementsByTagName("head")[0].appendChild(s);var i = 0;run_ga();
function run_ga(){if(typeof _gat == "object"){var pageTracker = _gat._getTracker(ga_key);pageTracker._initData();pageTracker._trackPageview();}else if(i < 20){i++;setTimeout(run_ga, 500);}};};
if(window.addEventListener){window.addEventListener("load", load_ga, false);}else if(window.attachEvent){window.attachEvent("onload", load_ga);} 

// swf heading replacement
var swfheadings = {
	'h2': { fsize: 28, lheight: 25, leading: -12, margin: '0 0 10px 0' },
	'h3': { fsize: 19, lheight: 17, leading: -4, margin: '24px 0 4px 0' },
	'h5': { fsize: 54, lheight: 52, leading: -24, margin: '0 0 0px 0'},
	'h6': { fsize: 23, lheight: 25, leading: -10, margin: '0 0 10px 0'},
	Init:function(htag){var helems=document.getElementsByTagName(htag);var hprops=swfheadings[htag];var hreplace=new Array();for(var i=0;i<helems.length;i++){if(helems[i].className.indexOf('swf')>-1){var hid='swfheading-'+htag+i;helems[i].setAttribute('id',hid);var atxt=helems[i].innerHTML.toUpperCase().split('<BR>');var h=helems[i].offsetHeight;var atxtf=new Array();for(var x=0;x<atxt.length;x++){atxtf.push(atxt[x].trim());}var txtf=atxtf.join('<br>');txtf=txtf.replace(/<span.*?>/gi,'<font color=\'#ec1d23\'>').replace(/<\/span>/gi,'</font>');var wrap=document.createElement('span');wrap.style.display='block';wrap.style.overflow='hidden';wrap.style.height=h+'px';wrap.style.margin=hprops.margin;helems[i].parentNode.insertBefore(wrap,helems[i]);wrap.appendChild(helems[i]);hreplace.push({'hid':hid,'text':'<font size=\''+hprops.fsize+'\' color=\'#000000\'>'+txtf+'</font>','leading':hprops.leading});}}for(var i=0;i<hreplace.length;i++){swfobject.embedSWF(CFG_BASEURL+'/assets/swf/heading.swf',hreplace[i].hid,600,100,'8.0','',{txt:escape(hreplace[i].text),tleading:hreplace[i].leading},{wmode:'transparent'},false);}}
};

// Invite a friend popup toggle
var invite = {
	maxh: 470,
	Toggle:function(b){if(b){var inviteWrap=document.createElement('div');inviteWrap.setAttribute('id','invite');inviteWrap.innerHTML='<div id="invite-inner"><iframe id="invite-iframe" src="'+CFG_BASEURL+'/invite/" scrolling="no" style="overflow:hidden;"></iframe></div>';inviteWrap=document.body.appendChild(inviteWrap);var startleft=Math.ceil((document.body.offsetWidth-inviteWrap.offsetWidth)/2);inviteWrap.style.left=startleft+'px';var starttop=el('bottom').offsetTop+el('bottom').offsetHeight+11;for(var i=0;i<invite.maxh;i++){starttop-=1;invite.timers[i]=window.setTimeout('invite.Resize('+i+', '+invite.maxh+', '+starttop+')',i*0.8);}inviteWrap.style.visibility='visible';}return false;},
	Resize:function(newh,endh,newt){var obj=el('invite');if(newh!=endh){obj.style.height=newh+'px';obj.style.top=newt+'px';}else{for(var i=0;i<invite.endh;i++){window.clearTimeout(invite.timers[i]);}}},
	Close:function(){var obj=el('invite');obj.parentNode.removeChild(obj);},
	done: false,
	timers: new Array()
};

var bgLoaded = function() {
	createCookie('nbx_bgloaded', 1, 365);
};

// Fave store function
var favStore = {
	set: function(arr) {
		createCookie('nbx_favstore', arr.join('|'), 365);
		var favLinks = el('wrap-content').getElementsByTagName('span');
		for(var i = 0; i < favLinks.length; i++) {
			if(favLinks[i].className.indexOf('active')>-1) {
				favLinks[i].className=favLinks[i].className.replace(new RegExp('active\\b'),'');
				favLinks[i].innerHTML = '&raquo; Make this my favourite store';
			}
		}
		el('store-'+arr[0]+'-fav').innerHTML = '&raquo; This is your new favourite store!';
		el('store-'+arr[0]+'-fav'),className += 'active';
		favStore.display();
	},
	display: function() {
		var fav = readCookie('nbx_favstore');
		if(fav) {
			fav = fav.split('|');
			var phone = fav[3].split(' ');
			el('bottom-fave-text').innerHTML = '<strong class="dark">'+fav[1]+'</strong><br />'+fav[2]+'<br /><span class="red">P:</span> <span class="lite">('+phone[0]+')</span> <span class="dark">'+phone[1]+' '+phone[2]+'</span><br /><a class="imgtext change" href="'+CFG_BASEURL+'/locations/">Change it</a>';
			el('bottom-fave-link').href = 'javascript:void(null);';
			el('bottom-fave-link').title = 'View map';
			el('bottom-fave-link').onclick = function() {
				showMap(fav[0],fav[1]);
			};
		}
		else {
			el('bottom-fave-text').innerHTML = 'Do you have a favourite <strong class="dark">Noodle Box</strong> store?<br /><a class="imgtext choose" href="'+CFG_BASEURL+'/locations/">Choose it</a>';
			el('bottom-fave-link').href = CFG_BASEURL+'/locations/';
			el('bottom-fave-link').title = '';
			el('bottom-fave-link').onclick = null;
		}
	}
};

// Bacground swf
var bgSwf = function() {
	swfobject.embedSWF(CFG_BASEURL+'/assets/swf/bgd.swf','swf-bgd','100%','100%','8.0',CFG_BASEURL+'/assets/swf/expressInstall.swf',false,{wmode:'transparent',scale:'noborder',align:'middle'},false);
};

// Popup map
var showMap = function(id, suburb) {
	var a = document.createElement("a");
    a.href = CFG_BASEURL+'/locations/map.php?id='+id;
    a.rel = 'lyteframe';
	a.title= 'Noodle Box '+suburb;
	a.rev = 'width: 500px; height: 500px; scrolling: no;';
	myLytebox.start( a, false, true);
	//modalbox.Show(CFG_BASEURL+'/locations/map.php?id='+id, 'Noodle Box '+suburb, 500, 500);
};

// Popup menu details
var menuDetails = function(str) {
	var a = document.createElement("a");
    a.href = CFG_BASEURL+'/menu/details/'+str+'.php';
    a.rel = 'lyteframe';
	a.rev = 'width: 600px; height: 500px; scrolling: yes;';
	myLytebox.start( a, false, true);
	//modalbox.Show(CFG_BASEURL+'/menu/details/'+str+'.php', 'Noodle Box', 600, 500);
};

// OnDomReady
addDOMLoadEvent(function(){
	swfheadings.Init('h2');
	swfheadings.Init('h3');
	swfheadings.Init('h5');
	swfheadings.Init('h6');
	if(el('bottom-fave')) {
		favStore.display();
	}
});

// Load bg swf
/*
var bg = readCookie('nbx_bgloaded');
if(bg) {
	addDOMLoadEvent(function(){
		bgSwf();
	});
}
else {
	if(window.addEventListener){
		window.addEventListener("load", bgSwf, false);
	}
	else if(window.attachEvent){
		window.attachEvent("onload", bgSwf);
	}
}
*/
