/*
@ Author : Remon de Boer
@ Company: Techtribe
@ E-mail : Remon@techtribe.nl
*/
var flashChangedState = false;

var FLASHVERSION = '9.0.124';

var Achmea = {

	wzwmb: {
		visitorID: "",
		rorschachGadgetId: "",
		showPollResults: false,
		showQuestion: false,
        noFlashString : (function (that) {
            var currentFlashPlayer = swfobject.getFlashPlayerVersion();
            return [
                '<a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash player</a> because your Adobe Flash Player (is ',
                currentFlashPlayer.major,
                ".",
                currentFlashPlayer.minor,
                '.',
                currentFlashPlayer.release,
                ' ) is not current (like ',
                FLASHVERSION,
                ').'
            ].join('');
        })(),

		init: function() {
			var visitorID = Achmea.wzwmb.getParameter("visitorID");
			if(visitorID != undefined){
				this.visitorID = visitorID;
			}
			var rorschachGadgetId = Achmea.wzwmb.getParameter("rorschachGadgetId");
			if(rorschachGadgetId != undefined){
				this.rorschachGadgetId = rorschachGadgetId;
			}
			var showPollResults = Achmea.wzwmb.getParameter("showPollResult");
			if(showPollResults == "true"){
				this.showPollResults = true;
			}
			var showQuestion = Achmea.wzwmb.getParameter("showQuestion");
			if(showQuestion == "true"){
				this.showQuestion = true;
			}
			Achmea.wzwmb.History.init();
			Achmea.wzwmb.Flash.init();
			Techtribe.TransparantFix.init();
		},

		getParameter: function(str) {
			var paramStr = location.search;
			if(paramStr.length > 0){
				paramStr = paramStr.substring(1, paramStr.length);
				if(paramStr.indexOf("&") == -1){
					var param = paramStr.split("=");
					if(param[0] == str){
						return param[1];
					}
				} else {
					var params = paramStr.split("&");
					for(var i=0;i<params.length;i++)
					{
						var param = params[i].split("=");
						if(param[0] == str){
							return param[1];
						}
					}
				}
			}
		},

		openHyvesFrame: function(url){
			var hyvesFrame = document.getElementById("hyvesFrame");
			var hyvesIFrame = document.getElementById("hyvesIFrame");
			hyvesIFrame.src = url;
			hyvesFrame.style.display = "block";

		}
	}
}

//Achmea History
Achmea.wzwmb.History =
{
	HOME_STATE: "home",
	BRANDS_STATE: "brands",
	ABOUT_STATE: "about",
	CONTACT_STATE: "contact",
	POLICY_STATE: "policy",
	ALL_CAMPAIGNS_STATE: "allCampaigns",
	CAMPAIGN_STATE: "campaign",
	STATEMENT_STATE: "statement",
	VISION_STATE: "vision",
	ARTICLE_STATE: "article",
	FACT_STATE: "fact",
	TOOL_STATE: "tool",
	flashChangedState: false,
	state: null,
	stateID: null,
	itemID: null,
	timer: null,

	init: function() {
		this.state = YAHOO.util.History.getBookmarkedState("state");
		if(!this.state){
			this.state = "home";
			this.stateID = "0";
			this.itemID = "0";
		} else {
			this.stateID = YAHOO.util.History.getBookmarkedState("stateID");
			if(!this.stateID){
				this.stateID = YAHOO.util.History.getBookmarkedState("id");
				if(!this.stateID){
					this.stateID = "0";
				}
			}
			this.itemID = YAHOO.util.History.getBookmarkedState("itemID");
			if(!this.itemID){
				this.itemID = "0";
			}
		}
		YAHOO.util.History.register("state", this.state, this.stateChangeHandler);
		YAHOO.util.History.register("stateID", this.stateID, this.stateIDChangeHandler);
		YAHOO.util.History.register("itemID", this.itemID, this.itemIDChangeHandler);
		YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe");
	},

	stateChangeHandler: function(state) {
		clearTimeout(this.timer);
		this.state = state;
		this.timer = setTimeout(updateFlash, 50, this.state, this.stateID, flashChangedState);
	},

	stateIDChangeHandler: function(state) {
		clearTimeout(this.timer);
		this.stateID = state;
		this.timer = setTimeout(updateFlash, 50, this.state, this.stateID, flashChangedState);
	},

	itemIDChangeHandler: function(state) {
		clearTimeout(this.timer);
		this.itemID = state;
		this.timer = setTimeout(updateFlash, 50, this.state, this.stateID, flashChangedState);
	},

	updateFrame: function(stateStr, id, windowTitle, counterName) {
		flashChangedState = true;
		var multiState = {state: stateStr, stateID: id};
		//YAHOO.util.History.multiNavigate(multiState);
		if((windowTitle != "") && (windowTitle != null) && (windowTitle != "null")){
			var title = Techtribe.Common.htmlEntityDecode(windowTitle);
			document.title = title;
		} else {
			document.title = "Waar zijn we mee bezig | wzwmb";
		}
		if((counterName != "") && (counterName != null) && (counterName != "null")){
			pageTracker._trackPageview(counterName);
		} else {
			pageTracker._trackPageview("/" + stateStr + "/" + id);
		}
	}
}

function updateFlash(stateStr, id, windowTitle, counterName) {
	if(!flashChangedState){
		//document.getElementById("flash_movie").updateFlash(stateStr, id);
	} else {
		flashChangedState = false;
	}
}

//Achmea flash
Achmea.wzwmb.Flash =
{
	init: function() {
		var flashvars = {
			state:Achmea.wzwmb.History.state,
			stateID:Achmea.wzwmb.History.stateID,
			itemID:Achmea.wzwmb.History.itemID,
			visitorID:Achmea.wzwmb.visitorID,
			rorschachGadgetId:Achmea.wzwmb.rorschachGadgetId,
			showPollResults:Achmea.wzwmb.showPollResults,
			showQuestion:Achmea.wzwmb.showQuestion,
			rootPath:rootPath,
			staticPath:staticPath,
			gatewayURI:"gateway",
			introFLV:"media/flv/achmea_wzwmb_intro.flv"
		};
		var params = {
		  	menu: "false",
			quality: 'high',
		  	allowFullScreen: "true",
		  	allowNetworking: "all",
		  	allowScriptAccess: "always"
		};
		var attributes = {
			id: "flash_movie",
			name: "flash_movie"
		};
		swfobject.embedSWF(flashPath, "flash", "980", "560", FLASHVERSION, "media/expressInstall.swf", flashvars, params, attributes);
	}
}

function spotlight(tagVal)
{
	var spotlighttag;
		var Tag;
		var axel = Math.random() + "";
		var ord = axel * 1000000000000000000;
		var prx = "?";

spotlighttag="http://ad.nl.doubleclick.net/activity;src=1885924;type=waarz374;cat="+tagVal+";ord="+ord+prx;
		Tag = new Image();
		Tag.src = spotlighttag;
}
