/*
(function($) {
    $.fn.equalizeCols = function(children) {
        var child = Array(0);
        if (children) child = children.split(",");
        var maxH = 0;
        this.each(
      function(i) {
          if (this.offsetHeight > maxH) maxH = this.offsetHeight;
      }
    ).css("height", "auto").each(
      function(i) {
          var gap = maxH - this.offsetHeight;
          if (gap > 0) {
              t = document.createElement('div');
              $(t).attr("class", "fill").css("height", gap + "px");
              if (child.length > i) {
                  $(this).find(child[i]).children(':last-child').after(t);
              }
              else {
                  $(this).children(':last-child').after(t);
              }
          }
      }
    );

    }
})(jQuery);
*/

//jQuery.fn.fadeToggle = function(speed, easing, callback) {
//    return this.animate({ opacity: 'toggle' }, speed, easing, callback);
//};
jQuery.fn.fadeToggle = function(speed, easing, callback) {
    var op = $(this).css('opacity');
    return this.animate({ opacity: op != 0.1 ? 0.1 : 1.0 }, speed, easing, callback);
};


$(function() {

    // do something on document ready
    $(".ROTATORCONTAINER .ROTATORTITLE").click(function() {
        $(this).parent().children(".MainSwapper").toggle();
    });
    $(".COLUMNCONTAINER .ROTATORTITLE").click(function() {
        $(this).parent().children(".MainSwapper").toggle();
    });

    $(".COLUMNLEFT .COLUMNTITLE").click(function() {
        $(this).parent().children(".COLUMNBOX").toggle();
    });

    $('.MAINROTATOR .MainSwapper').cycle({
        fx: 'scrollRight',
        speed: 'fast',
        timeout: 10000,
        delay: -2000,
        pause: 1,
        pager: '#SwapNavigation'
    });
    if ($('.datepicker').length > 0) {
        $('.datepicker').datepicker({
            minDate: 0,
            maxDate: 730,
            showOn: 'both',
            changeMonth: true,
            changeYear: true,
            changeFirstDay: false,
            closeText: 'X',
            dateFormat: 'dd.mm.yy',
            firstDay: 1,
            showAnim: 'show',
            duration: '',
            buttonImage: '/App_Themes/Fibula/js/calendar.gif',
            buttonImageOnly: true
        });
    }

    if ($('.datepickerflight').length > 0) {
        $('.datepickerflight').datepicker({
            minDate: 0,
            maxDate: 730,
            showOn: 'both',
            changeMonth: true,
            changeYear: true,
            changeFirstDay: false,
            closeText: 'X',
            dateFormat: 'dd.mm.yy',
            firstDay: 1,
            showAnim: 'show',
            duration: '',
            buttonImage: '/App_Themes/Fibula/js/calendar.gif',
            buttonImageOnly: true
        });
    }

    if ($('.datepickerflightRet').length > 0) {
        $('.datepickerflightRet').datepicker({
            minDate: 0,
            maxDate: 730,
            showOn: 'both',
            changeMonth: true,
            changeYear: true,
            changeFirstDay: false,
            closeText: 'X',
            dateFormat: 'dd.mm.yy',
            firstDay: 1,
            showAnim: 'show',
            duration: '',
            buttonImage: '/App_Themes/Fibula/js/calendar.gif',
            buttonImageOnly: true
        });
    }




    //$(".COLUMNLEFT, .COLUMNRIGHT").equalizeCols();

    $('.HOTELBOX').hover(function() {
        $(this).addClass('pretty-hover');
    }, function() {
        $(this).removeClass('pretty-hover');
    });

    $(".HOTELBOX").click(function() {
        window.location = $(this).find("a.clickableLink").attr("href");
        return false;
    });

    $("div#contentWide div.RotatorMainPageRightTheme .clickable").click(function() {
        //alert($(this).parent().parent().find("a.hlnkShowAll").attr("href"));
        window.location = $(this).parent().parent().find("a.hlnkShowAll").attr("href");
        return false;
    });


    if ($('#TabbedUISearchBox').length > 0) {
        $("#TabbedUISearchBox").tabs();
    }

    if ($('#TabbedUI').length > 0) {
        $("#TabbedUI").tabs();
    }

    Shadowbox.init({
        resizeDuration: 0.05,
        fadeDuration: 0.05
    });
    $(".stripes tr").mouseover(function() { $(this).addClass("over"); }).mouseout(function() { $(this).removeClass("over"); });
    $(".stripes tr:even").addClass("alt");

    //	$("div.MainPageTopHotelBox").click(function(){
    //		$("div.MainPageTopSearchBox").fadeTo("fast", 0.1);
    //	},function(){
    //		$("div.MainPageTopSearchBox").fadeTo("fast", 1);
    //	});
    //	
    //	$("div.MainPageTopSearchBox").click(function(){
    //		$("div.MainPageTopHotelBox").fadeTo("fast", 0.1);
    //	},function(){
    //		$("div.MainPageTopHotelBox").fadeTo("fast", 1);
    //	});

    $("div.MainPageTopHotelBox").click(function() {
        if ($('input.selectoneRadioNo1').attr('checked')) {

            $("<div class='MainPageTopSearchBoxcover'></div>").prependTo("div.MainPageTopSearchBox div.Box");
            $("div.MainPageTopSearchBoxcover").fadeTo("fast", 1);
            $("div.MainPageTopSearchBox div.Box select").hide();

            $("div.MainPageTopHotelBoxcover").fadeTo("fast", 0);
            $("div.MainPageTopHotelBoxcover").remove();
        }
        else {
            $('input.selectoneRadioNo2').removeAttr('checked');
            $("div.MainPageTopSearchBoxcover").fadeTo("fast", 0);
            $("div.MainPageTopSearchBoxcover").remove();
            $("div.MainPageTopSearchBox div.Box select").show();
        }
    });

    $("div.MainPageTopSearchBox").click(function() {
        if ($('input.selectoneRadioNo2').attr('checked')) {

            $("<div class='MainPageTopHotelBoxcover'></div>").prependTo("div.MainPageTopHotelBox div.Box");
            $("div.MainPageTopHotelBoxcover").fadeTo("fast", 1);

            $("div.MainPageTopSearchBoxcover").fadeTo("fast", 0);
            $("div.MainPageTopSearchBoxcover").remove();
            $("div.MainPageTopSearchBox div.Box select").show();
        }
        else {
            $('input.selectoneRadioNo1').removeAttr('checked');
            $("div.MainPageTopHotelBoxcover").fadeTo("fast", 0);
            $("div.MainPageTopHotelBoxcover").remove();
        }
    });

    //    $("div.MainPageTopSearchBox").click(function() {
    //        if ($('input.selectoneRadioNo2').attr('checked')) {
    //            $("div.MainPageTopHotelBox .HotelSearchBoxTable").fadeTo("fast", 0.1);
    //            $("div.MainPageTopSearchBox .pnlSearchBox").fadeTo("fast", 1);
    //        }
    //        else {
    //            $('input.selectoneRadioNo2').attr('checked', 'true');
    //            $("div.MainPageTopHotelBox .HotelSearchBoxTable").fadeTo("fast", 1);
    //        }
    //    });



});
