var theURL = document.location.href;
if(theURL.indexOf('lang=fr') > -1){    
	theURL = theURL.replace("lang=fr", "lang=en-GB");
	document.location.href = theURL;
}
else if(theURL.indexOf('lang=en') > -1 && theURL.indexOf('lang=en-GB') <= -1){    
	theURL = theURL.replace("lang=en", "lang=en-GB");
	document.location.href = theURL;
}

function mainNav(){
	var linkNo = $('#mainNav > ul > li > a').size();
	var width = $('#mainNav').width();
	var linkWidth = 0;
	$('#mainNav > ul > li > a').css('padding', 0);
	$('#mainNav > ul > li > a').each(function(e){
		linkWidth += $(this).width();
	});
	var padding = Math.floor(((width - linkWidth) / linkNo) / 2);
	var difference = width - (linkWidth + (Math.floor(((width - linkWidth) / linkNo) / 2) * (linkNo * 2)));
	$('#mainNav > ul > li > a').not('.dontResize a').css('padding-left', padding + 'px').css('padding-right', padding + 'px');
	$('#mainNav > ul > li > a:last').not('.dontResize a').css('padding-right', padding + Math.ceil(difference/2) + 'px');
	$('#mainNav > ul > li > a:last').addClass('last');
	$('#mainNav > ul > li > a:first').css('padding-left', padding + Math.floor(difference/2) + 'px').addClass('first');
	$('#mainNav ul ul').find('li:first').addClass('subFirst');
	$('#mainNav ul li').mouseenter(function(){
	   $(this).addClass('over');
	   $(this).find('a:first').addClass('hover');
	   $(this).find('ul:first').show();
	});
	$('#mainNav ul li').mouseleave(function(){
	   $(this).removeClass('over');
	   $(this).find('a:first').removeClass('hover');
	   $(this).find('ul:first').hide();
	});
};

function leftNav(){
    $('#leftNav li:first').attr('id', 'first');
    $('#leftNav li:last').attr('id', 'last');
	//$('#leftNav li li a span span').prepend('- ');
	if($('#leftNav ul:first li').size() == 1){
        $('#leftNav ul:first li').attr('id', 'single');
	}
}

function bookmark(){
	var url = 'http://www.statpro.com';
	var title = 'StatPro';
	if((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		window.external.AddFavorite(url,title);
	}
	else if(navigator.appName == "Netscape") {
		window.sidebar.addPanel(title,url,"");
	}else{
		alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
	}
}

function roundBoxes(){
    $('.blueBox').each(function(){
        $(this).wrapInner('<span class="bb2"><span class="bb3"></span></span>')
        $(this).addClass('bb1').removeClass('blueBox');
    });
    $('.redBox').each(function(){
        $(this).wrapInner('<span class="rb2"><span class="rb3"></span></span>')
        $(this).addClass('rb1').removeClass('redBox');
    });
    $('.blueBoxSmall').each(function(){
        $(this).wrapInner('<span class="bbs2"><span class="bbs3"></span></span>')
        $(this).addClass('bbs1').removeClass('blueBoxSmall');
    });
     $('.borderBox').each(function(){
        $(this).wrapInner('<div class="bbox2"><div class="bbox3"></div></div>')
        $(this).addClass('bbox1').removeClass('borderBox');
    });
}

function initLightbox(){
    if($('.lightbox').size() > 0){
        $('.lightbox').not($('.lightbox').attr('rel')).lightBox();
        lightBoxArray = [];
        $('.lightbox').each(function(){
            lightBoxArray.push($(this).attr('rel'));
        });
        for(i=0; i<lightBoxArray.length; i++){
            if(lightBoxArray[i] == lightBoxArray[i-1]){
                lightBoxArray.splice(lightBoxArray[i],2);
            }
        }
        for(i=0; i<lightBoxArray.length; i++){
            $('.lightbox[rel="' + lightBoxArray[i] + '"]').lightBox();
            //$(".lightbox[rel='" + lightBoxArray[i] + "']").not($(".lightbox:first[rel='" + lightBoxArray[i] + "']")).hide();
        }
    }
}

$(document).ready(function(){
	mainNav();
	leftNav();
	roundBoxes();
	initLightbox();
	if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        var ieversion=new Number(RegExp.$1)
        if(ieversion < 7 && parent.top.$("#PreviewWindow").size() == 0){
            DD_belatedPNG.fix('img, #top, #main, #footer, #mainNav, #mainNav .on a, #mainNav .on .last, #banner, .hrzList a, .bbox1, .bbox2, .bbox3');
        }
    }
});
