function ThreeColDropdownMenu() {
    $('.splitcol').each(function() {
          var colsize = Math.round($(this).find("li").size() / 3);

          $(this).find("li").each(function(i) {
               if (i>=((colsize*2))) {
                    $(this).addClass('col1_flag');
               } 
               else if (i>=colsize) {
                    $(this).addClass('col2_flag');
               } 
          });

          $(this).find('.col1_flag').insertAfter(this).wrapAll("<ul class='splitcol1'></ul>").removeClass("col1_flag");
          $(this).find('.col2_flag').insertAfter(this).wrapAll("<ul class='splitcol2'></ul>").removeClass("col2_flag");
     });
}


function getTweets() {
    $(".tweet").tweet({
            username: "DiscoverRB",
            join_text: "... ",
            avatar_size: null,
            count: 1,
            auto_join_text_default: "we said,",
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out",
            loading_text: "loading tweets..."
     });
}


function printSharePrice() {

  if (window.hour) {
    // Get feed time
    if(hour > 12) {
      var hsTempAMPM = "PM";
    } else {
      var hsTempAMPM = "AM";
    }
    var hsTempTime = hour+":"+min+hsTempAMPM;
    // Get current time
    now = new Date;
    var rbTempHours = now.getHours();
    if(rbTempHours > 12) {
      var rbTempAMPM = "PM";
    } else {
      var rbTempAMPM = "AM";
    }
    rbTempHours = rbTempHours.toString();
    if(rbTempHours.length == 1) {
      rbTempHours = "0" + rbTempHours;
    }
    var rbTempMinutes = now.getMinutes();
    rbTempMinutes = rbTempMinutes.toString();
    if(rbTempMinutes.length == 1) {
      rbTempMinutes = "0" + rbTempMinutes;
    }
    var rbTempSeconds = now.getSeconds();
    rbTempSeconds = rbTempSeconds.toString();
    if(rbTempSeconds.length == 1) {
      rbTempSeconds = "0" + rbTempSeconds;
    }
    var rbTempTime = rbTempHours+":"+rbTempMinutes+rbTempAMPM;
    document.write("<div class='homeshareprice'>");
    document.write("<span class='homesharepriceheading'>Share price</span><br>");
    document.write("<span class='homesharepricelive'>"+prices+"<br />");
    
    if(change > 0) {
      document.write("+");
    } 
  
    document.write(""+change+"p</span>"); 
    
    
    document.write("</div>");  
    document.write("<div class='homesharedetails'>");
    document.write("Date: "+dateddmmmyyyy+"<br>");
    document.write("Time now: "+rbTempTime+"<br>");
    document.write("Trade time: "+hsTempTime+"<br>");
    document.write("</div>");
  }
}

function sharePricePopUp(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function printSharePricePopUp() {
  // Get feed time
  if(hour > 12) {
    var hsTempAMPM = "PM";
  } else {
    var hsTempAMPM = "AM";
  }
  var hsTempTime = hour+":"+min+hsTempAMPM;
  // Get current time
  now = new Date;
  var rbTempHours = now.getHours();
  if(rbTempHours > 12) {
    var rbTempAMPM = "PM";
  } else {
    var rbTempAMPM = "AM";
  }
  rbTempHours = rbTempHours.toString();
  if(rbTempHours.length == 1) {
    rbTempHours = "0" + rbTempHours;
  }
  var rbTempMinutes = now.getMinutes();
  rbTempMinutes = rbTempMinutes.toString();
  if(rbTempMinutes.length == 1) {
    rbTempMinutes = "0" + rbTempMinutes;
  }
  var rbTempSeconds = now.getSeconds();
  rbTempSeconds = rbTempSeconds.toString();
  if(rbTempSeconds.length == 1) {
    rbTempSeconds = "0" + rbTempSeconds;
  }
  var rbTempTime = rbTempHours+":"+rbTempMinutes+rbTempAMPM;
  document.write("<span class='sharepricepopupprice'>"+prices+"</span><br>");
    if(change < 0) {
      document.write("<img src='../UploadedResources/rb_sharepricepopup_arrow_down.gif' alt='down arrow' style='margin-right:5px;'>");
    } else if (change > 0) {
      document.write("<img src='../UploadedResources/rb_sharepricepopup_arrow_up.gif' alt='up arrow' style='margin-right:5px;'>");
    }
  
  document.write("<span class='sharepricepopupchange'>"+change+"p</span><br>"); 
  document.write("<div class='sharepricepopupdetails'>");
  document.write("Date: "+dateddmmmyyyy+"<br>");
  document.write("Time now: "+rbTempTime+"<br>");
  document.write("Trade time: "+hsTempTime+"<br>");
  document.write("</div>");
}

/* This function opens a new window, or changes the URL, to display the appropriate content */

var winContent;

function popUpWindow(sURL,popWidth,popHeight,popLeft,popTop)
{
  if (!winContent)
  {
    winContent = window.open(sURL, 'PopUp','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+popWidth+',height='+popHeight+',left='+popLeft+',top='+popTop+'');
  }
  else
  {
    if (winContent.closed)
    {
      winContent = window.open(sURL, 'PopUp','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+popWidth+',height='+popHeight+',left='+popLeft+',top='+popTop+'');
    }
    else
    {
      winContent.document.location = sURL;
    }
  }
 
   winContent.focus();
}


/* EVERY THING BELOW THIS LINE IS NOW IN JS.GUI */

$(document).ready(function() {

    if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) {
        $('.slide ul').addClass('noopacity');
    };


    // Cycle images for sub content quotes

    $('#subContentFade, #homeContentFade').cycle({
        fx: 'fade',
        speed: 1000
    });


    $('#subContentFade2').cycle({
        fx: 'fade',
        speed: 1000,
        timeout: 10000
    });



    // START LOADING EXTERNAL CONTENT IN DIVS 						   

    $('.ajaxload').click(function() {

        var displayLocation = '#' + $(this).attr('rel');
        // We use '>' to make sure we only get the children of the <div> not the <div> itself
        var toLoad = $(this).attr('href') /* + ' ' + displayLocation + ' >'*/;

        $(displayLocation).fadeOut('fast', loadContent);

        function loadContent() {
            $(displayLocation).load(toLoad, '', showNewContent())
        }

        function showNewContent() {
            $(displayLocation).fadeIn('normal');

        }
        return false;

    });

    // END LOADING EXTERNAL CONTENT IN DIVS 

    // START BACKGROUND COLOR CHANGE 

    $('.home_secondary_3col').hoverIntent(function() {
        var activePanel = $(this).attr('id');
        $(this).addClass(activePanel + '_active');
        slidePanelUp(activePanel, '.home_slidepanel_3col');
    },
	function() {
	    var activePanel = $(this).attr('id');
	    $(this).removeClass(activePanel + '_active');
	    slidePanelDown(activePanel, '.home_slidepanel_3col');
	});
    $('.home_secondary').hoverIntent(function() {
        var activePanel = $(this).attr('id');
        $(this).addClass(activePanel + '_active');
        slidePanelUp(activePanel, '.home_slidepanel_3col');
    },
	function() {
	    var activePanel = $(this).attr('id');
	    $(this).removeClass(activePanel + '_active');
	    slidePanelDown(activePanel, '.home_slidepanel_3col');
	});

    $('.home_secondary_4col, .home_secondary_4col_b').hoverIntent(function() {
        var activePanel = $(this).attr('id');
        $(this).addClass(activePanel + '_active');
        slidePanelUp(activePanel, '.home_slidepanel_4col');
    },
	function() {
	    var activePanel = $(this).attr('id');
	    $(this).removeClass(activePanel + '_active');
	    slidePanelDown(activePanel, '.home_slidepanel_4col');
	});

    function slidePanelUp(activePanel, activePanelClass) {
        $('#' + activePanel + "_holder " + activePanelClass).animate({ top: '-165px' }, 'slow', 'swing');
    }

    function slidePanelDown(activePanel, activePanelClass) {
        $('#' + activePanel + "_holder " + activePanelClass).animate({ top: '0px' }, 'slow', 'swing');
    }


    // END BACKGROUND COLOR CHANGE 	


    // SET THE HOMEPAGE COLS TO BE EQUAL HEIGHT

    equalHeight($(".home_secondary_3col"));
    equalHeight($(".home_secondary"));
    equalHeight($(".home_secondary_4col"));
    equalHeight($(".home_secondary_4col, .home_secondary_4col_b"));


    function equalHeight(group) {
        tallest = 0;
        group.each(function() {
            thisHeight = $(this).height();
            if (thisHeight > tallest) {
                tallest = thisHeight;
            }
        });
        group.height(tallest);
    }

    $('.cssdropdown').hover(
      function() {
          $('.cssdropdown ul li ul').slideToggle('medium');
          $('.cssdropdown').parent().parent().parent().css({ 'z-index': '1000' });
      },
      function() {
          obj = this;
          $('.cssdropdown ul li ul').slideToggle('medium');
      }
    );

    // Revised dropdown jQuery script

    $('.hover-menu').hoverIntent(function() {

        var direction = "";
        $(this).find('ul ul').css('margin-top', '0px');

        var direction = $(this).attr("class");

        if (direction == "hover-menu up") {
            // var subMenuVerticalOffset = $(this).find('ul ul').height() + $(this).find('ul').height();
            var subMenuVerticalOffset = $(this).find('ul ul').height() + 24;
            $(this).find('ul ul').css('margin-top', '-' + subMenuVerticalOffset + 'px');
        }

        $('#home_secondary_1_holder').css({ 'z-index': '3000' });
        $(this).find('ul ul').fadeIn('fast');
    },
    function() {
        $(this).find('ul ul').fadeOut('fast')
    });


    // Country select menu

    $('.countryselectbutton').hoverIntent(function() {
        var subMenuVerticalOffset = $('.countryselect').height();

        $(this).find('.countryselect').css('margin-top', '-' + subMenuVerticalOffset + 'px');

        $('#home_secondary_2_holder').css({ 'z-index': '3000' });
        $(this).find('.countryselect').fadeIn('fast');
    },
    function() {
        $(this).find('.countryselect').fadeOut('fast')
    });

    // Country select menu 2 (Global Ops page)

    $('.countryselectbutton2').hoverIntent(function() {
        var subMenuHorizontalOffset = ($('.countryselect').width() / 2);

        $(this).find('.countryselect').css('margin-left', '-' + subMenuHorizontalOffset + 'px');
        $('.countryselect').css('margin-top', '20px');
        $('#home_secondary_2_holder').css({ 'z-index': '3000' });
        $(this).find('.countryselect').fadeIn('fast');
    },
    function() {
        $(this).find('.countryselect').fadeOut('fast')
    });

   
    // Set the configuration for the first set of carousels
    $(".content_carousel").jCarouselLite({
  
    btnPrev: ".slideshow_prev",
    btnNext: ".slideshow_next",
    visible: 1,
    circle: true,
    auto: null, // time in ms before the slide
    speed: 1000, // the speed of the slide
    start: 0
  
    });
    

});






jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.03
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);			
				var defTiming = stripWidth/settings.travelocity;
				var totalTravel = stripWidth+containerWidth;								
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};




