BROWSER = new Object();
BROWSER.isOpera = navigator.userAgent.indexOf("Opera") > -1;
BROWSER.isIE    = navigator.userAgent.indexOf("MSIE") > 1 && !BROWSER.isOpera; 
BROWSER.isMoz   = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !BROWSER.isOpera;

if (typeof($) != "function") $ = function(ID){ return document.getElementById(ID); }

function redirect(id) {
   alert("This link works only in front-end site!")
}

function popupimg(img) {
    var d = new Date()
    var ID = d.getDate()+""+d.getMonth()+1+""+d.getFullYear()+""+d.getHours()+""+d.getMinutes()+""+d.getSeconds();

    var loc = "/enlarge.php?src="+img;
	var win = window.open(loc, "_new"+ID,"toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=200,height=200");
	win.location.href = loc;
	win.focus();
}

/* highlist elements onmouse over event
 */
function highlight(groupElements, classOver) {
   var i, j, Obj, groupObjects = [];
   for(j=1; j<100; j++) {
   	   for(i in groupElements) {
   	   	   Obj = $(groupElements[i]+j);
           if (Obj) {
               Obj.ind = j; 
               groupObjects[groupObjects.length] = Obj;
           }
       }
   }
   
   for(i in groupObjects) {
      Obj = groupObjects[i];
      Obj.classDefault = Obj.className;
      Obj.classOver = classOver;
      Obj.groupObjects = groupObjects;
      
      Obj.onmouseover = function() {
      	  this.className = this.classOver;
      	  for(var i in this.groupObjects){
      	      var Obj = this.groupObjects[i]; 
      	  	  if (Obj.ind == this.ind) Obj.className = Obj.classOver;
      	  }
      }
      Obj.onmouseout = function() {
      	  this.className = this.classDefault;
      	  for(var i in this.groupObjects){
      	  	  var Obj = this.groupObjects[i];
      	  	  if (Obj.ind == this.ind) Obj.className = Obj.classDefault;
      	  }
      }
   }
}

function openLink(link) {
   location.href = link;
}

function showVideoCode(boxID) {
    var html = $("#"+boxID).html();
    $("#"+boxID).html("");
    $("#"+boxID).html(html);
}

function showVideoFile(boxID, videoFile){
    swfobject.embedSWF("/flash/mediaplayer.swf?file="+videoFile+"&skin=/flash/sheraton-skin.swf", boxID, "300", "200", "8.0.0", "/js/swfobject/expressInstall.swf", 
                       {width:"300", height:"200", autostart:false}, 
                       {allowfullscreen:"true", wmode:"transparent"},
                       {'id':boxID , 'name':boxID});
}

function showAudioFile(boxID, videoFile){
    swfobject.embedSWF("/flash/mediaplayer.swf?file="+videoFile, boxID, "300", "20", "8.0.0", "/js/swfobject/expressInstall.swf", 
                       {width:"300", height:"20", autostart:false}, 
                       {allowfullscreen:"true", wmode:"transparent"}, 
                       {'id':boxID , 'name':boxID});
}

function playAudio(objID) {
   var Obj = document.getElementById(objID)
   
   // JW player v.4 play
   if (typeof Obj.sendEvent != "unknown") Obj.sendEvent("PLAY"); 

   // JW player v.5.1
   // if (typeof Obj.play != "unknown") Obj.play();
}

function jsRedirect(url) {
    window.location.href = url;
}

function pad(n){
    return (n<10)?'0'+n:n; 
}

function submitReservationForm(reservationForm){
    
    $("form[name=reservation-form] input[name=reservation_form_night]").parent().removeClass("err");
    
    var numberNights = parseInt($("form[name=reservation-form] input[name=reservation_form_night]").val());
    if(numberNights>0){

        var departureDateArr = $("form[name=reservation-form] input[name=arrivalDate]").val().split("-");
        
        var departureDate = new Date();
        
        departureDate.setYear(departureDateArr[0]);
        departureDate.setMonth(departureDateArr[1]-1);
        departureDate.setDate(departureDateArr[2]);
        
        departureDate.setDate(departureDate.getDate()+numberNights);
        
        var departureDateString = departureDate.getFullYear()+"-"+pad(departureDate.getMonth()+1)+"-"+pad(departureDate.getDate());
        
        $("form[name=reservation-form] input[name=departureDate]").val(departureDateString);
        
        return true;
        
    }else{
        
        $("form[name=reservation-form] input[name=reservation_form_night]").parent().addClass("err");
        
        return false;
    }    
    return false;    
}

$(document).ready(function() {
    $("a.fancyboxBrochure").fancybox({'autoScale':false, 'width':800, 'height':600,'overlayOpacity':0.8, 'titlePosition':'inside', 'hideOnOverlayClick':false,'centerOnScroll':true});
    
    var browserOldIE = false;
    
//    if ( $.browser.msie && ($.browser.version.substring(0, 1) == 6 || $.browser.version.substring(0, 1) == 7 )) {
//      browserOldIE = true;
//    }
    
    //fancybox
    $("a.textImage").fancybox({'overlayOpacity':0.8,'titlePosition':'inside'});
    
    //reservation form
    $("a#reservation-form-link").click(function() {
        if($("#reservation-form-content").is(":hidden")){
            if(browserOldIE){
                $("#reservation-form-content").show();
            }else{
                $("#reservation-form-content").slideDown();
            }
            $("a#reservation-form-link").addClass("itemLinkActive");
            $("a#reservation-form-link").addClass("open");
        }else{
            if(browserOldIE){
                $("#reservation-form-content").hide();
            }else{
                $("#reservation-form-content").slideUp();
            }
            $("a#reservation-form-link").removeClass("itemLinkActive");
            $("a#reservation-form-link").removeClass("open");
        }
    return false;
    });
    
    //e-brochure
    $("a#e-brochure-link").click(function() {
        if($("#e-brochure-content").is(":hidden")){
            if(browserOldIE){
                $("#e-brochure-content").show();
            }else{
                $("#e-brochure-content").slideDown();
            }
            $("a#e-brochure-link").addClass("itemLinkActive");
            $("a#e-brochure-link").addClass("open");
        }else{
            if(browserOldIE){
                $("#e-brochure-content").hide();
            }else{
                $("#e-brochure-content").slideUp();
            }
            $("a#e-brochure-link").removeClass("itemLinkActive");
            $("a#e-brochure-link").removeClass("open");
        }
    return false;
    });
    
    //location
    $("a#location-link").click(function() {
        if($("#location-content").is(":hidden")){
            if(browserOldIE){
                $("#location-content").hide();
            }else{
                $("#location-content").slideDown();
            }
            $("a#location-link").addClass("itemLinkActive");
            $("a#location-link").addClass("open");
        }else{
            if(browserOldIE){
                $("#location-content").show();
            }else{
                $("#location-content").slideUp();
            }
            $("a#location-link").removeClass("itemLinkActive");
            $("a#location-link").removeClass("open");
        }
    return false;
    });
    
    //load send to a friend form in fancy box
    $("a#sendToAFriendButton").fancybox({
        'overlayOpacity':0.8,
        'titlePosition':'inside',
        'hideOnOverlayClick':false,
        'centerOnScroll':true,
        'type':'ajax',
        'href':'/_ajaxSendToAFriendMail.php?currentLang='+currentLang+'&currentPage='+currentPage,
        'onComplete':function(){
            $("#sendToAFriend").bind("submit", function(){
                sendToAFriendFormSubmit();
                return false;
            });
        }
    });
    
});

function sendToAFriendFormSubmit(){

    $.fancybox.showActivity();

    $("#fancybox-inner").fadeOut("fast");
    
    $.ajax({
        type: "POST",
        url: '/_ajaxSendToAFriendMail.php?currentLang='+currentLang+'&currentPage='+currentPage,
        data: $("#sendToAFriend").serialize(),
        success: function(html){
            $.fancybox({
                'overlayOpacity':0.8,
                'titlePosition':'inside',
                'hideOnOverlayClick':false,
                'centerOnScroll':true,
                'title':$("a#sendToAFriendButton").attr("title"),
                'content':html,
                'onComplete':function(){
                    $("#sendToAFriend").bind("submit", function(){
                        sendToAFriendFormSubmit();
                        return false;
                    });
                }
            });
        }
    });
    return false;
}