/* function to show and hide the sign in pop up menu */
var blnTestParam = false;
$(document).ready(function() {
	//sma_TopMenuSmall_LoadImg();
	if(window.location.href.indexOf("smanutrition") == -1){
		
	}
	sma_MoveNavi();
	sma_SetPersonaCookie();
	sma_SetPersonaLinks();
	sma_evtSignIn();
	sma_SetRightNaviText();
	sma_SetRightNaviLinkHeight();
	sma_StagingModul();
	sma_SetLavaLamp();
	sma_socialBookmarkHover();
	sma_SetTabidCookie();
	sma_checkIEVersion();
	sma_SetSearchSubmit();
	sma_previewRVStoredKH();
	sma_SetBookmarksPosition();
	sma_Breadcrumb();
	sma_DevBack();
	//Start - important link
	if($("#ImportantLinks") != null){
		if($("#ImportantLinks").length != 0){
			intLinkTop = $("#ImportantLinks").offset().top;
			sma_evtShowHideImportantLinks();
			sma_evtWindowScroll();
			sma_WindowScroll();
		}
	}
	sma_HideBanner();
	//End - important link
	sma_SetSwoosh();

	// check which domain is used and change the header of the page
	if(sma_GetLocal() == "1"){
		//$("#BannerUKold").toggle();
		$("#BannerUK").toggle();
		$('.onlyShowOnUK').toggle();
	}
	else if(sma_GetLocal() == "2"){
		$("#BannerIE").toggle();
		// defines for ireland domains - each entry with a iphone promo is not shown on the page
		$('.onlyShowOnIE').toggle();
		// if the domain ie is used -> the iphone promo disappear on the homepage, landingpage, articlepage
		//$('#IPhonePromo').css('left','-280px');
		$('.landingSMACarelineContent').css('margin','0 0 0 80px');
	}
	//if the querystring contains key-value-pair "test=ok" and the user is on non prod system, the global var blnTestParam is set to ok. this can be used to test some moduls which can not be seen again after some action
	if(sma_GetQueryStr("test") == "ok" && window.location.href.indexOf("smanutrition") == -1 && window.location.href.indexOf("smahcp") == -1){
		blnTestParam = true;
	}
	
	
	var google_conversion_language = "";
	var google_conversion_format = "";
	var google_conversion_color = "";
	var google_conversion_label = "";
	var google_conversion_value = 0;
	
	sma_Conversion();

});
function sma_Conversion(){
	var strCatID = $.cookie("PersonaID");
	var blnExcl = false;
	if(sma_GetLocal() == 2){
		blnExcl = true;
	}
	if(typeof blnConvExcl != 'undefined'){
		if(blnConvExcl == true){
			blnExcl = true;
		}
	}
	if(blnExcl == false){
		switch(strCatID){
			case "13":
				google_conversion_id = 965128005;
				google_conversion_language = "en";
				google_conversion_format = "3";
				google_conversion_color = "666666";
				google_conversion_label = "NcDZCMuipgMQxd6azAM";
				google_conversion_value = 0;
				break;
			case "14":
				google_conversion_id = 965128005;
				google_conversion_language = "en";
				google_conversion_format = "3";
				google_conversion_color = "666666";
				google_conversion_label = "80Q1CIP9pwMQxd6azAM";
				google_conversion_value = 0;
				break;
			case "15":
				google_conversion_id = 965128005;
				google_conversion_language = "en";
				google_conversion_format = "3";
				google_conversion_color = "666666";
				google_conversion_label = "vJ8CCPv9pwMQxd6azAM";
				google_conversion_value = 0;
				break;
			case "16":
				google_conversion_id = 965128005;
				google_conversion_language = "en";
				google_conversion_format = "3";
				google_conversion_color = "666666";
				google_conversion_label = "0RxbCPP-pwMQxd6azAM";
				google_conversion_value = 0;
				break;
			case "17":
				google_conversion_id = 965128005;
				google_conversion_language = "en";
				google_conversion_format = "3";
				google_conversion_color = "666666";
				google_conversion_label = "rdalCOv_pwMQxd6azAM";
				google_conversion_value = 0;
				break;
			case "18":
				google_conversion_id = 965128005;
				google_conversion_language = "en";
				google_conversion_format = "3";
				google_conversion_color = "666666";
				google_conversion_label = "sxk4COOAqAMQxd6azAM";
				google_conversion_value = 0;
				break;
			default:
				blnExcl = true;
				break;
		}
	}
	if(blnExcl == false){
		var strHtml = '<div id="ConvTest" style="display:hidden;"></div>';
		$("body").append(strHtml);
		  
		var objScript = document.createElement('script');
		objScript.type = 'text/javascript';
		objScript.src = 'http://www.googleadservices.com/pagead/conversion.js';
		document.getElementById("ConvTest").appendChild(objScript);

		strHtml = '<noscript>';
		strHtml += '<div style="display:inline;">';
		strHtml += '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/965128005/?label=' + google_conversion_label + '&amp;guid=ON&amp;script=0"/>';
		strHtml += '</div>';
		strHtml += '</noscript>';
		strHtml += '</div>';
		$("#ConvTest").append(strHtml);
	}
}
//moves the navi to its parent cat
function sma_MoveNavi(){
	var blnFound = false;
	var strPath = window.location.href;
	if($("#KnowHowNaviGrey")){
		$("#KnowHowNaviGrey").attr("id","KnowHowNavi");
	}
	if($("#ResourceNaviBlue")){
		$("#ResourceNaviBlue").attr("id","ResourceNavi");
	}
	if($("#ProductNaviBlue")){
		$("#ProductNaviBlue").attr("id","ProductNavi");
	}

	if(strPath.indexOf("/know-how/") != -1){
		$("#MidNavi").insertAfter("#KnowHowNavi");
		$("#KnowHowNavi").attr("class","blue");
		$("#ResourceNavi").attr("class","grey");
		$("#ProductNavi").attr("class","grey");
		blnFound = true;
	}
	if(strPath.indexOf("/resources/") != -1 || strPath.indexOf("/resources-for-you/") != -1){
		$("#MidNavi").insertAfter("#ResourceNavi");
		$("#KnowHowNavi").attr("class","grey");
		$("#ResourceNavi").attr("class","blue");
		$("#ProductNavi").attr("class","grey");
		blnFound = true;
	}
	if(strPath.indexOf("/sma-products/") != -1){
		$("#MidNavi").insertAfter("#ProductNavi");
		$("#KnowHowNavi").attr("class","grey");
		$("#ResourceNavi").attr("class","grey");
		$("#ProductNavi").attr("class","blue");
		blnFound = true;
	}
	if(blnFound == false){
		$("#MidNavi").insertAfter("#ProductNavi");
		$("#KnowHowNavi").attr("class","grey");
		$("#ResourceNavi").attr("class","grey");
		$("#ProductNavi").attr("class","grey");
	}
	$("#MidNavi").toggle();
}

//sets the background of dev and sta
function sma_DevBack(){
	if(window.location.href.indexOf(".dev") != -1){
		$("body").css("background","url(/Portals/_default/Skins/SMA-Consumer/img/backDEV.jpg) repeat");
	}
	if(window.location.href.indexOf(".sta") != -1){
		$("body").css("background","url(/Portals/_default/Skins/SMA-Consumer/img/backSTA.jpg) repeat");
	}
}
//Gets the value from the given key of the querystring
function sma_GetQueryStr(strQueryString) {
	var strURL = window.location.search.substring(1);
	var arrKeys = strURL.split("&");
	var strReturn = "";
	for (i=0;i<arrKeys.length;i++) {
		var strKey = arrKeys[i].split("=");
		if (strKey[0] == strQueryString) {
			strReturn = strKey[1];
			continue;
		}
	}
	return strReturn;
}
// function which checks the actual domain
function sma_GetLocal(){
	var strLang = "";
	if(window.location.host.indexOf(".uk12") != -1 || window.location.host.indexOf(".co.uk") != -1){
		strLang = "1";
	}
	if(window.location.host.indexOf(".ie12") != -1 || window.location.host.indexOf(".ie") != -1){
		strLang = "2";
	}
	return strLang;
}

// function to show the text for every social bookmark
function sma_socialBookmarkHover(){
	$("#SocialFB").hover(function (){
		$("#SocialFB").append($("<span>Share on Facebook</span>"));
	  },
	  function () {
		$(this).find("span:last").remove();
	  }
	);
	$("#SocialTwitter").hover(function (){
		$("#SocialTwitter").append($("<span>Share on Twitter</span>"));
	  },
	  function () {
		$(this).find("span:last").remove();
	  }
	);
	$("#SocialDelicious").hover(function (){
		$("#SocialDelicious").append($("<span>Share on Delicious</span>"));
	  },
	  function () {
		$(this).find("span:last").remove();
	  }
	);
	$("#SocialBookmarkMe").hover(function (){
		$("#SocialBookmarkMe").append($("<span>Add to your bookmarks</span>"));
	  },
	  function () {
		$(this).find("span:last").remove();
	  }
	);
	$("#SocialMail").hover(function (){
		$("#SocialMail").append($("<span>Send an email</span>"));
	  },
	  function () {
		$(this).find("span:last").remove();
	  }
	);
}

function sma_evtSignIn(){
	$("#SignInUser").click(function () {
		if ($("#dnn_SignInPane").is(":hidden")) {
			$("#dnn_SignInPane").show();
			$("#UserProfileSignIn #SignInUser").css("background","url(/Portals/_default/Skins/SMA-Consumer/img/signInButtonActiv.png) no-repeat");
		} else {
			$("#dnn_SignInPane").hide();
			$("#UserProfileSignIn #SignInUser").css("background","url(/Portals/_default/Skins/SMA-Consumer/img/signInButton.png) no-repeat");
		}
	});
	if (document.getElementById('Successmessage')){
		$("#dnn_SignInPane").show();
		$("#UserProfileSignIn #SignInUser").css("background","url(/Portals/_default/Skins/SMA-Consumer/img/signInButtonActiv.png) no-repeat");
	}else{
		$("#dnn_SignInPane").hide();
		$("#UserProfileSignIn #SignInUser").css("background","url(/Portals/_default/Skins/SMA-Consumer/img/signInButton.png) no-repeat");
	}
	// $("body").click(function () {
	// if ($("#dnn_SignInPane").not(":hidden")&& document.getElementById('Successmessage')) {
		// $("#dnn_SignInPane").hide();
		// $("#UserProfileSignIn a").css("background","url(/Portals/_default/Skins/SMA/img/_signInButton.png) no-repeat");
	// }
	// });
}

/* Start - Functions for Staging Top Modul */
function sma_StagingModul(){

	sma_SetStageTitle();
	sma_evtStageClickNext();
	sma_evtStageClickPrev();
	sma_LinkStageImage();
}
/* function to show the title at the stage control by load a specific landing page */
function sma_SetStageTitle(){
	var strTitleStage;
	var newCls;
	
	$(".topMenu_small li").each(function(){
		newCls = $(this).attr("id");
	
		if(newCls.indexOf("_on") != -1)
		{
			sma_setCookies(newCls.replace("_on", ""));
		}
	});

	strTitleStage = $.cookie("StageTitle");
	$('#TitleStage').text(strTitleStage);
	if($.cookie("StageImage") != null){
		$('#SelectedStage').attr("src",$.cookie("StageImage"));
	}
	else{
		$('#SelectedStage').attr("src","/Portals/_default/Skins/SMA-Consumer/img/null.gif");
	}
}

// function to change the catid to specific ids. this ids updates the cookies
function sma_MappingCatId(tmpStageId){
	switch(tmpStageId){
		case 13:
			tmpStageId = "TM1";
			break;
		case 14:
			tmpStageId = "TM2";
			break;
		case 15:
			tmpStageId = "TM3";
			break;
		case 16:
			tmpStageId = "TM4";
			break;
		case 17:
			tmpStageId = "TM5";
			break;
		case 18:
			tmpStageId = "TM6";
			break;
	}
	sma_setCookies(tmpStageId);
}

// function to set a link on the product page stage control to navigate directly to the know-how page
function sma_LinkStageImage(){
	if ($('ul#TopMenuProd').length){}
		//var strURLKnowHow = $("#KnowHowNaviGrey a").attr("href");
		var strURLKnowHow = sma_GetPersonaLinks("Persona");

		$("#LinkStage").attr("href",strURLKnowHow);
		
		var arrTmp = strURLKnowHow.split("?");
		var arrGetParam = arrTmp[1].split("&");
		var arrTabId = arrGetParam[0].split("=");
		
		//if no stage is selected		
		if(arrGetParam.length > 1){
			var arrCatId = arrGetParam[1].split("=");
			
			$("#NextStage").click(function(){
				if (arrTabId[1] < 1227 || arrCatId[1] < 18){
					arrTabId[1]++;
					arrCatId[1]++;
				}else{
					arrTabId[1] = 1222;
					arrCatId[1] = 13;
				}
				$("#NextStage").attr("href",arrTmp[0]+"?"+arrTabId[0]+"="+arrTabId[1]+"&"+arrCatId[0]+"="+arrCatId[1]);
				sma_MappingCatId(arrCatId[1]);
			});
			
			$("#PrevStage").click(function(){
				if (arrTabId[1] > 1222 || arrCatId[1] > 13){
					arrTabId[1]--;
					arrCatId[1]--;
				}else{
					arrTabId[1] = 1227;
					arrCatId[1] = 18;
				}
				$("#PrevStage").attr("href",arrTmp[0]+"?"+arrTabId[0]+"="+arrTabId[1]+"&"+arrCatId[0]+"="+arrCatId[1]);
				sma_MappingCatId(arrCatId[1]);
			});
		}
	
}
/* function to switch forward in the stagecontrol panel of the header.  */
function sma_evtStageClickNext(){
	$("a#NextStage").click(function(){
		$(".topMenu_small li").each(function(){
			var newCls = $(this).attr("id");
			if(newCls.indexOf("_on") != -1)
			{
				var arrStage = newCls.split("_");
				var intStage = arrStage[0].substring("2");
				if (intStage < '6'){
					intStage++;
					var strLinkStage = $("#TM"+intStage+" a").attr("href");
					$("a#NextStage").attr("href",strLinkStage);
				}else{
					intStage = 1;
					var strLinkStage = $("#TM"+intStage+" a").attr("href");
					$("a#NextStage").attr("href",strLinkStage);
				}
				sma_setCookies("TM"+intStage);
			}
		}); 	
	});
}
/* function to switch back in the stagecontrol panel of the header.  */
function sma_evtStageClickPrev(){
	$("a#PrevStage").click(function(){
		$(".topMenu_small li").each(function(){
			var newCls = $(this).attr("id");
			if(newCls.indexOf("_on") != -1)
			{
				var arrStage = newCls.split("_");
				var intStage = arrStage[0].substring("2");
				if (intStage > '1'){
					intStage--;
					var strLinkStage = $("#TM"+intStage+" a").attr("href");
					$("a#PrevStage").attr("href",strLinkStage);
				}else{
					intStage = 6;
					var strLinkStage = $("#TM"+intStage+" a").attr("href");
					$("a#PrevStage").attr("href",strLinkStage);
				}
				sma_setCookies("TM"+intStage);
			}
		}); 	
	});
}
/* End - Functions for Staging Top Modul */

// Section to define the right Helpsheets title in the content navi menu on the right side. the original page title will be overwritten
function sma_SetRightNaviText(){
	if ($('#0_06HelpsheetConstipation').length){
		$('#0_06HelpsheetConstipation .MenuInnerContainer span').text('0 - 6 Months');
	}
	if ($('#0_612HelpsheetConstipation').length){
		$('#0_612HelpsheetConstipation .MenuInnerContainer span').text('6 - 12 Months');
	}
	if ($('#0_12HelpsheetConstipation').length){
		$('#0_12HelpsheetConstipation .MenuInnerContainer span').text('12 Months');
	}
	if ($('#0_06HelpsheetDiarrhoea').length){
		$('#0_06HelpsheetDiarrhoea .MenuInnerContainer span').text('0 - 6 Months');
	}
	if ($('#0_612HelpsheetDiarrhoea').length){
		$('#0_612HelpsheetDiarrhoea .MenuInnerContainer span').text('6 - 12 Months');
	}
	if ($('#0_12HelpsheetDiarrhoea').length){
		$('#0_12HelpsheetDiarrhoea .MenuInnerContainer span').text('12 Months');
	}
	if ($('#0_HelpsheetPortionGuide').length){
		$('#0_HelpsheetPortionGuide .MenuInnerContainer span').text('Portion Guide');
	}
	if ($('#0_HelpsheetSugar').length){
		$('#0_HelpsheetSugar .MenuInnerContainer span').text('Sugar');
	}
	if ($('#0_HelpsheetNutrition').length){
		$('#0_HelpsheetNutrition .MenuInnerContainer span').text('Nutrition');
	}
	if ($('#0_HelpsheetAntenatalScans').length){
		$('#0_HelpsheetAntenatalScans .MenuInnerContainer span').text('Antenatal scans');
	}
	if ($('#0_HelpsheetUnderstanding').length){
		$('#0_HelpsheetUnderstanding .MenuInnerContainer span').text('Maternity notes');
	}
	if ($('#0_HelpsheetVaccinations').length){
		$('#0_HelpsheetVaccinations .MenuInnerContainer span').text('Vaccinations');
	}
	if ($('#0_HelpsheetMaternity').length){
		$('#0_HelpsheetMaternity .MenuInnerContainer span').text('Maternity rights');
	}
	if ($('#0_HelpsheetBackToWork').length){
		$('#0_HelpsheetBackToWork .MenuInnerContainer span').text('Back to work');
	}
	if ($('#0_HelpsheetRestRelaxation').length){
		$('#0_HelpsheetRestRelaxation .MenuInnerContainer span').text('Rest and Relaxation');
	}
	if ($('#0_HelpsheetRestSleep').length){
		$('#0_HelpsheetRestSleep .MenuInnerContainer span').text('Rest and Sleep');
	}
	if ($('#0_ComparisonFIM').length){
		$('#0_ComparisonFIM .MenuInnerContainer span').text('Comparison');
	}
	if ($('#0_Milk_intolerant_allergic_baby').length){
		$('#0_Milk_intolerant_allergic_baby .MenuInnerContainer span').text('Milk intolerant / allergic baby');
	}
	
	if($('ul#menu').length){
		/* dynamically set the title and subtitle of the midnavi menu on the right side of a article page */
		if($('.titleArticle').length){
			var tmpTitlePage = $('.titleArticle h1').html();
			var titlePage = tmpTitlePage.replace(/&amp;/g, "&");
			$('#0_Video .MenuInnerContainer a').append('<div></div>');
			$('#0_Video .MenuInnerContainer div').text(titlePage);
			
			// special cases if more than one video is shown per article
			if ($('#0_VideoBathing').length){
				$('#0_VideoBathing .MenuInnerContainer span').text('Video');
				$('#0_VideoBathing .MenuInnerContainer a').append('<div></div>');
				$('#0_VideoBathing .MenuInnerContainer div').text('Bathing');
			}
			if ($('#0_VideoTopsTails').length){
				$('#0_VideoTopsTails .MenuInnerContainer span').text('Video');
				$('#0_VideoTopsTails .MenuInnerContainer a').append('<div></div>');
				$('#0_VideoTopsTails .MenuInnerContainer div').text('Tops and Tails');
			}
		}
	}
}
/* sets the height for span according to the backround-image, so the whole div is clickable instead of only the a(anchor) */
function sma_SetRightNaviLinkHeight(){
	$("#menu li .MenuInnerContainer a span").each(function () {
	  var strHeight = $(this).parent().parent().height()+"px;";
	  $(this).attr("style", "height:"+strHeight);
	});
}
/*Start -- set Persona Cookie OnClick */
function sma_SetPersonaCookie(){
	var objMenu = null;
	var strID = "";
	
	if($("#TopMenu").length){
		objMenu = $("#TopMenu li");
	}
	if($("#TopMenuHP").length){
		objMenu = $("#TopMenuHP li");
	}
	if(objMenu != null){
		objMenu.click(
			function(){
				strID = $(this).attr("id");
				if(strID.indexOf("_on") != -1){
					strID = strID.replace("_on", "");
				}
				sma_setCookies(strID);
			}
		); 
	}
}

function sma_SetTabidCookie(){
	var objMenu = null;
	var objNavi = null;
	var objContentNavi = null;
	var strID = "";
	var strTabLink = "";
	//$.cookie("smaTabId","", { path: '/' })
//alert($.cookie("smaTabId"));
	if($("#TopMenu").length){
		objMenu = $("#TopMenu li");
		objNavi = $("#MidNavi li");
		objContentNavi = $("#contentNav li");
	}
	if($("#TopMenuProd").length){
		objMenu = $("#TopMenuProd li");
		objNavi = $("#MidNavi li");
		objContentNavi = $("#contentNav li");
	}
	if(objMenu != null && objNavi != null){
		
		objMenu.click(
			function(){
				strID = $(this).attr("id");
				if(strID.indexOf("_on") != -1){
					strID = strID.replace("_on", "");
				}
				strID = sma_GetPageValues(strID,"smaTabId");
				sma_ComputeCookieString(strID, 2);
			}
		); 
		objNavi.click(
			function(){
				strTabLink = $(this).children("a").attr("href");
				sma_ComputeCookieString(strTabLink, 1);
			}
		); 
		objContentNavi.click(
			function(){
				strTabLink = $(this).children(".MenuOuterContainer").children(".MenuInnerContainer").children("a").attr("href");
				sma_ComputeCookieString(strTabLink, 1);
			}
		);
	}
	sma_ComputeCookieString("","")
}
/* this function is called from the Login Modul */
function sma_GetUrlForRedirect(){
	var objMenu = null;
	var objNavi = null;
	var objContentNavi = null;

	if($("#TopMenu").length){
		objMenu = $("#TopMenu li");
		objNavi = $("#MidNavi li");
		objContentNavi = $("#contentNav li");
	}
	if($("#TopMenuProd").length){
		objMenu = $("#TopMenuProd li");
		objNavi = $("#MidNavi li");
		objContentNavi = $("#contentNav li");
	}
	if(objMenu != null){
		objMenu.each(function(){
			strID = $(this).attr("id");
			if(strID.indexOf("_on") != -1){
				strID = strID.replace("_on", "");
				strID = sma_GetPageValues(strID,"smaTabId");
			}
			sma_ComputeCookieString(strID, 2);
		});
	}
	else{
		sma_ComputeCookieString("", 2);
	}
		strTabLink = location.href;
		sma_ComputeCookieString(strTabLink, 1);
}
function sma_ComputeCookieString(_strLink, _intType){
	var strCookieVal1 = "";
	var strCookieVal2 = "";
	var strCookieVal3 = "";
	var strSMACookie = "";

	if($.cookie("smaTabId") == null){
		strSMACookie = "/default.aspx" + "|" + "/default.aspx" + "|";
	}
	if($.cookie("smaTabId") != null){
		strCookieVal1 = $.cookie("smaTabId").slice(0,$.cookie("smaTabId").indexOf("|"));
		strCookieVal2 = $.cookie("smaTabId").slice($.cookie("smaTabId").indexOf("|")+1,$.cookie("smaTabId").lastIndexOf("|"));
		strCookieVal3 = $.cookie("smaTabId").slice($.cookie("smaTabId").lastIndexOf("|")+1,$.cookie("smaTabId").length);
		if(_intType == 1){
			strCookieVal2 = _strLink;
		}
		if(_intType == 2){
			strCookieVal3 = _strLink;
		}
		strCookieVal1 = strCookieVal2 + "?catid=" + strCookieVal3;
		strSMACookie = strCookieVal1 + "|" + strCookieVal2 + "|" + strCookieVal3;
	}	
	sma_SetCookieTabID(strSMACookie);
}
function sma_SetCookieTabID(_strCookieVal){
	$.cookie("smaTabId", _strCookieVal, { path: '/' });
}
function sma_GetCookieTest(){
	alert($.cookie("PersonaID"));
}
// function to update the cookies by changing the stage
function sma_setCookies(_strID){
	$.cookie("PersonaID", sma_GetPageValues(_strID,"PersonaID"), { path: '/' });
	$.cookie("StageTitle", sma_GetPageValues(_strID,"StageTitle"), { path: '/' });
	$.cookie("StageImage", sma_GetPageValues(_strID,"StageImage"), { path: '/' });
}
function sma_GetPageValues(_strCatID,_strReturnValue){
	var strID = "";
	var strStageTitle = "";
	var strImgStage = "";
	var strReturn = "";
	
	switch(_strCatID){
		case "TM1":
			strID = "13";
			strStageTitle = "Early Pregnancy";
			strImgStage = "/Portals/_default/Skins/SMA-Consumer/img/menu/TM1_on.jpg";
			break;
		case "TM2":
			strID = "14";
			strStageTitle = "Later Pregnancy";
			strImgStage = "/Portals/_default/Skins/SMA-Consumer/img/menu/TM2_on.jpg";
			break;
		case "TM3":
			strID = "15";
			strStageTitle = "New Mum";
			strImgStage = "/Portals/_default/Skins/SMA-Consumer/img/menu/TM3_on.jpg";
			break;
		case "TM4":
			strID = "16";
			strStageTitle = "Baby";
			strImgStage = "/Portals/_default/Skins/SMA-Consumer/img/menu/TM4_on.jpg";
			break;
		case "TM5":
			strID = "17";
			strStageTitle = "Weaning";
			strImgStage = "/Portals/_default/Skins/SMA-Consumer/img/menu/TM5_on.jpg";
			break;
		case "TM6":
			strID = "18";
			strStageTitle = "Toddler";
			strImgStage = "/Portals/_default/Skins/SMA-Consumer/img/menu/TM6_on.jpg";
			break;
		case "TMProd1":
			strID = "19";
			break;
		case "TMProd2":
			strID = "20";
			break;
		case "TMProd3":
			strID = "21";
			break;
	}
	
	switch(_strReturnValue){
		case "PersonaID":
			strReturn = strID;
			break;
		case "StageTitle":
			strReturn = strStageTitle;
			break;
		case "StageImage":
			strReturn = strImgStage;
			break;
		case "smaTabId":
			strReturn = strID;
			break;
	}
	
	return strReturn;
}
/*End -- set Persona Cookie OnClick */
/*Start -- Changes the KnowHowLink and the LogoLink depending on the selected Stage --> important for the ProductPages */
function sma_SetPersonaLinks(){
	var strNewKnowHowLink = sma_GetPersonaLinks("Persona");
	var strNewLogoLink = sma_GetPersonaLinks("Logo");
	
	if($("#KnowHowNaviGrey").length){
		$("#KnowHowNaviGrey a").attr("href",strNewKnowHowLink);
	}
	if($("#KnowHowNavi").length){
		$("#KnowHowNavi a").attr("href",strNewKnowHowLink);
	}
	$("#TopLogoLink").attr("href",strNewLogoLink);
}
function sma_GetPersonaLinks(strLinkType){
	var strTabId = "";
	var strNewKnowHowLink = "";
	var strNewLogoLink = "";
	var strPersonaID = $.cookie("PersonaID");
	switch(strPersonaID){
		case "13":
			strTabId = "1222";
			break;
		case "14":
			strTabId = "1223";
			break;
		case "15":
			strTabId = "1224";
			break;
		case "16":
			strTabId = "1225";
			break;
		case "17":
			strTabId = "1226";
			break;
		case "18":
			strTabId = "1227";
			break;			
	}

	if (strPersonaID == null){
		strNewKnowHowLink = '/default.aspx?TabId=1222&catid=13';
		strNewLogoLink = '/default.aspx';
	}else{
		strNewKnowHowLink = '/default.aspx?TabId=' + strTabId + '&catid=' + strPersonaID;
		strNewLogoLink = '/default.aspx?catid=' + strPersonaID;
	}
	
	var strReturn = "";
	if(strLinkType == "Logo"){
		strReturn = strNewLogoLink;
	}
	if(strLinkType == "Persona"){
		strReturn = strNewKnowHowLink;
	}
	return strReturn;
}
/*End -- Changes the KnowHowLink and the LogoLink depending on the selected Stage --> important for the ProductPages */
/* Start - Set LavaLamp */
function sma_SetLavaLamp(){
	/*if($('ul#menu').length){
		$("ul#menu li").each(function(){
			newCls = $(this).attr("id");
			if(newCls.indexOf("_on") != -1){
				newCls = newCls.substring(2,3);
				newCls -= 1;
				$('ul#menu').lavaLamp({startItem:newCls,speed:400});
			}
		});
	}*/
	if($('ul#menu').length){
		var i = 0;
		$("ul#menu li").each(function(){
			newCls = $(this).attr("class");
			newCls = newCls + "_" + i;
			i++;
			if (newCls.indexOf("activeitem") != -1){
				newCls = newCls.charAt(newCls.length - 1);
				$('ul#menu').lavaLamp({startItem:newCls, speed:400});
			}
		});
	}
	if($('ul#TopMenu').length){
		$(".topMenu_small li").each(function(){
			newCls = $(this).attr("id");
			if(newCls.indexOf("_on") != -1){
				newCls = newCls.substring(2,3);
				newCls -= 1;
				$('ul#TopMenu').lavaLamp({startItem:newCls,speed:400});
			}
		});
	}
	if($('ul#TopMenuProd').length){
		$(".topMenuProd_small li").each(function(){
			newCls = $(this).attr("id");
			if(newCls.indexOf("_on") != -1){
				newCls = newCls.substring(2,3);
				newCls -= 1;
				$('ul#TopMenuProd').lavaLamp({startItem:newCls,speed:400});
			}
		});
	}
}
/* End - Set LavaLamp */
/* Start - Set TopMenuSmall */
function sma_TopMenuSmall_LoadImg(){
	if($(".topMenu_small").length){
		$(".topMenu_small li").each(function(){
			newCls = $(this).attr("id");
			var intNmb = newCls.replace("TM","");
			if(newCls.indexOf("_on") != -1)
			{
				$(this).children().html("<span><img src='/Portals/_default/Skins/SMA-Consumer/img/menu/MImg" + intNmb + ".jpg'/></span>");
			}
			else{
				$(this).children().html("<span><img src='/Portals/_default/Skins/SMA-Consumer/img/menu/MImg" + intNmb + "_off.jpg'/></span>");
			}
		});
	}
}
/* End - Set TopMenuSmall */
/* Start - Browser Check */
function sma_getInternetExplorerVersion(){
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer'){
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function sma_checkIEVersion(){
  var msg = "You're not using Internet Explorer.";
  var ver = sma_getInternetExplorerVersion();
  if ( ver > -1 )  {
    if ( ver <= 6 ) {
      $('body').prepend('<br/><div style="margin: 0 auto;padding:0; position: relative;width: 1000px;"><div style="background-color: #FFFFFF; margin: 0 auto 30px; padding: 20px 20px 20px 20px; width: 1000px;"><h4 class="pinkText">Your are using an old browser, which is not supported. Please consider to update to the newest version.</h4></div></div>')
	}
  }
}
/* End - Browser Check */
function sma_SetSearchSubmit(){
	$("#dnn_SearchInput1_linkSearch").attr("href","javascript:sma_SearchTest()");
	
}
function sma_SearchTest(){
__doPostBack('dnn$SearchInput1$linkSearch','');
}
// function to devide the title of the last pages to fit in the recently viewed and stored know how teaser box. 
function sma_previewRVStoredKH(){
	$('#TableRecentlyViewContent li a').each(function(){sma_CutTitle(this,140)});
	$('#HelloUser').each(function(){sma_CutTitle(this,120)});
	$('#NotYourName').each(function(){sma_CutTitle(this,100)});
}
function sma_CutTitle(objCurrent,intWidth){
		/*
		var tmp = $(objCurrent).html();
		var tmpTitle = tmp.split(" - ");
		$(objCurrent).html(tmpTitle[0]);

		if(tmpTitle.length > 1 || tmpTitle[0].length > 22 ){
			$(objCurrent).html(tmpTitle[0].substr(tmpTitle[0],20) + " ...");
		}
		$(objCurrent).html(tmpTitle[0])
		*/
		$(objCurrent).shorten({ width: intWidth, tail: ' ...'});
		$(objCurrent).css({'display' : 'inline', 'visibility' : 'visible', 'white-space':'nowrap'});
}
//Sets the Bookmarks-CSS-Position to absolute if width is to small, otherwise it Social-Bookmarks are not shown
function sma_SetBookmarksPosition(){
	if($(document).width() <= 1060){
		if($("#Social") != null){
			$("#Social").css("position","absolute");
		}
	}
}
//Start - important link
function sma_evtShowHideImportantLinks(){
	$('#ImportantLinks h4').click(function(){
		var strSrc = $('#ImportantLinks').attr('status');
		$('#AdditionalLinks').toggle('fast',sma_WindowScroll);
	});
}
function sma_evtWindowScroll(){
$(window).scroll(sma_WindowScroll);
}
function sma_WindowScroll2(){
	var intLinkHeight = $("#ImportantLinks").height();
	var intDocTop = $(document).scrollTop();
	
	var intConHeight = $("#MidContentTopLeftCon").height();
	var intConTop = $("#MidContentTopLeftCon").position().top;
	
	var intNaviHeight = $("#MidContentTopRightCon").height();
	if(intConHeight<intNaviHeight+intLinkHeight){
		$("#MidContentTopLeftCon").height(intNaviHeight+intLinkHeight+20);
	}
	if(intDocTop >= intLinkTop){
		$("#ImportantLinks").css({"position":"fixed","top":"10px"});
	}
	if(intDocTop < intLinkTop){
		$("#ImportantLinks").css({"position":"","top":""});
	}
	if(intDocTop + intLinkHeight> intConHeight +  intConTop){
		$("#ImportantLinks").css({"position":"absolute","top":intConHeight +  intConTop-intLinkHeight});
	}

	//console.debug(intLinkHeight + " " + intLinkTop  + " " +intDocTop + " " +intConHeight +" "+intConTop +" "+intNaviHeight);
	
}
function sma_WindowScroll(){
	var intLinkHeight = $("#ImportantLinks").height();
	var intDocTop = $(document).scrollTop();
	
	var intConHeight = $("#MidContentTopCon").height();
	var intConTop = $("#MidContentTopLeftCon").position().top;
	
	var intNaviHeight = $("#MidContentTopRightCon").height();

	if(intDocTop >= intLinkTop){
		$("#ImportantLinks").css({"position":"fixed","top":"10px"});
	}
	if(intDocTop < intLinkTop){
		$("#ImportantLinks").css({"position":"","top":""});
	}
	if(intDocTop + intLinkHeight> intConHeight +  intConTop){
		$("#ImportantLinks").css({"position":"absolute","top":intConHeight +  intConTop-intLinkHeight});
	}

	//console.debug(intLinkHeight + " " + intLinkTop  + " " +intDocTop + " " +intConHeight +" "+intConTop +" "+intNaviHeight);
	
}
//End - important link

// function to show the correct page name in the breadcrumb - this happens if there are more than one video or helpsheet is on a article page
function sma_Breadcrumb(){
	if ($('.SkinObject').text().indexOf('Helpsheet') != -1){
		$('.SkinObject:last').html('Helpsheet');
	}
	if ($('.SkinObject').text().indexOf('Video') != -1){
		$('.SkinObject:last').html('Video');
	}
}
//this function is used to unhide the banner, if we are not on a legalnotice page
function sma_HideBanner(){
			if($("#BannerHide").length == 0){
				$("#TopMiddle").show();
			}
}
function sma_SetSwoosh(){
	var objMenu = null;
	var strID = "";
	
	if($("#TopMenuProd").length){
		objMenu = $("#TopMenuProd li");
	}
	if(objMenu != null){
		objMenu.each(
			function(){
				strID = $(this).attr("id");
				if(strID.indexOf("_on") != -1){
					strID = strID.replace("_on", "");
					switch(strID){
						case "TM1Prod":
							$("#FooterContainer").attr("class","");
							break;
						case "TM2Prod":
							$("#FooterContainer").attr("class","swooshYellow");
							break;
						case "TM3Prod":
							$("#FooterContainer").attr("class","swooshRed");
							break;
						case "TM4Prod":
							$("#FooterContainer").attr("class","swooshGreen");
							break;
						case "TM5Prod":
							$("#FooterContainer").attr("class","swooshBlue");
							break;
					}
				}
			}
		); 
	}
}
