﻿if (!window.HN) HN = window.HN = {};
HN.MS = {};
HN.MS.Bing_solidaire = {};
HN.MS.Bing_solidaire.domain = "bingsolidaire.com";

var cm = new HN.CookieManager();

// Execute the Init function when DOM is ready
$(function(){ HN.MS.Bing_solidaire.Init(); });

HN.MS.Bing_solidaire.Init = function () {

	HN.png2alpha("png2keep");
	
	// Preload some images
	var img2preloadList = [
	];
	for (var i=0; i<img2preloadList.length; i++) {
		var img2preload = new Image();
		img2preload.src = HN.MS.MPEL.base_url+HN.MS.MPEL.base_rsc_url+"images/"+img2preloadList[i];
	}

	var $home = $("div.home, div.how-it-works");
	if ($home.length > 0) {
		$home.find("a.button-activate").click(function(){
			var startingPage = $home.find("input[name=startingPage][type=radio]:checked").val();
			var charitableAssociation = $home.find("input[name=charitableAssociation][type=radio]:checked").val();
			var cookieString = (startingPage?startingPage:"")+"|"+(charitableAssociation?charitableAssociation:"");
			var expirationDate = new Date();
			expirationDate.setTime(expirationDate.getTime()+365*24*60*60*1000);
			cm.write("bingSolidaire", cookieString, expirationDate, "/", HN.MS.Bing_solidaire.domain);
			if (HN.browser.msie) {
				if (startingPage == "BING")
					this.href = "http://www.bingsolidaire.com/ressources/toolbar/bing_solidaire_bing.exe";
				else if (startingPage == "MSN")
					this.href = "http://www.bingsolidaire.com/ressources/toolbar/bing_solidaire_msn.exe";
			}
			else if (HN.browser.firefox) {
				if (startingPage == "BING")
					this.href = "http://www.bingsolidaire.com/ressources/toolbar/bing_solidaire.xpi";
				else if (startingPage == "MSN")
					this.href = "http://www.bingsolidaire.com/ressources/toolbar/bing_solidaire.xpi";
			}
			else {
				this.href = "";
				$("div.popup-not-compatible").fadeIn(300);
				return false;
			}
			//return false;
		});
		
	}
	
	// Default search engine
	var $make_dft_search = $("#make-dft-search");
	if (HN.browser.msie) {
		$make_dft_search.click(function(){
			this.style.behavior = "url(#default#homepage)";
			this.setHomePage("http://www.bing.com/");
			return false;
		});
	}
	else {
		$make_dft_search.hide();
	}
	
	// Credits
	$("div.menu-bottom a.credits-link").click(function(){ $("div.credits").fadeIn(300); return false; })
	$("div.credits div.close").click(function(){ $("div.credits").fadeOut(300); })
	
	// Popup not compatible
	$("div.popup-not-compatible div.close").click(function(){ $("div.popup-not-compatible").fadeOut(300); })
}

HN.MS.Bing_solidaire.Inter = function () {
	var startingPage = "msn.fr";
	var charitableAssociation = "";
	var settings = cm.read("bingSolidaire");
	if (settings) {
		settings = settings.split("|");
		startingPage = settings[0];
		charitableAssociation = settings[1];
	}
	window.location.href = "http://dons.bingsolidaire.com/FinInstallation.jsp?startingPage="+startingPage+"&charitableAssociation="+charitableAssociation;
}

