$(function() {
    $("#application").hide();
});
/**
 * @author Rob Been, Qelp BV 
 */
 
/*var Urls = {
 "nl_BE": "http://www.base.be/nl/configureer-je-gsm",
 "fr_BE": "http://www.base.be/fr/configurez-votre-gsm",
 "en_UK": "http://www.base.be/en/configure-your-handset"
};*/

var Urls = {
 "nl_BE": "http://www.base.be/nl/mobiel-internet/op-je-gsm/configureren/qelp",
 "fr_BE": "http://www.base.be/fr/internet-mobile/sur-votre-gsm/configurer/qelp",
 "en_UK": "http://www.base.be/en/mobile-internet/on-your-handset/configure/qelp"
};

function CustomerObject() {
	// Will be called by main script, fill with extra functions as needed.
	this.BRAND = "BASE";
	this.LOCALES = ["nl_BE", "fr_BE", "en_UK"];
	this.SUBSCRIPTIONPLANS = ["Base", "Jim"];
	this.DEFAULT_MANUFACTURER = "Nokia"
	var qelpObject;
	var that = this;
	
	this.init = function(qelpObject) {
		this.qelpObject = qelpObject;
		this.qelpObject.flashLoaded = false;
		this.qelpObject.done = false;
		
		 var newLocation = Urls[this.getLocale()] + "#" + window.location.pathname;
         if (document.referrer) {
             newLocation += "?qelpReferrer=" + encodeURIComponent(encodeURIComponent(document.referrer));
         }
         window.location = newLocation;
         return false;
		
		/*
		try {
			//alert(location.pathname);
			if (SWFAddress.getValue() == "/") {
				// history / deeplinking current location
				SWFAddress.setValue(location.pathname.replace("index.html", ""));
				newLoad = true;
			}
		} catch (error){}
		//if (swfobject.getQueryParamValue("nowrap") != 1) this.loadWrapper();
		//else this.loadFlash();
		if (swfobject.getQueryParamValue("hideFlash") == "" && swfobject.getFlashPlayerVersion().major >= 9)
		{
			that.hasFlash = true;
			that.loadFlash();
			return true;
		}*/ 
		//return false; 
	}
	
	
	this.getBrand = function() {
		return this.BRAND;
	}
	
	this.getLocale = function() {
		if (window.location.hostname.search("nl-be") >= 0 || window.location.pathname.search(this.LOCALES[0]) >= 0) return this.LOCALES[0];
		if (window.location.hostname.search("fr-be") >= 0 || window.location.pathname.search(this.LOCALES[1]) >= 0) return this.LOCALES[1];
		if (window.location.hostname.search("en-uk") >= 0 || window.location.pathname.search(this.LOCALES[2]) >= 0) return this.LOCALES[2];
		return this.LOCALES[0];
	}
	
	this.getDefaultManufacturer = function() {
		return this.DEFAULT_MANUFACTURER;
	}
	this.setCurrentStepText = function(step, total) {
		var intro = "Stap ";
		var middle = " van ";
		var outtro = "";
		
		$("#currentStep").html(intro + step + middle + total + outtro);
	}
	
	this.loadFlash = function () {
		this.qelpObject.loadFlash("/flash/qelpUI.swf", "918", "540", "9", "#FFFFFF");
	}
	
	this.loadWrapper = function(){
		that.qelpObject.done = false;
		$.get("/javascript/wrapper-" + this.getLocale() + ".tpl", null, that.showWrapper, "text");
	}
	
	this.addCss = function()
	{
		$('head').append('<link rel="stylesheet" type="text/css" href="http://www.base.be/sites/all/themes/base/css/style.css?1" />');
		$('head').append('<link rel="stylesheet" type="text/css" href="http://www.base.be/sites/all/themes/base/custom/css/extrastyle.css?1" />');
		
	}
	
	this.addScripts = function()
	{
	
	}
	
	
	
	this.showWrapper = function(data, textStatus) {
		$('body').addClass('page');
		$('#customerServiceCodeArea').remove();
		that.addCss();
		var newBody = data.replace("[TOESTELHULP]", $("body").html());
		$("body").html(newBody);
		
		that.qelpObject.done = true;
		if (swfobject.getQueryParamValue("hideFlash") == "" && swfobject.getFlashPlayerVersion().major >= 9)
		{
			that.hasFlash = true;
			that.loadFlash();
		} 
		else
		{
			that.qelpObject.startStepNavigation();
			if ($.browser.msie && $.browser.version < 7) 
			{
				// fix next and previous hover arrows for IE 6
				$("#goNext").hover(function() { 
					$(this).css("background-position", "right -70px");
					$(this).css("color", "#E20074");
				}, function() { 
					$(this).css("background-position", "right -42px");
					$(this).css("color", "#000000");
				})
							
				$("#goPrevious").hover(function() {
					$(this).css("background-position", "left -28px");
					$(this).css("color", "#E20074");	
				}, function() {
					$(this).css("background-position", "left 0px");
					$(this).css("color", "#000000");	
				})
			}
		}
		that.qelpObject.checkShow()
	}
}
