function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
        // Alternatively you could use:
        // (new Image()).src = this;
    });
}

// Usage:

preload([
    'images/nav/1_zihuatanejo_ON.gif',
    'images/nav/1_sugarbeach_ON.gif'
]);

function onBefore() { 
	SwapImage(this.id);
}
function SwapImage(TheProperty){
	switch(TheProperty)
	{
	case "JAL":
	  	$("#trmimg").attr("src","/images/nav/1_rivieramaya_OFF.gif");
	  	$("#tzuimg").attr("src","/images/nav/1_zihuatanejo_OFF.gif");
	  	$("#jalimg").attr("src","/images/nav/1_sugarbeach_ON.gif");
	  break;
	case "ZUN":
	  	$("#trmimg").attr("src","/images/nav/1_rivieramaya_OFF.gif");
	  	$("#jalimg").attr("src","/images/nav/1_sugarbeach_OFF.gif");
	  	$("#tzuimg").attr("src","/images/nav/1_zihuatanejo_ON.gif");
	  break;
	}
}

$(document).ready(function() {
    $('.slideshow').cycle({
		fx: 'fade',
		timeout: 5000,
		speed: 1500,
		before: onBefore
	});

	$('.slideshow img').click(function (){
		if (jQuery(this).attr('rel').indexOf("NewWindow") != -1){
		window.open (jQuery(this).attr('rel'), '_blank');
		}else{
	      document.location.href = jQuery(this).attr('rel');
		}
	    }).css('cursor', 'pointer');

    $("#jalnav").mouseover(function(){
        $('.slideshow').cycle(0);
        $('.slideshow').cycle('pause');
        SwapImage('JAL');
    });
    $("#jalnav").mouseout(function(){
      $('.slideshow').cycle('resume');
    });

    $("#tzunav").mouseover(function(){
        $('.slideshow').cycle(1);
        $('.slideshow').cycle('pause');
        SwapImage('ZUN');
    });
    $("#tzunav").mouseout(function(){
      $('.slideshow').cycle('resume');
    });
});
