$(document).ready(function() {
	
	$.fn.equalCols = function(){		
		var sortNumber = function(a,b){return b - a;};
		var heights = [];		
		$(this).each(function(){
			heights.push($(this).height());
		});		
		heights.sort(sortNumber);
		var maxHeight = heights[0];		
		return this.each(function(){
			$(this).css({'height': maxHeight});
		});
	};
	
	$(function($){			   
		$('#latest, #calendar, #rewards').equalCols();
	});
	
	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	
	$('.noSelect').disableTextSelect();
	
	$("#mainMenu li").hover(
      function () {
		  $(this).addClass('hover');
		  $(this).children('.subMenu').toggle();
      }, 
      function () {
		  $(this).removeAttr('class');
		  $(this).children('.subMenu').toggle();
      }
    );
	
	$(".switchControl").click(function () { 
		$("#slider, #map").toggle();
		$("#sliderAndMapWrap .arrow").toggleClass('close');
    });
	$("#map .cross").click(function () { 
		$("#slider, #map").toggle();
    });
    
	function mycarousel_initCallback(carousel)
	{
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
	
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
	
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
		
		$(".switchControl").click(function () {
			carousel.stopAuto();
		});
	};
	function mycarousel_initCallback2(carousel)
	{
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
	
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
	
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
		
		$(".switchControl").click(function () {
			carousel.stopAuto();
		});
	};

	$('#slider').jcarousel({
        auto: 3,
        scroll: 1,
        wrap: 'both',
        initCallback: mycarousel_initCallback
    });
	$('#sliders').jcarousel({
        auto: 3,
        scroll: 1,
        wrap: 'both',
        initCallback: mycarousel_initCallback2
    });
	
	
	$('#carousel').jcarousel({
        scroll: 1,
        wrap: 'both'
    });
	$('#carousel li').hover(
		function () { 
			$(this).addClass('hover');
		},
		function () { 
			$(this).removeClass('hover');
		}
	
	);
	$('.eventsList li').hover(
		function () { 
			$(this).addClass('hover');
		},
		function () { 
			$(this).removeClass('hover');
		}
	
	);
	
								   
								   

	$("#tabs li:not(.active)").live("click", function(){
		$("#tabs li.active").removeAttr('class');
		$(this).addClass('active');
		$(".events, .promo").toggle();			
    });
	
	$(".autoclear").click(function() {
		if ($(this).val() == $(this).attr('defaultValue'))
			$(this).val("");
	}).blur(function() {
		if ($(this).val() == "")
			$(this).val($(this).attr('defaultValue'));
	}); 

	$(".expand .more").click(function () { 
      $(this).parent().find('.text-box').show(); 
	  $(this).hide();
	  $(this).parent().find(".close").show();
    });
	$(".expand .close").click(function () { 
      $(this).parent().find('.text-box').hide(); 
	  $(this).hide();
	  $(this).parent().find(".more").show();
    });
    
    /*$("#datepicker").datepicker();*/
});