﻿
$(document).ready(function() {
    //$(document).pngFix(); 
    $(".delButton").each(function(i) {
        $(this).click(function() {
            return confirm("are you sure?");
        });
    });

    $('.lang').click(function() {
        $('.lang_vf>p').slideToggle(50);
        $(".lang_v p").slideToggle(50);
        $('.lang>a.curlang').toggleClass('curdn');
        //        return false;
    })
    $('.lang>p>a').click(function() {
        //            $itext = $(this).text();
        //            $('.lang>a.curlang>i').text($itext);
        DelCookie("languageid");
        SetCookie("languageid", $(this).attr("languageid"));
        //        if (location.href.indexOf("LanguageID=") > 0)
        //            location.href = location.href.replace(/LanguageID=[0-9]+/g, "LanguageID=" + $(this).attr("languageid"));
        //        else {
        //            if (location.href.indexOf("#") > 0)
        //                location.href = location.href.replace(/#.*/g, "");
        //            else
        //                location.reload();
        //        }
        //return false;
    });
    /* reserv reservbtn */
    formatReservBtn();

    /**navThemID=2**/
    mainmenu();

    /*Rooms Num*/

    $('.roomnum').toggle(
			  function() { $(this).find('span').slideDown(0); },
			  function() { $(this).find('span').slideUp(0); }
			  ).find("span>a").click(function() {
			      $(this).parent().prev().val($(this).text());
			  });
    /* for article sub sub nav 2009-12-30 */
    $("div.hb_fragContent>.subtab>a").each(function(i) {
        $(this).click(function() {
            $(this).parent().find("a").removeClass("curr");
            $(this).addClass("curr");
            $("div.hb_fragContent>div.subContent>div.hb_subcontent").hide().eq(i).show();
            return false;
        });
    });

    /* ysmr template nav show hide() */
    $('div.nav').hover(function() {
    }, function() {
        $('div.nav>div').hide(); $('div.nav>a').removeClass("navhover");
        $("#gallery").stop(true, false).fadeTo("slow", 1);
    });
    $('div.nav>a').each(function(i) {

        if ($(".nav").hasClass("vertical")) {
            /*make nav two cols*/

            //$(".rolloverContainter").each(function() {
            //    var li_num = $(this).find("li").length;
            //    if(li_num>5) {
            //        $(this).find("ul").after("<ul></ul>");
            //        $(this).find("ul").eq(0).find("li:gt(4)").appendTo($(this).find("ul").eq(1)); 
            //    }    
            //});


            $(this).hover(function() {
                $(this).siblings("div").hide();
                $('div.nav>a').removeClass("navhover");
                $("#gallery").stop(true, false).fadeTo("slow", 1);

                if ($(this).hasClass("drop")) {
                    $(this).siblings("div").hide().eq(i).show();

                    $('div.nav>a').removeClass("navhover");
                    $(this).addClass("navhover");
                    $("#gallery").stop(true, false).fadeTo("slow", 0.3);

                    $(this).addClass("curr").siblings("a").removeClass("curr");
                    var i = $(".nav>a").index(this);

                    $(this).siblings("div").hide().eq(i).show().css("left", $(this).offset().left);     /*new drop menu */
                    //if miniScreen 
                    var posx = $(this).offset().left + $(this).siblings("div").eq(i).outerWidth(false) - $("body").width();
                    if (posx > 0) {
                        $(this).siblings("div").eq(i).css("left", $(this).offset().left - posx);
                    }
                }
            }, function() {
                // $(this).siblings("div").fadeOut(500);
            });


            $(".rolloverContainter").each(function() {
                $(this).find("li").mouseover(function() {
                    $(this).parent().parent().find("img").attr("src", $(this).attr("pic"));
                });
            });


        }
        else if ($(".nav").hasClass("horizontal")) {

            $(this).hover(function() {
                $(this).siblings("div").hide();
                $("#gallery").stop(true, false).fadeTo("slow", 1);

                $("#gallery").stop(true, false).fadeTo("slow", 0.3);


                $(this).addClass("curr").siblings("a").removeClass("curr");
                var i = $(".nav>a").index(this);

                $(this).siblings("div").fadeOut(50).eq(i).fadeIn(50).find("img:first").css("left", $(this).offset().left - $('div.nav').offset().left + $(this).outerWidth(false) / 2);
                $(this).siblings("div").hide().eq(i).show().css("left", $(".nav>a:first").offset().left-1); /* old drop menu */
            }, function() {
                //$(this).siblings("div").fadeOut(500);
            });
        }

        else { return false; }
    });







    /*text-overflow:ellipsis*/
    $(".roomSegList .roomItem .links dd").each(function() {
        if ($(this).text().length > 30) {
            $(this).attr("title", $(this).text());
            var str = $(this).text().substring(0, 27) + "...";
            $(this).html(str);
        }
    });

});

     

function formatReservBtn() {
    $('a.reservbtn').click(function() {
        var parm = "";
        var tUrl = "/Reservations/Default.aspx"; //$(this).attr("href");//promotioncode
        parm += "segmentid=" + $(this).attr("segmentid");
        parm += "&check_in=" + $("div.qReserve input[name='date1']").val();
        parm += "&check_out=" + $("div.qReserve input[name='date2']").val();
        parm += "&numberofnights=" + $("div.qReserve select[name='numberofnights']").val();
        parm += "&numberofrooms=" + $("div.qReserve select[name='numberofrooms']").val();
        if (undefined != $("input[name='promotioncode']").val() && "undefined" != $("input[name='promotioncode']").val())
        parm += "&promotioncode=" + $("input[name='promotioncode']").val();
        parm = parm.replace(/=undefined/g,"=");
        tUrl += "?" + parm;
        $(this).attr("href", tUrl);
    });
}

/**navThemID=2**/
function mainmenu() {
    $(" #nav ul ").css({ display: "none","z-index":"100","position":"absolute" }); // Opera Fix
    $(" #nav li").hover(function() {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show(400);
    }, function() {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });
}

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

  // Create a cookie with the specified name and value.
  // The cookie expires at the end of the 20th century. 
  function SetCookie(sName, sValue) {
      date = new Date(2099,12,31);
      document.cookie = sName + "=" + escape(sValue) + "; path=/; expires=" + date.toGMTString();
      //document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT; domain=/; path=/";
  }
  // Retrieve the value of the cookie with the specified name.
  function GetCookie(sName) {
      // cookies are separated by semicolons
      var aCookie = document.cookie.split("; ");
      for (var i = 0; i < aCookie.length; i++) {
          // a name alue pair (a crumb) is separated by an equal sign
          var aCrumb = aCookie[i].split("=");
          if (sName == aCrumb[0])
              return unescape(aCrumb[1]);
      }
      // a cookie with the requested name does not exist
      return null;
  }
  // Delete the cookie with the specified name.
  function DelCookie(sName) {
      document.cookie = sName + "=; expires=Fri, 31 Dec 1900 23:59:59 GMT";
  }





  /**Location Right Menu**/
  function LocationPOIlistStyleShow() {
      $(".locRbar>dl>dt").toggle(function() {
          $(this).addClass('up').siblings('dd').slideUp(100);
      }, function() {
          $(this).removeClass('up').siblings('dd').slideDown(50);

      });
  }
  function LocationPOIlistStyleHide() {
      /**Location Right Menu**/
      $(".locRbar>dl:not(.topmenu)>dd").hide();
      $(".locRbar>dl:not(.topmenu)>dd").eq(0).show();
      $(".locRbar>dl:not(.topmenu)>dt").addClass("up");
      $(".locRbar>dl:not(.topmenu)>dt").eq(0).removeClass("up");

      $(".topmenu>dt").click(function() {
          if ($(this).attr("class").indexOf("up")>0) {
              $(this).siblings("dd").slideDown(50);
              $(this).removeClass("up");
          }
          else {
              $(this).siblings("dd").slideUp(100);
              $(this).addClass("up");
          }
      });
      $(".locRbar>dl:not(.topmenu)>dt").click(function() {
          if ($(this).attr("class").indexOf("up")) {
              $(this).parent("dl").siblings("dl:not(.topmenu)").find("dd").slideUp(100).siblings("dt").addClass("up");
              $(this).siblings("dd").slideDown(50);
              $(this).removeClass("up");
          }
          else {
              $(this).siblings("dd").slideUp(100);
              $(this).addClass("up");
          }
      });
  }