function setupHomepageMarquee() {
  $("#slideshow_image>ul").marquee({
    autoPlay: true,
	effect: {
      delay: 0,         /* For 'fade', delay after fadeOut and before fadeIn */
      easing: "swing",  /* The style of animation */
      name: "slide",    /* just slide or fade at the moment. specifying anything else will do show/hide with the easing parameter */
      speed: 1200        /* The speed of the animation */
    },
	interval: 5000,     /* Time interval between transitions. */
    beforeNext: function( activeIndex, nextIndex, dir ) {
      $("#slideshow_left_banner li").eq(activeIndex).fadeOut(600);
      $("#slideshow_left_banner li").eq(nextIndex).fadeIn(600);
    }
  });
  $("#slideshow_menu a").each(function( i ) {
    $(this).click(function() {
      $("#slideshow_menu li").removeClass("active");
      $(this).closest("li").addClass("active");
      $(".frame_wrapper").trigger("jump", i);
      return false;
    });
  });
  $("#slideshow_left_banner li:first").show();
}


function setupCountryMarquee() {
  $("#country_slider_top_feature>.slideshow").marquee({
    autoPlay: false,
    afterNext: function( activeIndex, nextIndex, dir ) {
      $("#country_slider_top_feature .info>li").eq(activeIndex).fadeOut(600);
      $("#country_slider_top_feature .info>li").eq(nextIndex).fadeIn(600);
    }
  });
  $("#country_selector>ul>li>a").each(function( i ) {
    $(this).click(function() {
      $("#country_selector a").removeClass("active");
      $(this).addClass("active");
      $("#country_slider_top_feature .frame_wrapper").trigger("jump", i);
      return false;
    });
  });
  $("#country_slider_top_feature .info>li:first").show();
}


$(document).ready(function(){
	
  setupHomepageMarquee();
  setupCountryMarquee();
  $(".profile_text_pic p:last, .profile_text p:last").addClass("p_last");
	 $("#profile_left_content li:last").addClass("p_last");
	 

	$(".right_sidebar_button:last").addClass("right_sidebar_button_last");

	
	//COUNTRY DROPDOWN
	function clickOutsideOtherCountries() {
    $("#profile_left_country_header_view_other_countries>.profile_left_country_dropdown").hide();
    $(document).unbind("click", clickOutsideOtherCountries);
  }
		
  $("#profile_left_country_header_view_other_countries>.profile_left_country_dropdown").click(function( event ) {
    return false;
  });
  
  $("#profile_left_country_header_view_other_countries>a").click(function() {
    $("#profile_left_country_header_view_other_countries>.profile_left_country_dropdown").show();
    $(document).unbind("click", clickOutsideOtherCountries).click(clickOutsideOtherCountries);
    return false;
  });
	
	  $("#profile_left_country_header_view_other_countries>.profile_left_country_dropdown a").click(function( event ) {
    window.location = $(this).attr("href");
  });
  
  
  $(".country_dropdown_top>.country_dropdown_top_ghost").click(function() {
    $("#profile_left_country_header_view_other_countries>.profile_left_country_dropdown").hide();
    return false;
  });
	
	//TOUR DROPDOWN
	function clickOutsideOtherTours() {
    $("#profile_left_country_header_view_other_tours>.profile_left_tour_dropdown").hide();
    $(document).unbind("click", clickOutsideOtherTours);
  }
		
  $("#profile_left_country_header_view_other_tours>.profile_left_tour_dropdown").click(function( event ) {
    return false;
  });
  
  $("#profile_left_country_header_view_other_tours>.profile_left_tour_dropdown a").click(function( event ) {
    window.location = $(this).attr("href");
  });
  
  $("#profile_left_country_header_view_other_tours>a").click(function() {
    $("#profile_left_country_header_view_other_tours>.profile_left_tour_dropdown").show();
    $(document).unbind("click", clickOutsideOtherTours).click(clickOutsideOtherTours);
    return false;
  });
  
  $(".tour_dropdown_top>.tour_dropdown_top_ghost").click(function() {
    $("#profile_left_country_header_view_other_tours>.profile_left_tour_dropdown").hide();
    return false;
  });
  
	
  var $profileRightInner = $("#profile_right_inner");
  $("#right_tour_container .right_tour_container_entity_right_cta").each(function() {
    var $ctr = $(this),
        $cta = $(this).children("a"),
        $flyout = $(this).children(".flyout"),
        $close = $flyout.find(".close"),
        $wrapper = $("<div class='flyout_wrapper'></div>");
    function hideFlyout() {
      $flyout.unbind("hide.flyout");
      $flyout.animate({ left: $wrapper.width() }, 300, 'swing', function() {
        $flyout.removeClass("open").hide();
        $cta.after($flyout);
        $wrapper.remove();
      });
      return false;
    }
    function showFlyout() {
      if($flyout.is(".open")) {
        return false;
      }
      $(".flyout.open").each(function() {
        $(this).triggerHandler("hide");
      });
      $("body").append($wrapper);
      $wrapper.append($flyout);
      $wrapper.css({
        left: $profileRightInner.offset().left - $flyout.outerWidth(),
        position: "absolute",
        top: $ctr.parent().offset().top
      });
      $flyout.css({ left: $wrapper.width(), top: 0 }).show().animate({ left: 0 }, 300, 'swing', function() {
        $flyout.addClass("open");
      });
      return false;
    }
    $close.click(hideFlyout);
    $cta.click(showFlyout);
    $flyout.bind("hide", hideFlyout);
  });
  
  
  $("#menu_container>ul").hovermenu({ speed: 200 });
  
  $("#expanded_customize_form").hide();
  $("#expanded_form_submitted_message").hide();
  
  $("#simple_customize_form").submit(function() {
    var $form = $(this);
    $.post($form.attr("action"), $form.serialize(), function( data ) {
      data = $.parseJSON(data);
      if(data.success) {
        $form.slideUp();
        $("#expanded_customize_form").fadeIn(600);
      } else {
        alert(data.error);
      }
    });
    return false;
  });
  
  $("#expanded_customize_form").submit(function() {
    var $form = $(this);
    var params = $.param($.extend($("#simple_customize_form").serializeArray(), $form.serializeArray()));
    $.post($form.attr("action"), params, function( data ) {
      data = $.parseJSON(data);
      if(data.success) {
        $("#expanded_customize_form").slideUp();
        $("#expanded_form_submitted_message").fadeIn(600);
      } else {
        alert(data.error);
      }
    });
    return false;
  });
  
  $("#contact_form_submitted_message").hide();
  $("#contact_form").submit(function() {
    var $form = $(this);
    var params = $form.serializeArray();
    $.post($form.attr("action"), params, function( data ) {
      data = $.parseJSON(data);
      if(data.success) {
        $("#contact_form").slideUp();
        $("#contact_form_submitted_message").fadeIn(600);
      } else {
        alert(data.error);
      }
    });
    return false;
  });
  
  $("input[type=text].date").datepicker({
    changeMonth: true,
    changeYear: true
  });
  
  $("[data-example]").example(function() {
    return $(this).attr("data-example");
  });
  
  $(".accordian, .accordion").accordion({
    autoHeight: false
  });
});
