// Generate a random number for the banner

     var numRand = Math.floor(Math.random()*9);

// Suckerfish fix for IE6 and <

     sfHover = function() {
	var sfEls = document.getElementById("level1").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	    }
          }
     if (window.attachEvent) window.attachEvent("onload", sfHover);

jQuery(document).ready(function() {

// Simple Modal

$("#modalContent1").css({'display':'none'});
$("#modalContent2").css({'display':'none'});
$("#modalContent3").css({'display':'none'});
$("#modalContent4").css({'display':'none'});
$("#modalContent5").css({'display':'none'});
$("#modalContent6").css({'display':'none'});

$("#modalButton1").click(function(e) {
  e.preventDefault();
  $("#modalContent1").modal();
});

$("#modalButton2").click(function(e) {
  e.preventDefault();
  $("#modalContent2").modal();
});

$("#modalButton3").click(function(e) {
  e.preventDefault();
  $("#modalContent3").modal();
});

$("#modalButton4").click(function(e) {
  e.preventDefault();
  $("#modalContent4").modal();
});

$("#modalButton5").click(function(e) {
  e.preventDefault();
  $("#modalContent5").modal();
});

$("#modalButton6").click(function(e) {
  e.preventDefault();
  $("#modalContent6").modal();
});

// Randomised Quotes

var childLength = $(".inlineQuoteBox").children().size(); 
var randomNum = Math.floor(Math.random()*childLength);

$("div.quote").eq(randomNum).css({'display' : 'block'});

$(".innerQuoteDiv").each(function (i) {
    $(this).find("p:first").prepend("<img src='/graphics/iconQuoteOpen.gif' width='21' height='16' alt='' />");
    $(this).find("p:last").append("<img src='/graphics/iconQuoteClose.gif' width='21' height='16' alt='' />");
});

// Randomised tagline in header

        var titleHeight = 60;
        var totalNum = 4;
        var rndNum = Math.floor(Math.random() * totalNum);
        var positionPixels = titleHeight * rndNum;
        $("div#headerStrap").css("backgroundPosition", "0px -" + positionPixels + "px");

// Breadcrumb Length

if(document.getElementById("centerTop"))
{
        var hey = $(".breadcrumb-trail span:last");
        var hmm = hey.html().length;

        if ( hmm >= 25 ) {

          $(".breadcrumb-trail span:last").html(hey.html().substring(0,25) + "...");

        }
}
							
// Let's get rid of annoying title popups. They cause problems with the drop-down menu.

	$("a").removeAttr("title");

// Wraps shadow code on all images with a class of "image".

	$("span.imageWrap img, #investmentHeaderLeft img").wrap("<div class='inlineImage'><div class='shadowTop'><div class='shadowBottom'>" + "</div></div></div>");
	$("#investmentHeaderLeft2 img").wrap("<div class='inlineImage'><div class='shadowTop2'><div class='shadowBottom2'>" + "</div></div></div>");
	
// Accordion control.

	$("#homeAccordion").accordion({autoHeight: false});
        $(".numberedAccordion").accordion({autoHeight: false});
        $(".tickAccordion").accordion({autoHeight: false});

// Carousel control & config.

	$("#btnNext").css('opacity', 0.80); 
	$("#btnNext").hover(
		function(){
			$(this).css('opacity', 0.90);
		}
	);
	$("#btnNext").mouseout(
		function(){
			$(this).css('opacity', 0.80);
		}
	);

// Large Home Banner

	$("#carousel").jCarouselLite({
		btnNext: "#btnNext",
		btnPrev: "#btnPrevious",
		speed: 500,
		auto: 9000,
                // visible: 1,
                scroll: 1,
		circular: true,
                start: 1
                // numRand set at top
	});

// Panel Banner On Home Page

        $("#homeCarousel").jCarouselLite({
		btnNext: "#btnHomeNext",
		btnPrev: "#btnHomePrevious",
		speed: 400,
		// auto: 6000,
                visible: 1,
                scroll: 1,
		circular: true,
                start: 1
	});

// Remove empty elements because Sitekit is a pain!

        $(".item").each(function(i){
		var i = $.trim($(this).text());
		if(i.length == 0) {
		    $(this).remove();
                }
                else {

$(this).click(function(){
     window.location=$(this).find("a").attr("href");
     return false;
});

		}
	});

// Remove empty accordion elements

        $(".numberedAccordion h3 a, .tickAccordion h3 a").each(function(j){
		var j = $.trim($(this).text());
		if(j.length < 3) {
		   $(this).parent().remove();
		   $(this).parent().next("div").remove();
		}
	});

// Remove empty people

        $(".personText").each(function(j){
		var j = $.trim($(this).text());

		if(j.length == 0) {

		   $(this).parent().remove();
		   //$(this).parent().next("div").remove();
		}
	});

// Quote-box elements

        $(".inlineQuoteBox").each(function(myItem){
		var myItem = $.trim($(this).text());
		if(myItem.length == 0) {
		   $(this).remove();
		}	
	});

        $(".fullQuoteBox").each(function(myItem){
		var myItem = $.trim($(this).text());
		if(myItem.length == 0) {
		   $(this).remove();
		}	
	});

// Related Links element

        if ($("#internalLinks").length < 1) {
            $("#sectionBox_2").remove();
        } 

// Truncate News text

        $("#boxLatestNews .newsItem p:odd a").truncate( 90, {
            chars: /\s/,
            trail: [ " <span class='truncate_show'>[+]</span>", " <span class='truncate_hide'>[-]</span>" ]
        });

// Sort Painful SiteKit forms without class ready for IE

        $("input[type='text']").removeClass().addClass("txt");

});
