var siteUrl = '/';

var OP   = (navigator.userAgent.indexOf("Opera") != -1); 
var IE   = (navigator.userAgent.indexOf("MSIE") != -1) && !OP; 
if (IE) {     
	sfHover = function()
		{   
		var sfEls = document.getElementById("navContainer").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++){
			sfEls[i].onmouseover=function(){
				this.className+=" hover";
			}
			sfEls[i].onmouseout=function(){
				this.className=this.className.replace(new RegExp(" hover\\b"), "");
			}
		}
	}
if (window.attachEvent) window.attachEvent("onload", sfHover); }  

if (location.href.indexOf('') == -1){
		location.href = ''; 
	} 
	else{
		$(document).ready(function(){
		
		// FIX -- repeated breadcrumb arrows
		$('.breadcrumb a:empty').remove();
		$('.breadcrumb a').after(' » ');
		
		// Global navigation drop menus
		// --------------------------------------------- 
		$('#navContainer ul li').each(function(){
			if ($(this).find('ul').length > 0){
				$(this).addClass('hasMenu');
			}	 
		});
		
// Historic reports redirect
		$("a[href='/OurInvestmentRange/InvestmentTrustInformation/HistoricReports.aspx']").attr('href', '/InvestorInformation/HistoricReports.aspx');


		// Last sitemap node
		$('.sitemap ul ul').each(function(){
			$(this).children('li:last').addClass('last'); });
		
		// Redirect interactive factsheet - DC site
		if (urlParameter('FundID') && urlParameter('ShareClassID') && urlParameter('FundType')){
			if (urlParameter('FundType') == 'Life'){
				$('#factsheet, #factsheetDP').attr('src','http://213.229.167.101/LF/retail/LifeFundOff.asp?PASSJP=&PARAMMIFID=' + mifid + '&USERJP=&lang=EN&view=GENERAL&fundid=' + urlParameter('FundID') + '&country=GB&subview=SUMMARY&frecuencia=Monthly&cambioshare=1&css=2&option=1&share=' + urlParameter('ShareClassID')); 
			}
			else{ 
				$('#factsheet, #factsheetDP').attr('src','http://213.229.167.101/FS/retail/FactSheet.asp?PASSJP=&PARAMMIFID=' + mifid + '&USERJP=&lang=EN&view=GENERAL&fundid=' + urlParameter('FundID') + '&country=GB&subview=SUMMARY&frecuencia=Monthly&cambioshare=1&css=2&option=1&share=' + urlParameter('ShareClassID'));
			}
		}
		
		// Redirect Investment Trust interactive factsheet
		if (urlParameter('TrustCode')){
			//$('#InvTrustFactsheet').attr('src','http://213.229.167.101/ITRUST/TestUC.aspx?trustCode=' + urlParameter('TrustCode') + '&css=2&PARAMMIFID=' + mifid + '&AspxAutoDetectCookieSupport=1');
			$('#InvTrustFactsheet').attr('src','http://213.229.167.101/JP/JP.mvc/ITOverview?FundId=' + urlParameter('TrustCode') + '&PARAMMIFID=' + mifid);
		}
	}); 
}  

// FIX -- get top most Section
function getTopSection(){ 	
	if ('' != ''){
		return location.pathname.split('/')[2]; 	
	} 	
	else{
	return location.pathname.split('/')[1]; 	
	} 
}  

// Get URL parameters 
// ---------------------------------------------  
function urlParameter(name){ 	
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");   	
	var regexS = "[\\?&]"+name+"=([^&#]*)";  	
	var regex = new RegExp(regexS);  	
	var results = regex.exec(window.location.href);   	
	if (results == null){
		return "";  	
	}
	else{
		return results[1]; 	
	}
}

// Change site name to friendly display name in site switcher - KA
$(function() {
	var $siteName = $('#siteName');
	if ('Investment Trusts' == 'Investment Trusts') {
		$siteName.html('For investment trusts');
	}
});
