/*Cufon.replace('', { hover: true, fontFamily: "DIN-Medium" });
Cufon.replace('', { hover: true, fontFamily: "DIN-Bold" });
Cufon.replace('', { hover: true, fontFamily: "DIN-Regular" });
*/
$(function(){
    // Menu
    $('#header ul').find('> li').has("ul").hover(function(){
        $("#header ul li").removeClass("hover");
        $(this).addClass("hover").find('ul').show();
    }, function(){
        $("#header ul li").removeClass("hover");
        $(this).find('ul').hide();
    });
    
    // Forms & Labels
    // Hide overlay on focus
    $("input.text").focus(function() {
        $(this).prev("label.overlay").hide();
    });

    // Show overlay on blur
    $("input.text").blur(function() {
        if ($(this).attr("value") == "") {
            $(this).prev("label.overlay").show();
        }
    });

    // Focus input on overlay click ;)
    $("label.overlay").click(function() {
        $(this).next().focus();
    });

    // Hide if input box filled
    $("input.text").each(function() {
        if ($(this).attr("value") !== "")
            $(this).prev("label.overlay").hide();
    });
  
    // Carousel
    $('#slider').slides({
	    effect: "slide",
	    slideSpeed: 500,
		preload: true,
		preloadImage: 'images/loading.gif',
		play: 10000,
		hoverPause: false,
		generateNextPrev: true,
		slideEasing: "easeInBounce"
	});
	
	$("#slider").children(":not(.slides_container)").wrapAll("<div id='slider_controls'></div>").filter("a.prev").css({
	    left: -($(".pagination").width() + 50)
	}).end().filter("a").text("");
	
	$("#slider .pagination li a").text("");
	
	$('.highlights').slides({
	    effect: "fade",
	    fadeSpeed: 500,
		preload: true,
		preloadImage: 'images/loading.gif',
		play: 0,
		hoverPause: false,
		generateNextPrev: false,
		crossfade: true
	});
	
	$('.highlights .pagination li').each(function(i){
	    $(this).find("a").html($(".highlights .slide:nth-child("+(i+1)+") h3").clone());
	}).filter(':last').addClass("last");
	
    
	$("#splash #courses img").css("opacity", 0.8);
	$("#splash #courses img").hover(function(){
	    $(this).css("opacity", 1);
	}, function(){
	    $(this).css("opacity", 0.8);
	});
	
	
	// Fading Popup
	/*$("a.popup").fancybox({
        inline: true,
        overlayOpacity: 0.2,
        margin:0,
        padding:0,
        autoDimensions: false,
        width: 500,
        overlayColor: "#000000",
        transitionIn: "fade",
        transitionOut: "fade",
        titlePosition: "over"
    });
    
    // Gallery Popup
    $("a.gallery").fancybox({
        inline: true,
        overlayOpacity: 0.2,
        cyclic: true,
        margin:0,
        padding:25,
        overlayColor: "#000000",
        transitionIn: "elastic",
        transitionOut: "elastic",
        titlePosition: "over"
    });*/
	
	var _href = "";
	
    $('.sectionlarge #rssFeedDiv').rssfeed('http://www.facebook.com/feeds/page.php?id=122422727844070&format=rss20', {
            limit: 40
    }, function(data){
    data.find(".rssBody ul > li > h4 > a").each(function(){
       _href = $(this).attr("href");
    });
        $(".sectionlarge #rssFeedDiv").jScrollPane();
                
                
                
                
    });

    $(".sectionred li").each(function(){
       $(this).find(".promo").hide().end().filter(".open").find(".promo").show(); 
    });
    
    $(".sectionred li").live("click", function(){
      var _this = $(this);

      if(!_this.hasClass("open")) {
        $(".sectionred li.open").removeClass("open").find(".promo").slideUp(750, "easeInOutExpo");
        _this.addClass("open").find(".promo").slideDown(750, "easeInOutExpo");
      }
    });
    
    $(".sectionred li a.opener").click(function(e){
       e.preventDefault();
    });
    
/*
    if($("#player, #player_news").length > 0) {
      $('#player, #player_news').youTubeEmbed({
        video: "http://www.youtube.com/watch?v=50n4Hn1d4uk",
        width: 568
      });
    }
*/
    var _booking_course_id = $("#booking_course_id").val();
    var _course_option_id = $("#_course_option_id").val();

    updateCourseType($("#booking_course_type").val());

    $("#booking_course_type").live("change", function(){
      updateCourseType($(this).val());
    });

    $("#booking_course_id").live("change", function(){
      updateVenueType($(this).val());
    });
    
    function updateCourseType(option) {
      $.get("/booking/get-courses-by-type/" + option, function(data){
        $("#booking_course_id").empty().append(data);
        
        if(_booking_course_id) {
          $("#booking_course_id").val(_booking_course_id);
          _booking_course_id = null;
        }
        
        updateVenueType($("#booking_course_id").val());
      });
    }
    
    function updateVenueType(option) {
      $.get("/booking/get-course-options/" + option, function(data) {
        for (var x = 1; x <= 4; x++)
        {
          if (document.getElementById('booking_passenger_form_' + x + '_course_option_id'))
          {
            $('#booking_passenger_form_' + x + '_course_option_id').empty().append(data);

            if (document.getElementById('_passenger_' + x + '_option_id'))
            {
              var id = $('#_passenger_' + x + '_option_id').val();
              if (id)
              {
                $('#booking_passenger_form_' + x + '_course_option_id').val(id);
                $('#_passenger_' + x + '_option_id').val(false);
              }
            }
            else if (_course_option_id) {
              $('#booking_passenger_form_' + x + '_course_option_id').val(_course_option_id);
            }
          }
        }
        _course_option_id = null;
      });
    }
    
    $(".add-passenger").click(function(){
      $(".extra-passenger:hidden:first").show();
      if($(".extra-passenger:hidden").length == 0) {
        $(this).hide();
      }
      return false;
    });
    
});



