jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	jQuery("<img>").attr("src", arguments[i]);
}
jQuery.preloadImages("i/scroller_down.png", "i/scroller_up.png", "i/scroller_down_over.png", "i/scroller_up_over.png" );

jQuery(document).ready(function(){

$("#menu li a img").fadeTo("fast", 0.85);
$(".scrollerBox").fadeTo("fast", 0.82);
$(".scrollerSmlBox").fadeTo("fast", 0.82);
$(".scrollerTallBox").fadeTo("fast", 0.82);
$("#alsoInThisSection").fadeTo("fast", 0.7).corner("5px");
$("#relatedPages").fadeTo("fast", 0.7).corner("5px");
$("ul#menu li.mega div").fadeTo("fast", 0.75);

	//settings
	var opacity = 0.82, toOpacity = 0.95, duration = 250;
	//set opacity ASAP and events
	$('.scrollerBox').css('opacity',opacity).hover(function() {
			$(this).fadeTo(duration,toOpacity);
		}, function() {
			$(this).fadeTo(duration,opacity);
		}
	);
	$('.scrollerSmlBox').css('opacity',opacity).hover(function() {
			$(this).fadeTo(duration,toOpacity);
		}, function() {
			$(this).fadeTo(duration,opacity);
		}
	);
	$('.scrollerTallBox').css('opacity',opacity).hover(function() {
			$(this).fadeTo(duration,toOpacity);
		}, function() {
			$(this).fadeTo(duration,opacity);
		}
	);
	
	$('#alsoInThisSection').css('opacity',0.7).hover(function() {
			$(this).fadeTo(duration,0.9);
		}, function() {
			$(this).fadeTo(duration,0.7);
		}
	);
	
	$('#relatedPages').css('opacity',0.7).hover(function() {
			$(this).fadeTo(duration,0.9);
		}, function() {
			$(this).fadeTo(duration,0.7);
		}
	);	
	
	$('ul#menu li.mega div').css('opacity',0.75).hover(function() {
			$(this).fadeTo(duration,0.9);
		}, function() {
			$(this).fadeTo(duration,0.75);
		}
	);	
	
	$('#developers').css('opacity',0.35).hover(function() {
			$(this).fadeTo(duration,0.9);
		}, function() {
			$(this).fadeTo(duration,0.35);
		}
	);			
		

$("#pageHeader h1").fadeTo("fast", 0.75);
$("#toppanel").fadeTo("fast", 0.95);
$("#vidInfo").fadeTo("fast", 0.85).corner("5px");


	$("#menu li a").hover(
		function(){
			$(this).children("img").animate({"left": "+=10px", "easing": "easein"}, "fast");
			$(this).children("span").animate({"left": "+=10px", "easing": "easein"}, "fast");
			$(this).children("span").css({color: "#CC5500"});
			$(this).children("img").css({zIndex: "7"});
			$(this).css("cursor", "pointer");
		},
		function(){
			$(this).children("img").animate({"left": "-=10px", "easing": "easeout"}, "fast");
			$(this).children("span").animate({"left": "-=10px", "easing": "easeout"}, "fast");	
			$(this).children("span").css({color: "white"});					
   			$(this).children("img").css({zIndex: "1"});
			$(this).children("span.submenu").animate({opacity: "hide"}, "fast");
		});
		
	$("#homePageLinks .link ").hover(
		function(){
			var iconName = $(this).children("img").attr("src");
			var origen = iconName.split(".png")[0];
			$(this).children("img").attr({src: "" + origen + "_o.png"});
		},
		function(){
			var iconName = $(this).children("img").attr("src");
			var origen = iconName.split("_o.")[0];
			$(this).children("img").attr({src: "" + origen + ".png"});
		});		
		
	$("#homeLink").hover(
		function(){
			var iconName = $(this).children("img").attr("src");
			var origen = iconName.split(".png")[0];
			$(this).children("img").attr({src: "" + origen + "_o.png"});
		},
		function(){
			var iconName = $(this).children("img").attr("src");
			var origen = iconName.split("_o.")[0];
			$(this).children("img").attr({src: "" + origen + ".png"});
		});			
		
});

		$(function()
		{
			$('#pane').jScrollPane({showArrows:true, arrowSize:55, scrollbarWidth:50, scrollbarMargin: 0, wheelSpeed:18, dragMinHeight:0, dragMaxHeight:200, reinitialiseOnImageLoad:true, topCapHeight:10, bottomCapHeight:15 });
			$('#paneSml').jScrollPane({showArrows:true, arrowSize:55, scrollbarWidth:50, scrollbarMargin: 0, wheelSpeed:18, dragMinHeight:0, dragMaxHeight:200, reinitialiseOnImageLoad:true, topCapHeight:10, bottomCapHeight:15 });
			$('#paneTall').jScrollPane({showArrows:true, arrowSize:55, scrollbarWidth:50, scrollbarMargin: 0, wheelSpeed:18, dragMinHeight:0, dragMaxHeight:200, reinitialiseOnImageLoad:true, topCapHeight:10, bottomCapHeight:15 });			
			// $('.jScrollPaneContainer').resizable();
			//$('.scrollerBox').draggable().css("cursor", "move");
			//$('.scrollerSmlBox').draggable().css("cursor", "move");
			//$('.scrollerTallBox').draggable().css("cursor", "move");
			// $('#navBox').draggable();
		});

    $(document).ready(function() {
      
      function addMega(){
        $(this).addClass("hovering");
        }

      function removeMega(){
        $(this).removeClass("hovering");
        }

    var megaConfig = {
         interval: 250,
         sensitivity: 4,
         over: addMega,
         timeout: 300,
         out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig);
	$("ul#menu li.mega div").corner("5px");	
	
	});




$(document).ready(function() {
    $('.flames1').cycle({ 
    fx:     'fade',
    timeout:  60,
	continuous: 1,
	random: 1,
	pause:  1,
	delay:         1,
	cleartype:true  
});
});
$(document).ready(function() {
    $('.flames2').cycle({ 
    fx:     'fade',
    timeout:  1,
	continuous: 1,
	random: 1,
	pause:  0,
	delay:         0,
	cleartype:true   
});
});
$(document).ready(function() {
    $('.flames3').cycle({ 
    fx:     'fade',
    timeout:  1,
	continuous: 1,
	random: 1,
	pause:  0,
	delay:         1,
	cleartype:true    
});
});
$(document).ready(function() {
    $('.flames4').cycle({ 
    fx:     'fade',
    timeout:  1,
	continuous: 1,
	random: 1,
	pause:  0,
	delay:         2,
	cleartype:true   
});
});

$(document).ready(function() {
    $('.slideshow').cycle({ 
    fx:     'fade',
    timeout:  6000,
	pause:  1,
	cleartype:true  
});
});


    $(function() {
        $('#gallery a').lightBox();
		
		
		// have to force IE left margin as it won't center... 

		var windowheight = $(document).height();
		var windowwidth = $(document).width();
		var myLefty = (windowwidth -1000) / 2;  			
		var myLeftyFooter = myLefty -49;					
											
		// $("#container").css("margin-left", myLefty + "px");
		// $("#footer").css("margin-left", myLeftyFooter + "px");								
		
    });
	
	

	$(function() {
		$('.dateField').datepicker({
			changeMonth: true,
			changeYear: true,
			maxDate: '-18Y',
			dateFormat: 'd/MM/yy'
		});
		$('.dateFieldFunctions').datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'd/MM/yy'
		});		

	});
