jQuery(document).ready(function() {
    
    
    var uri = window.location.pathname;
    //alert(uri.length + "("+uri+")");
    if (uri.length == 1){
        var language = window.navigator.userLanguage || window.navigator.language;
        if(language.length > 2){
            language = language.substr(0,2 + language.length - language.length);
        };
    }
    else {
        //alert(uri);
        var language = uri.substr(1,2 + uri.length - uri.length);
    //alert(language);
    }
    

    var offerAddress = "/"+language+"/offer/";
    
    jQuery(".reservationForm").load("/reservationForm/");
    //jQuery(".hotOffers").load(offerAddress);
    jQuery(".form-review").load("/reviewform/"+language);
    
    
    
    
    jQuery(".galleryDiv").hide();
    jQuery('.galleryNav li').css("color","#666");
    jQuery('.galleryNav li:first').css("color","#FFF");
    var onLoadGalleryID = jQuery('.galleryNav li:first').attr("id");
    var $loadGalleryNav = '/gallery/getGalleryNav/' + onLoadGalleryID;
    jQuery(".galleryDiv").load($loadGalleryNav, function() {
        jQuery(".galleryDiv").fadeIn("slow");
        jQuery('.imageCount ol li:first').css("color","#F7931E");
        var firstImage = jQuery('.imageCount ol li:first').attr("name");
        var img = '<img src="/template/images/gallery/' + onLoadGalleryID + '/' + firstImage + '" />';
        jQuery('.imageContent').html(img);
    });
    
    $(".selectGallery").click(function() { 
        jQuery('.galleryDiv').hide();
        var galleryID = $(this).attr("id");
        var $loadGalleryNav = '/gallery/getGalleryNav/' + galleryID;
        jQuery(".galleryDiv").load($loadGalleryNav, function() {
            jQuery(".galleryDiv").fadeIn("slow");
            jQuery('.imageCount ol li:first').css("color","#F7931E");
            var firstImage = jQuery('.imageCount ol li:first').attr("name");
            var img = '<img src="/template/images/gallery/' + galleryID + '/' + firstImage + '" />';
            jQuery('.imageContent').html(img);
        });
        jQuery('.galleryNav li').css("color","#666");
        jQuery(this).css("color","#FFF");
    });
    
    
    if ($("div.loadContactForm").length > 0){
        $("div.loadContactForm").hide();
        $("div.loadContactForm").load('/en/contactForm').fadeIn(1000);
    }
    
       
    
    
});





function theRotator() {
    //Set the opacity of all images to 0
    $('div.TopImages ul li').hide();	
    //Get the first image and display it (gets set to full opacity)
    $('div.TopImages ul li:first').show();		
//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds	
	
}

function rotate() {	
    //Get the first image
    var current = ($('div.TopImages ul li.show')?  $('div.TopImages ul li.show') : $('div.TopImages ul li:first'));
    if ( current.length == 0 ) current = $('div.TopImages ul li:first');
    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.TopImages ul li:first') :current.next()) : $('div.TopImages ul li:first'));
	
    //Un-comment the 3 lines below to get the images in random order	
    //var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = $( sibs[ rndNum ] );			

    //Set the fade in effect for the next image, the show class has higher z-index
    next.addClass('show').fadeIn();
    //Hide the current image
    current.fadeOut().removeClass('show');	
	
};
$(document).ready(function() {		
    //Load the slideshow
    //theRotator();
    rotate();
    setInterval('rotate()',4000);
});

