// JavaScript Document
$(function(){ //drop down menu
  $('#nav li ul').css({
    display: "none",
    left: "auto"
  });
  $('#nav li').hover(function() {
    $(this)
      .find('ul')
      .stop(true, true)
      .slideDown('medium');
  }, function() {
    $(this)
      .find('ul')
      .stop(true,true)
      .css('display','none');
  });
jQuery.preloadImages( //preloads images for main nav
	"/images/nav/over/en-2011PROGRAMME.gif",
	"/images/nav/over/en-ABOUTLEGATUM.gif",
	"/images/nav/over/en-LINKS.gif",
	"/images/nav/over/en-MEDIA.gif",
	"/images/nav/over/en-NEWS.gif",
	"/images/nav/over/en-OURSPONSORS.gif"
	);
$("#topnav > li:first").find("a").css({"border" : "none"});//removes borders from first element in top nav
$("#topnav img").parent("a").css({"border" : "none", "padding" : "0 5px"});//removes border from language images in top nav
$("#topnav").find("img").last().parent("a").css({"padding-right" : "0"});//removes padding from last item in top nav
$("#main div.blockwrapper:first").css({"margin-top" : "0"}).find("span h2").css({"margin-top" : "30px"});//adjusts margin in first block
$("#main div.blockwrapper:first div.block:first").css({"margin-top" : "0"});//set zero margin for content under tabs
$("#main div.row:first").css({"margin-top" : "0"});//set zero margin for first row in news and media block
$("ul.calendar:odd").css({"background-color" : "#eaede3"});//set alternative rows for calendar
$("#col1 .news:first").css({"padding-top" : "4px", "border-top" : "none"});//set top padding and remove border for first news item
$("#awards ul li > a:odd").css({"background-color" : "#dedfdd"});//set alternate rows for awards block
$("#alumni ul:last").css({"margin" : "0"});//removes margin from last item in previous alumni block
$("fieldset > div:odd").css("background-color","#ededed");
jQuery.mainNav();//main navigation mouse over and initialization
	$("#hostnations > a:not(:last)").each(function(index, element) {
		$(this).append("<span class='hide tooltip'></span>").find("span").text($(this).find("img").attr("alt"));
	});
	$("#hostnations > a:not(:last)").hover(function(){
		$(this).find("span").show();
	},
	function(){
		$(this).find("span").hide();
	});
	
});

//preload images function
(function($) {
  var cache = [];
  $.preloadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);

//main navigation function
(function($){
	$.mainNav = function(){
		$("#nav li").each(function(index, element) {
            if($(this).attr("class") == "selected"){
				$(this).find("img").attr("src", $(this).find("img").attr("src").replace("/out/","/over/"));
			}
        });
		$("#nav li a").hover(function(){
			$(this)
			.find("img").attr("src",$(this).find("img").attr("src").replace("/out/","/over/"));
		},
		function(){
			if($(this).parent().attr("class") != "selected"){
			$(this)
			.find("img").attr("src",$(this).find("img").attr("src").replace("/over/","/out/"));
			}
		});
	}
})(jQuery);


