
/* function to show and hide the sign in pop up menu */
 var $jq = jQuery.noConflict();  
$jq(document).ready(function() {
	//sma_TopMenuSmall_LoadImg();
	sma_SetPersonaCookie();
	sma_SetPersonaLinks();
	sma_evtSignIn();
	sma_SetRightNaviText();
	sma_SetRightNaviLinkHeight();
	sma_StagingModul();
	sma_SetLavaLamp();
	sma_socialBookmarkHover();
	sma_SetTabidCookie();
	sma_checkIEVersion();
	sma_SetSearchSubmit();
	sma_showHideKnowHow();
	sma_previewRVStoredKH();
	sma_RatingOnStart();
	sma_OrderLitSetStyles();
	sma_SetBookmarksPosition();
	sma_Breadcrumb();
	sma_PageFlip();
});
//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 to show the text for every social bookmark
function sma_socialBookmarkHover(){
	$jq(".addKnowHow").hover(function (){
		$jq(".addKnowHow").append($jq("<span id='AddKH'>Add Page to My Know-how</span>"));
	  },
	  function () {
		$jq(this).find("span").remove();
	  }
	);
	$jq(".removeKnowHow").hover(function (){
		$jq(".removeKnowHow").append($jq("<span id='RemoveKH'>Remove Page from My Know-how</span>"));
	  },
	  function () {
		$jq(this).find("span").remove();
	  }
	);
	$jq("#SocialFB").hover(function (){
		$jq("#SocialFB").append($jq("<span>Share on Facebook</span>"));
	  },
	  function () {
		$jq(this).find("span:last").remove();
	  }
	);
	$jq("#SocialTwitter").hover(function (){
		$jq("#SocialTwitter").append($jq("<span>Share on Twitter</span>"));
	  },
	  function () {
		$jq(this).find("span:last").remove();
	  }
	);
	$jq("#SocialDelicious").hover(function (){
		$jq("#SocialDelicious").append($jq("<span>Share on Delicious</span>"));
	  },
	  function () {
		$jq(this).find("span:last").remove();
	  }
	);
	$jq("#SocialBookmarkMe").hover(function (){
		$jq("#SocialBookmarkMe").append($jq("<span>Add to your bookmarks</span>"));
	  },
	  function () {
		$jq(this).find("span:last").remove();
	  }
	);
	$jq("#SocialMail").hover(function (){
		$jq("#SocialMail").append($jq("<span>Send an email</span>"));
	  },
	  function () {
		$jq(this).find("span:last").remove();
	  }
	);
}

function sma_evtSignIn(){
	$jq("#SignInUser").click(function () {
		if ($jq("#dnn_SignInPane").is(":hidden")) {
			$jq("#dnn_SignInPane").show();
			$jq("#UserProfileSignIn a").css("background","url(/Portals/_default/Skins/SMA-Professional/img/signInButtonActiv.png) no-repeat");
		} else {
			$jq("#dnn_SignInPane").hide();
			$jq("#UserProfileSignIn a").css("background","url(/Portals/_default/Skins/SMA-Professional/img/signInButton.png) no-repeat");
		}
	});
	if (document.getElementById('Successmessage')){
		$jq("#dnn_SignInPane").show();
		$jq("#UserProfileSignIn a").css("background","url(/Portals/_default/Skins/SMA-Professional/img/signInButtonActiv.png) no-repeat");
	}else{
		$jq("#dnn_SignInPane").hide();
		$jq("#UserProfileSignIn a").css("background","url(/Portals/_default/Skins/SMA-Professional/img/signInButton.png) no-repeat");
	}
	// $jq("body").click(function () {
	// if ($jq("#dnn_SignInPane").not(":hidden")&& document.getElementById('Successmessage')) {
		// $jq("#dnn_SignInPane").hide();
		// $jq("#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;
	
	$jq(".topMenu_small li").each(function(){
		newCls = $jq(this).attr("id");
	
		if(newCls.indexOf("_on") != -1)
		{
			sma_setCookies(newCls.replace("_on", ""));
		}
	});

	strTitleStage = $jq.cookie("StageTitle");
	$jq('#TitleStage').text(strTitleStage);
	if($jq.cookie("StageImage") != null){
		$jq('#SelectedStage').attr("src",$jq.cookie("StageImage"));
	}
	else{
		$jq('#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 22:
			tmpStageId = "TM1";
			break;
		case 23:
			tmpStageId = "TM2";
			break;
		case 24:
			tmpStageId = "TM3";
			break;
		case 25:
			tmpStageId = "TM4";
			break;
		case 26:
			tmpStageId = "TM5";
			break;
		case 27:
			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 ($jq('ul#TopMenuProd').length){}
		//var strURLKnowHow = $jq("#KnowHowNaviGrey a").attr("href");
		var strURLKnowHow = sma_GetPersonaLinks("Persona");

		$jq("#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("=");
			
			$jq("#NextStage").click(function(){
				if (arrTabId[1] < 1282 || arrCatId[1] < 27){
					arrTabId[1]++;
					arrCatId[1]++;
				}else{
					arrTabId[1] = 1277;
					arrCatId[1] = 22;
				}
				$jq("#NextStage").attr("href",arrTmp[0]+"?"+arrTabId[0]+"="+arrTabId[1]+"&"+arrCatId[0]+"="+arrCatId[1]);
				sma_MappingCatId(arrCatId[1]);
			});
			
			$jq("#PrevStage").click(function(){
				if (arrTabId[1] > 1277 || arrCatId[1] > 22){
					arrTabId[1]--;
					arrCatId[1]--;
				}else{
					arrTabId[1] = 1282;
					arrCatId[1] = 27;
				}
				$jq("#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(){
	$jq("a#NextStage").click(function(){
		$jq(".topMenu_small li").each(function(){
			var newCls = $jq(this).attr("id");
			if(newCls.indexOf("_on") != -1)
			{
				var arrStage = newCls.split("_");
				var intStage = arrStage[0].substring("2");
				if (intStage < '6'){
					intStage++;
					var strLinkStage = $jq("#TM"+intStage+" a").attr("href");
					$jq("a#NextStage").attr("href",strLinkStage);
				}else{
					intStage = 1;
					var strLinkStage = $jq("#TM"+intStage+" a").attr("href");
					$jq("a#NextStage").attr("href",strLinkStage);
				}
				sma_setCookies("TM"+intStage);
			}
		}); 	
	});
}
/* function to switch back in the stagecontrol panel of the header.  */
function sma_evtStageClickPrev(){
	$jq("a#PrevStage").click(function(){
		$jq(".topMenu_small li").each(function(){
			var newCls = $jq(this).attr("id");
			if(newCls.indexOf("_on") != -1)
			{
				var arrStage = newCls.split("_");
				var intStage = arrStage[0].substring("2");
				if (intStage > '1'){
					intStage--;
					var strLinkStage = $jq("#TM"+intStage+" a").attr("href");
					$jq("a#PrevStage").attr("href",strLinkStage);
				}else{
					intStage = 6;
					var strLinkStage = $jq("#TM"+intStage+" a").attr("href");
					$jq("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 ($jq('#0_06HelpsheetConstipation').length){
		$jq('#0_06HelpsheetConstipation .MenuInnerContainer span').text('0 - 6 Months');
	}
	if ($jq('#0_612HelpsheetConstipation').length){
		$jq('#0_612HelpsheetConstipation .MenuInnerContainer span').text('6 - 12 Months');
	}
	if ($jq('#0_12HelpsheetConstipation').length){
		$jq('#0_12HelpsheetConstipation .MenuInnerContainer span').text('12 Months');
	}
	if ($jq('#0_06HelpsheetDiarrhoea').length){
		$jq('#0_06HelpsheetDiarrhoea .MenuInnerContainer span').text('0 - 6 Months');
	}
	if ($jq('#0_612HelpsheetDiarrhoea').length){
		$jq('#0_612HelpsheetDiarrhoea .MenuInnerContainer span').text('6 - 12 Months');
	}
	if ($jq('#0_12HelpsheetDiarrhoea').length){
		$jq('#0_12HelpsheetDiarrhoea .MenuInnerContainer span').text('12 Months');
	}
	if ($jq('#0_PortionGuide').length){
		$jq('#0_PortionGuide .MenuInnerContainer span').text('Portion Guide');
	}
	if ($jq('#0_Sugar').length){
		$jq('#0_Sugar .MenuInnerContainer span').text('Sugar');
	}
	if ($jq('#0_Nutrition').length){
		$jq('#0_Nutrition .MenuInnerContainer span').text('Nutrition');
	}
	if ($jq('#0_ProductBooklet').length){
		$jq('#0_ProductBooklet .MenuInnerContainer span').text('New Formula');
	}
	if ($jq('#0_ComparisonFIM').length){
		$jq('#0_ComparisonFIM .MenuInnerContainer span').text('Comparison');
	}
	
	if($jq('ul#menu').length){
		/* dynamically set the title and subtitle of the midnavi menu on the right side of a article page */
		if($jq('.titleArticle').length){
			var tmpTitlePage = $jq('.titleArticle h1').html();
			var titlePage = tmpTitlePage.replace(/&amp;/g, "&");
			$jq('#0_Video .MenuInnerContainer a').append('<div></div>');
			$jq('#0_Video .MenuInnerContainer div').text(titlePage);
			
			// special cases if more than one video is shown per article
			if ($jq('#0_VideoBathing').length){
				$jq('#0_VideoBathing .MenuInnerContainer span').text('Video');
				$jq('#0_VideoBathing .MenuInnerContainer a').append('<div></div>');
				$jq('#0_VideoBathing .MenuInnerContainer div').text('Bathing');
			}
			if ($jq('#0_VideoTopsTails').length){
				$jq('#0_VideoTopsTails .MenuInnerContainer span').text('Video');
				$jq('#0_VideoTopsTails .MenuInnerContainer a').append('<div></div>');
				$jq('#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(){
	$jq("#menu li .MenuInnerContainer a span").each(function () {
	  var strHeight = $jq(this).parent().parent().height()+"px;";
	  $jq(this).attr("style", "height:"+strHeight);
	});
}
/*Start -- set Persona Cookie OnClick */
function sma_SetPersonaCookie(){
	var objMenu = null;
	var strID = "";
	
	if($jq("#TopMenu").length){
		objMenu = $jq("#TopMenu li");
	}
	if($jq("#TopMenuHP").length){
		objMenu = $jq("#TopMenuHP li");
	}
	if(objMenu != null){
		objMenu.click(
			function(){
				strID = $jq(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 = "";
	//$jq.cookie("smaTabId","", { path: '/' })
//alert($jq.cookie("smaTabId"));
	if($jq("#TopMenu").length){
		objMenu = $jq("#TopMenu li");
		objNavi = $jq("#MidNavi li");
		objContentNavi = $jq("#contentNav li");
	}
	if($jq("#TopMenuProd").length){
		objMenu = $jq("#TopMenuProd li");
		objNavi = $jq("#MidNavi li");
		objContentNavi = $jq("#contentNav li");
	}
	if(objMenu != null && objNavi != null){
		
		objMenu.click(
			function(){
				strID = $jq(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 = $jq(this).children("a").attr("href");
				sma_ComputeCookieString(strTabLink, 1);
			}
		); 
		objContentNavi.click(
			function(){
				strTabLink = $jq(this).children(".MenuOuterContainer").children(".MenuInnerContainer").children("a").attr("href");
				sma_ComputeCookieString(strTabLink, 1);
			}
		);
	}
	sma_ComputeCookieString("","")
}
function sma_GetUrlForRedirect(){
	var objMenu = null;
	var objNavi = null;
	var objContentNavi = null;

	if($jq("#TopMenu").length){
		objMenu = $jq("#TopMenu li");
		objNavi = $jq("#MidNavi li");
		objContentNavi = $jq("#contentNav li");
	}
	if($jq("#TopMenuProd").length){
		objMenu = $jq("#TopMenuProd li");
		objNavi = $jq("#MidNavi li");
		objContentNavi = $jq("#contentNav li");
	}
	if(objMenu != null){
		objMenu.each(function(){
			strID = $jq(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($jq.cookie("smaTabId") == null){
		strSMACookie = "/default.aspx" + "|" + "/default.aspx" + "|";
	}
	if($jq.cookie("smaTabId") != null){
		strCookieVal1 = $jq.cookie("smaTabId").slice(0,$jq.cookie("smaTabId").indexOf("|"));
		strCookieVal2 = $jq.cookie("smaTabId").slice($jq.cookie("smaTabId").indexOf("|")+1,$jq.cookie("smaTabId").lastIndexOf("|"));
		strCookieVal3 = $jq.cookie("smaTabId").slice($jq.cookie("smaTabId").lastIndexOf("|")+1,$jq.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){
	$jq.cookie("smaTabId", _strCookieVal, { path: '/' });
}
function sma_GetCookieTest(){
	alert($jq.cookie("PersonaID"));
}
// function to update the cookies by changing the stage
function sma_setCookies(_strID){
	$jq.cookie("PersonaID", sma_GetPageValues(_strID,"PersonaID"), { path: '/' });
	$jq.cookie("StageTitle", sma_GetPageValues(_strID,"StageTitle"), { path: '/' });
	$jq.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 = "22";
			strStageTitle = "Resources HCPs";
			strImgStage = "/Portals/_default/Skins/SMA-Professional/img/menu/TM1_on.jpg";
			break;
		case "TM2":
			strID = "23";
			strStageTitle = "Resources Mums";
			strImgStage = "/Portals/_default/Skins/SMA-Professional/img/menu/TM2_on.jpg";
			break;
		case "TM3":
			strID = "24";
			strStageTitle = "Breastfeeding";
			strImgStage = "/Portals/_default/Skins/SMA-Professional/img/menu/TM3_on.jpg";
			break;
		case "TM4":
			strID = "25";
			strStageTitle = "Bottle-feeding";
			strImgStage = "/Portals/_default/Skins/SMA-Professional/img/menu/TM4_on.jpg";
			break;
		case "TM5":
			strID = "26";
			strStageTitle = "Nutrition";
			strImgStage = "/Portals/_default/Skins/SMA-Professional/img/menu/TM5_on.jpg";
			break;
		case "TM6":
			strID = "27";
			strStageTitle = "Feeding Problems";
			strImgStage = "/Portals/_default/Skins/SMA-Professional/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($jq("#KnowHowNaviGrey").length){
		$jq("#KnowHowNaviGrey a").attr("href",strNewKnowHowLink);
	}
	if($jq("#KnowHowNavi").length){
		$jq("#KnowHowNavi a").attr("href",strNewKnowHowLink);
	}
	$jq("#TopLogoLink").attr("href",strNewLogoLink);
}
function sma_GetPersonaLinks(strLinkType){
	var strTabId = "";
	var strNewKnowHowLink = "";
	var strNewLogoLink = "";
	var strPersonaID = $jq.cookie("PersonaID");
	switch(strPersonaID){
		case "22":
			strTabId = "1277";
			break;
		case "23":
			strTabId = "1278";
			break;
		case "24":
			strTabId = "1279";
			break;
		case "25":
			strTabId = "1280";
			break;
		case "26":
			strTabId = "1281";
			break;
		case "27":
			strTabId = "1282";
			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($jq('ul#menu').length){
		var i = 1;
		$jq("ul#menu li").each(function(){
			newCls = $jq(this).attr("class");
			newCls = newCls + "_" + i;
			i++;
			if (newCls.indexOf("activeitem") != -1){
				newCls = newCls.charAt(newCls.length - 1);
				newCls -= 1;
				$jq('ul#menu').lavaLamp({startItem:newCls, speed:400});
			}
		});
	}
	if($jq('ul#TopMenu').length){
		$jq(".topMenu_small li").each(function(){
			newCls = $jq(this).attr("id");
			if(newCls.indexOf("_on") != -1){
				tmpBackLava = newCls;
				newCls = newCls.substring(2,3);
				newCls -= 1;
				$jq('ul#TopMenu').lavaLamp({startItem:newCls,speed:400});
			}
		});
	}
	if($jq('ul#TopMenuProd').length){
		$jq(".topMenuProd_small li").each(function(){
			newCls = $jq(this).attr("id");
			if(newCls.indexOf("_on") != -1){
				newCls = newCls.substring(2,3);
				newCls -= 1;
				$jq('ul#TopMenuProd').lavaLamp({startItem:newCls,speed:400});
			}
		});
	}
}
/* End - Set LavaLamp */
/* Start - Set TopMenuSmall */
function sma_TopMenuSmall_LoadImg(){
	if($jq(".topMenu_small").length){
		$jq(".topMenu_small li").each(function(){
			newCls = $jq(this).attr("id");
			var intNmb = newCls.replace("TM","");
			if(newCls.indexOf("_on") != -1)
			{
				$jq(this).children().html("<span><img src='/Portals/_default/Skins/SMA-Professional/img/menu/MImg" + intNmb + ".jpg'/></span>");
			}
			else{
				$jq(this).children().html("<span><img src='/Portals/_default/Skins/SMA-Professional/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 ) {
      $jq('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: <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" target="_blank">go to Microsoft</a></h4></div></div>')
	}
  }
}
/* End - Browser Check */
function sma_SetSearchSubmit(){
	$jq("#dnn_SearchInput1_linkSearch").attr("href","javascript:sma_SearchTest()");
	
}
function sma_SearchTest(){
__doPostBack('dnn$SearchInput1$linkSearch','');
}
// show and hide the stored know how content
function sma_showHideKnowHow(){
	$jq('#OpenStoredKH').click(function(){
		var strSrc = $jq('#OpenStoredKH').attr('src');
		$jq('#SKHs_list').toggle('slow');
		
		if (strSrc.indexOf("add") != -1){
			$jq('#OpenStoredKH').attr('src','/Portals/_default/Skins/SMA-Professional/img/remove_tiny.jpg');	
		}else{
			$jq('#OpenStoredKH').attr('src','/Portals/_default/Skins/SMA-Professional/img/add_tiny.jpg');
		}
	});
}
// function to devide the title of the last pages to fit in the recently viewed and stored know how teaser box. 
function sma_previewRVStoredKH(){
	$jq('#TableRecentlyViewContent li a').each(function(){sma_CutTitle(this,140)});
	$jq('.tableStoredKnowHow li a').each(function(){sma_CutTitle(this,170)});
	$jq('#HelloUser').each(function(){sma_CutTitle(this,120)});
	$jq('#NotYourName').each(function(){sma_CutTitle(this,100)});
}
function sma_CutTitle(objCurrent,intWidth){
		$jq(objCurrent).shorten({ width: intWidth, tail: ' ...'}); 
		$jq(objCurrent).css({'visibility ': 'visible', 'display' : 'inline', 'white-space' : 'wrap'});
}

function sma_RatingOnStart(){
	if($jq("#RatingContainer") != null){
		if($jq("#RatingContainer").length > 0){
			$jq('.auto-submit-results').results({callback: function(value, link) {sma_DoRating(value, link,this)}});
			$jq('.auto-submit-item').rating({callback: function(value, link) {sma_DoRating(value, link,this)}});
			$jq("#RatingContainer").css('display','block');
		}
	}
}
function sma_DisplayRating(){
	if($jq("#DisplayRating").html().indexOf("Rate") > -1){
		if($jq('#content_rating').html() == null){
			if($jq('#RatingDetail').html().indexOf("<div>You have to login to rate this page.</div>") == -1){
				$jq('#RatingDetail').html($jq('#RatingDetail').html()+"<div>You have to login to rate this page.</div>");
			}
		}
		$jq('#RatingDetail').css('display','block');
		$jq("#DisplayRating").html("Close");
	}
	else{
		$jq('#RatingDetail').css('display','none');
		$jq("#DisplayRating").html("Rate");
	}
}
function sma_UpdateRating(originalRequest) {
	var objRating = $jq(originalRequest).find('div[id=RatingContainer]');
	if(objRating.length > 0){
		$jq('#RatingContainer').html(objRating.html());
		sma_RatingOnStart();
	}
}
function sma_DoRating(value, link,objThis){
			// the cancel button has been selected
			var intIndex = 0;
			
			// a star has been selected -> get the index
			if (value != ''){
				var objCollection = objThis.parentNode.parentNode.childNodes;
				var intCounter = 0;
				var intTemp = 0;
				
				for (intTemp = 0; intTemp != objCollection.length; intTemp++)
					if (objCollection[intTemp].id == 'content_rating_item')	{
						intCounter += 1;
						if (objCollection[intTemp].innerHTML.indexOf(value) != -1)
							intIndex = intCounter;
					}
				// Only do the following if we have half stars --> intStars is defined in template (XSL)
				if (intStars == 2)
					if (value.indexOf(']') == -1)
						intIndex -= 0.5;
			}
			
			// --- END: GET INDEX --------------------------------------------------------------------------------------
			// --- SUBMIT THE VALUE TO THE SERVER ----------------------------------------------------------------------
			
			// use AJAX if the parameter has been set to 1 --> intAjax is defined in template (XSL)
			if (intAjax == 1)
				jQuery.ajax({ type: "POST", url: location.href, data: 'rating='+intIndex,  success: sma_UpdateRating });									
			
			// the parameter hasn't been set to one -> no AJAX
			else{
				// get the form
				var objForm = document.forms['Form'];
				if (!objForm)
					objForm = document.Form;
			
				// generete ur parameter
				var strURL = location.href;
				if(strURL.indexOf('?') == -1){
					var intParamIndex = strURL.indexOf('?rating=');
					if (intParamIndex == -1)
						strURL = strURL + '?rating=' + intIndex;
					else
						strURL = strURL.split('?rating=')[0] + '?rating=' + intIndex;
				}
				else{
					var intParamIndex = strURL.indexOf('&amp;rating=');
					if (intParamIndex == -1)
						strURL = strURL + '&amp;rating=' + intIndex;
					else
						strURL = strURL.split('&amp;rating=')[0] + '&amp;rating=' + intIndex;								
				}										
				location.href = strURL;
				objForm.submit();
			}
			
			// --- END: SUBMIT THE VALUE TO THE SERVER ----------------------------------------------------------------------
		}

function sma_OrderLitSetStyles(){
	if($jq("#dnn_ctr2087_ViewOrderLiterature_btnPlaceOrder") != null){
		if($jq("#dnn_ctr2087_ViewOrderLiterature_btnPlaceOrder").length > 0){
			$jq(".forwarButton").addClass('Alternativ');	
			$jq("#dnn_ctr2087_ViewOrderLiterature_btnPlaceOrder").css("margin","10px 107px 5px 2px");
		}
	}
}
//Sets the Bookmarks-CSS-Position to absolute if width is to small, otherwise it Social-Bookmarks are not shown
function sma_SetBookmarksPosition(){
	if($jq(document).width() <= 1060){
		if($jq("#Social") != null){
			$jq("#Social").css("position","absolute");
		}
	}
}
// 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 ($jq('.SkinObject').text().indexOf('Helpsheet') != -1){
		$jq('.SkinObject:last').html('Helpsheet');
	}
	if ($jq('.SkinObject').text().indexOf('Video') != -1){
		$jq('.SkinObject:last').html('Video');
	}
}
function sma_PageFlip(){
	$jq(function() {
		//single book
		$jq('#mybook').booklet({
			width: 570,
			height: 420,
			shadows: true,
			easing: "easeInOutQuad",
			shadowTopFwdWidth: 166,
			shadowTopBackWidth: 166,
			shadowBtmWidth: 50,
			closed:true,
			autoCenter:true,
			arrows:true,
			overlays:false,
			manuals:false,
			pageNumbers:false
		});
	});
}
