/* === HOME ANIMATION === */

(function($) {
    
    $.fn.transition = function(css, options) {
        return this.each(function(){
            var $el = $(this);
            var defaults = {
                duration : 300,
                complete: function(){},
                easing: 'linear'
            };
            var settings = $.extend({}, defaults, options);
            if(settings.duration === 0) {
                $el.css(css);
                window.setTimeout(settings.complete, 0);
            } else {
                if ($.browser.safari)
                {
                    var s = [];
                    for(var i in css) {
                        s.push(i);
                    }
                    $el.css({
                        webkitTransitionProperty: s.join(", "), 
                        webkitTransitionDuration: settings.duration+'ms', 
                        webkitTransitionTimingFunction: settings.easing
                    });
                    if (settings.complete) {
                        $el.one('webkitTransitionEnd', settings.complete);
                    }
                    setTimeout(function(el){ el.css(css) }, 0, $el);
                }
                else
                {
                    $el.animate(css,{duration:settings.duration,complete:settings.complete});
                }
            }
        });
    }
})(jQuery);

	$(document).ready(function(){
		//1 = rsh - 2 = ldb - 3 = maya
		var images = [
						
						{image:'/i/SITE_110830_13551159_1DP1V/templates/home2.jpg',link:'/locations/virgin_gorda_bvi/',smallimage:'/i/SITE_110830_13551159_1DP1V/templates/home2.gif'},
						{image:'/i/SITE_110830_13551159_1DP1V/templates/home3.jpg',link:'/locations/riviera_maya_mexico/',smallimage:'/i/SITE_110830_13551159_1DP1V/templates/home3.gif'}
					];
		
		var w = $(window);
		var l = $('.largeImage');
		var s = $('.awardText');
		/* Cache the other images */
		for(var i in images){
			var l2 = l.clone();
			var s2 = s.clone();
			l2.find('img').attr('src',images[i].image);
			
			s2.find('a').attr('href',images[i].link);
			s2.find('img').attr('src',images[i].smallimage);
			s2.find('img').hide().css('z-index', 2);
			
			l.before(l2);
			s.before(s2);
		}
		l.addClass('active');
		s.addClass('active');
		
		var lI = $('.largeImage img');
		var maxH = $('.bar').height();
		if(lI.length==0){
			lI = $('.largeImagesub img');
			maxH = $('.barsub').height();
		}
		var resizeFunc = function(){
			var wi = $(document.body).width();
			var lIh = lI.height();
			var lIw = lI.width();
			if( (lIh / lIw) * wi < maxH )
				wi = (lIw / lIh) * maxH;
			lI.width(wi);
                         //[RSG]
                        lI.css({'margin-top':'-'+ parseInt((lIh-449)/2) +'px'});
		};
		w.resize(resizeFunc);
		w.load(resizeFunc);
		
		
		l = $('.largeImage');
		var moveNext = function(){
			var current = $('.largeImage.active');
			var next = current.next('.largeImage');
			
			var tCurrent = $('.awardText.active');
			var tnext = tCurrent.next('.awardText');
			
			if(next.length==0)next = $('.largeImage:first');
			current.css('z-index',2);
			next.css('z-index',1);
			
			if(tnext.length==0)tnext = $('.awardText:first');
			tCurrent.css('z-index',2);
			tnext.css('z-index',1);
			
			
			
			if($.browser.webkit){
				current.delay(4000).queue(function(){
                    current.css({
                        webkitTransitionProperty: 'opacity', 
                        webkitTransitionDuration: '1000ms', 
                        webkitTransitionTimingFunction: 'linear'
                    }).one('webkitTransitionEnd', function(){
						current.css('z-index',0).css({webkitTransitionProperty:'none',opacity:1});
						current.dequeue();
						tCurrent.find('img').hide().css('z-index', 0);
						tCurrent.removeClass('active');
						tnext.find('img').show().css('z-index', 2);
						tnext.addClass('active');
						moveNext();
					}).css({
						opacity: 0
					});
					
				});
			}else{
				current.find('img').delay(4000).fadeOut({duration:1000,easing:'linear',complete:function(){
					current.css('z-index',0).find('img').show();
					tCurrent.find('img').hide().css('z-index', 0);
					tCurrent.removeClass('active');
					tnext.find('img').show().css('z-index', 2);
					tnext.addClass('active');
					moveNext();
				}});
			}			
			

			current.removeClass('active');
			next.addClass('active');
		};
		moveNext();	
		
	});

/* === HOME ANIMATION === */




/* === SITE MAP ROW COLORS === */
/* $(function() {
	$(".siteMapNav li:even").addClass("dark");
}); */
/* === ENDSITE MAP ROW COLORS === */



