/* Author: 
	sn0lan
*/

 function initialize() {
    var latlng = new google.maps.LatLng(51.51726, -0.15784);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("google-map"),
        myOptions);

	var image = new google.maps.MarkerImage('img/map-icon.png',
      // This marker is 20 pixels wide by 32 pixels tall.
      new google.maps.Size(40, 57),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(20, 56));
      
	var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon: image
    });
  }

  jQuery(function($){

    if ($('.menu-holder').is(":visible")) {
      $('.menu-holder h2').live('click', function(){
        if (!$(this).parent().children('div').is(":visible")) {
          $('.menu-holder div:visible').slideUp();
          $(this).parent().children('div').slideDown();
        } else {
          $('.menu-holder div:visible').slideUp();
        };
      })
    };

    $('input[type=text]').live('focusin',function(){
      if ($(this).val()==$(this).attr('title')) {
        $(this).val('');
      };
    }).live('focusout',function(){
      if ($(this).val()=="") {
        $(this).val($(this).attr('title'));
      };
    })

    $('.transition img:not(":first")').hide();
    var count=0;
    var countImages = $('.transition img').size();

    if(countImages>1){
      setInterval(nextImage,4000); //The number here dictates the length of time between the animation
    }

    function nextImage() {
      $('.transition img:eq('+count+')').fadeOut(1500); //Length of FadeOut transition
      if(count<countImages-1){
        count++;
      } else {
        count=0;
      }
      $('.transition img:eq('+count+')').fadeIn(1500); //Length of FadeIn transition
    }

    ////

    $('.offer-container article:not(":first")').hide();
    var offerCount=0;
    var countOffers = $('.offer-container article').size();

    if(countOffers>1){
      setInterval(nextOffer,3000); //The number here dictates the length of time between the animation
    }

    function nextOffer() {
      $('.offer-container article:eq('+offerCount+')').fadeOut(1500); //Length of FadeOut transition
      if(offerCount<countOffers-1){
        offerCount++;
      } else {
        offerCount=0;
      }
      $('.offer-container article:eq('+offerCount+')').fadeIn(1500); //Length of FadeIn transition
    }


  	if ($('#contact').size()>0) {
  		initialize();
  	};

    if ($('#gallery').size()>0) {
      $(".gallery li a").prettyPhoto();
    };

    
    $(".signup-show").click(function (e){
      e.preventDefault();
      $(".signupform").animate({
        width: 370
      });
    });

    $(".signupform a.closebtn").click(function (e){
      e.preventDefault();
      $(".signupform").animate({
        width: 0
      });
    });

    $(".room-rates").not(":first").hide();

    $("#room-rates h2").click(function(){
      $(".room-rates:visible").slideUp();
      $(this).next().slideDown();
    });
	
	$(".room-sub-nav").hide();
    $(".sub-nav").mouseenter(function (e){
      e.preventDefault();
	  
	  $(".room-sub-nav").fadeIn();
	  e.stopPropagation();
	  });
	$(".sub-nav").mouseleave(function (e){
      e.preventDefault();
	  
	  $(".room-sub-nav").fadeOut();
	  e.stopPropagation();
	  });

    $(".more").hide();
    $(".readmore").click(function (e){
      e.preventDefault();
      $(this).next().slideDown();
      $(this).hide();
    });

    $(".readless").click(function (e){
      e.preventDefault();
      $(this).parent().slideUp();
      console.log($(this).parent().parent().find(".readmore"));
      $(this).parent().parent().find(".readmore").show();
    });
;
    if ($('#check-availability input').size() > 0) {
    currentSelection = $('#check-availability form').attr('action')
      $( "#check-availability input.textbox" ).datepicker({
          "dateFormat":"d M yy"
          // onSelect: function(dateText, inst) {
          //   $('#check-availability form').attr('action', currentSelection + '?' +dateText.replace(' ','+').replace(' ','+'))
          // }
        });
    };

    //Fancybox
    $('#virtual-tour').fancybox({
      'type' : 'iframe',
      'autoScale' : true,
      'transitionIn'    : 'elastic',
      'transitionOut'   : 'elastic',
      'autoDimensions'  : false,
      'width'           : 970,
      'height'          : 385
    });
  })
