window.addEvent("domready",_csolInit);

function _csolInit(){
	CSOL.init();
}

/* 	Load pop up dialog box on page load 

	Added by White - 13-04-08
	
	getTheQuery() gets called inside CSOL on line 50
	
	Modified by Cactuslab 25-11-08
	- Added code to strip other URL parameters when opening the page.
		
/************************************************************************************************/
function getTheQuery()
{
	var pageidRegexp=new RegExp(".*?(pageid=)","gi");
	var pageidRegexp2=new RegExp("\&.*","gi");
	var loc = window.location.search;
	var pageid=loc.replace(pageidRegexp,"");
	var pageid=pageid.replace(pageidRegexp2,"");
	if(pageid) 
	{
	  var launchPage=CSOL.pages[pageid];
	  if(launchPage)CSOL.showWindow(launchPage.window,null,pageid);
	}
}
/************************************************************************************************/

CSOL = {
	loggedIn: false,
	flashId: "csol_flash",
	flashContainerId: "csol_flashContainer",
	flash:null,
	
	init: function(){
		Dialog.overlayAlpha = 0;
		var myThis = this;
		SWF.setNoFlashCallback(function(){myThis.showPage("noFlash");});
		SWF.setExpressInstallPath("swf/expressinstall.swf");
		SWF.setGatewayURL("swf/JavaScriptFlashGateway.swf");
		slidepane = new SlidePane();
		this.switchSlidePane("loggedOutPanel");
		this.flash = new SWF("swf/csol_0_main.swf",8);
		this.flash.setEffectable(true);
		this.flash.setProperty("id",this.flashContainerId);
		this.flash.setProperty("flashId",this.flashId);
		this.flash.setProperty("align","middle");
		this.flash.setProperty("bgcolor","#ffffff");
		this.flash.setProperty("scale","noscale");
		this.flash.setProperty("swLiveConnect",true);
		this.flash.setProperty("width","100%");
		this.flash.setProperty("height","100%");
		this.flash.setStyle("min-width","1016");
		this.flash.setStyle("min-height","570");
		this.flash.injectInside($E('body'));
		getTheQuery(); // Call the page dialog prompt
	},
	
	// SlidePane stuff
	switchSlidePane: function(to){
		var div = Extensions.getPrebuilt(to)
		if(div)slidepane.setContents(div);
	},
	
	// Dialog box stuff
	skins: {
		whiteBox:{
			width:565,
			header:"whiteHeader",
			body:"whiteBody",
			footer:"whiteFooter",
			closeButton:"whiteCloseButton",
			titleClass:"whiteTitle",
			frameClass:"whiteFrame"
		},
		whiteBox_wide:{
			width:748,
			header:"whiteHeader_wide",
			body:"whiteBody_wide",
			footer:"whiteFooter_wide",
			closeButton:"whiteCloseButton_wide",
			titleClass:"whiteTitle",
			frameClass:"whiteFrame_wide"
		}
	},
	windows: {
		registration:{
			defaultPage:"rego1",
			skin:"whiteBox",
			height:600
		},
		info:{
			defaultPage:"privacyPolicy",
			skin:"whiteBox",
			height:600
		},
		alert:{
			defaultPage:"passwordReminder",
			skin:"whiteBox",
			height:300
		},
		aboutCoke:{
			defaultPage:"aboutUs",
			skin:"whiteBox_wide",
			height:600
		},
		tellAFriend:{
			defaultPage:"tellAFriend",
			skin:"whiteBox",
			height:600
		},
		noFlash:{
			defaultPage:"noFlash",
			skin:"whiteBox",
			height:400
		}
	},
	pages: {
		rego1:{
			title:"Sign me up",
			url:"html/dialog_pages/signmeup_step1.htm",
			window:"registration",
			showClose:true,
			includeQueryString:false
		},
		regoValidate:{
			title:"Sign me up",
			url:"html/dialog_pages/signmeup_step2.htm",
			window:"registration",
			showClose:true,
			includeQueryString:false
		},
		regoComplete:{
			title:"Sign me up",
			url:"html/dialog_pages/signmeup_complete.htm",
			window:"registration",
			showClose:true,
			includeQueryString:false
		},
		regoFooty:{
			title:"Sign me up",
			url:"html/dialog_pages/signmeup_footy.htm",
			window:"registration",
			showClose:true,
			includeQueryString:false
		},
		editProfile:{
			title:"Edit Profile",
			url:"html/dialog_pages/edit_profile.htm",
			window:"registration",
			showClose:true,
			includeQueryString:false
		},
		welcomeEditProfile:{
			title:"Welcome to the Coke Side of Life",
			url:"html/dialog_pages/welcome_edit_profile.htm",
			window:"registration",
			showClose:true,
			includeQueryString:false
		},
		privacyPolicy:{
			title:"Privacy Policy",
			url:"html/dialog_pages/privacy_policy.htm",
			window:"info",
			showClose:true,
			includeQueryString:false
		},
		termsOfUse:{
			title:"Terms of Use",
			url:"html/dialog_pages/terms_of_use.htm",
			window:"info",
			showClose:true,
			includeQueryString:false
		},
		contactUs:{
			title:"Contact Us",
			url:"html/dialog_pages/contact_us.htm",
			window:"info",
			showClose:true,
			includeQueryString:false
		},
		contactUsThanks:{
			title:"Contact Us",
			url:"html/dialog_pages/contact_us_thanks.htm",
			window:"info",
			showClose:true,
			includeQueryString:false
		},
		faqs:{
			title:"Frequently Asked Questions",
			url:"html/dialog_pages/faqs.htm",
			window:"info",
			showClose:true,
			includeQueryString:false
		},
		newButton:{
			title:"New Button",
			url:"html/dialog_pages/newButton.htm",
			window:"info",
			showClose:true,
			includeQueryString:false
		},
		unclaimedPrizes:{
			title:"Prize Winners",
			url:"html/dialog_pages/unclaimed_prizes.htm",
			window:"info",
			showClose:true,
			includeQueryString:false
		},
		passwordReminder:{
			title:"Password Reminder",
			url:"html/dialog_pages/password_reminder.htm",
			window:"alert",
			showClose:true,
			includeQueryString:false
		},
		notLoggedIn:{
			title:"Log in or register",
			url:"html/dialog_pages/not_logged_in.htm",
			window:"alert",
			showClose:true,
			includeQueryString:false
		},
		aboutUs:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_us.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutAdvert:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_advert.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutBrands:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_brands.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutCokeZero: {
			title:"About Coca-Cola Zero",
			url:"html/dialog_pages/about_cokezero.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutContour:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_contour.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutDietary:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_dietary.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutFacts:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_facts.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutFaq:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_faq.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutMade:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_made.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutOlympics:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_olympics.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutOrigins:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_origins.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		aboutSanta:{
			title:"About Coca-Cola",
			url:"html/dialog_pages/about_santa.htm",
			window:"aboutCoke",
			showClose:true,
			includeQueryString:false
		},
		tellAFriend:{
			title:"Tell a Friend",
			url:"html/dialog_pages/tell_a_friend.htm",
			window:"tellAFriend",
			showClose:true,
			includeQueryString:false
		},
		tellAFriendThanks:{
			title:"Tell a Friend",
			url:"html/dialog_pages/tell_a_friend_thanks.htm",
			window:"tellAFriend",
			showClose:true,
			includeQueryString:false
		},
		resetPassword:{
			title:"Reset Password",
			url:"html/dialog_pages/reset_password.sm",
			window:"alert",
			showClose:true,
			includeQueryString:true
		},
		resetPasswordThanks:{
			title:"Reset Password",
			url:"html/dialog_pages/reset_password_thanks.htm",
			window:"alert",
			showClose:true,
			includeQueryString:false
		},
		noFlash:{
			title:"Update Flash Player",
			url:"html/dialog_pages/noflash.htm",
			window:"noFlash",
			showClose:false,
			includeQueryString:false
		}
	},
	showWindow: function(windowId, callback, page){
		var queryString = location.search;
	
		var window = this.windows[windowId];
		var page = this.pages[(page)?page:window.defaultPage];
		if(window && page){
			var skin = this.skins[window.skin];
			if(skin){
				var url = page.url;
				if( page.includeQueryString ) {
					url = url + queryString;
				}
			
				showStyledDialog(windowId, page.title, url, page.showClose, window.height, skin.width, callback, skin.header, skin.body, skin.footer, skin.frameClass, skin.titleClass, skin.closeButton);
				return false;
			}
		}
		return true;
	},
	hideWindow: function(windowId) {
		var window = getDialog(windowId);
		window.hide();
	},
	showPage: function(pageId){
		var page = this.pages[pageId];
		if(page){
			var window = getDialog(page.window);
			if(window){
				var url = page.url;
				if( page.includeQueryString ) {
					url = url + location.search;
				}
				window.show(url, page.title, page.showClose);
			}else{
				var ret = this.showWindow(page.window, null, pageId);
			}
			return false;
		}
		return true;
	}
}