$(document).ready(function() {

	//var themepath = 'http://www.emeraldcasino.co.za/wp-content/themes/emerald/';
	var themepath = '/wp-content/themes/emerald/';

	var mycarousel_itemList = [
		{url: themepath + 'img/home/slider-1.jpg', title: 'London Clubs International'},
		{url: themepath + 'img/home/slider-2.jpg', title: 'London Clubs International'},
		{url: themepath + 'img/home/slider-4.jpg', title: 'London Clubs International'},
		{url: themepath + 'img/home/slider-3.jpg', title: 'London Clubs International'},
		{url: themepath + 'img/home/slider-5.jpg', title: 'London Clubs International'}
	];

	$.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});
		});
	};
	
	$.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).removeClass('hover');
			$(this).addClass('hover');
			//$(this).children('.subMenu').toggle();
			$(this).children('.subMenu').css("display", "inline");
		}, 
		function () {
			$(this).removeClass('hover');
			//$(this).children('.subMenu').toggle();
			$(this).children('.subMenu').css("display", "none");
		}
	);
	// Workaround for iPhones
	/*
	$("#mainMenu li").unbind('click');
	$("#mainMenu li").click(function() {
		// If this display is none, show it and return false, otherwise
		if ( $(this).children('.subMenu').is(':hidden') ) {
			alert('London Clubs International');
		}
	});
	//*/
	
	$(".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();
		});
	};

	$('#slider').jcarousel({
        auto: 3,
        scroll: 1,
        wrap: 'circular',
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
        initCallback: mycarousel_initCallback
    });
	
	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
	{
	    // The index() method calculates the index from a
	    // given index who is out of the actual item range.
	    var idx = carousel.index(i, mycarousel_itemList.length);
	    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
	};

	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
	{
	    carousel.remove(i);
	};

	/**
	 * Item html creation helper.
	 */
	function mycarousel_getItemHTML(item)
	{
	    return '<img src="' + item.url + '" alt="' + item.title + '" />';
	};

	$('#carousel').jcarousel({
        scroll: 1,
        wrap: 'both'
    });

	$("#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'));
	}); 

	$("#sidebar .block:not(#photoGallery) h3 a").bigTarget({
		hoverClass: 'hover',
		clickZone : 'div:eq(0)'
	});

	$(".list1 .more").click(function () { 
      $(this).parent().parent().find('.fullInfo').show(); 
    });
	$(".list1 .close").click(function () { 
      $(this).parent().parent().parent().parent().hide(); 
    });

});
