function limitChars(textid, limit, infodiv){
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit){
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}else{
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}


$(document).ready(function(){
	
	/* The Search stuff in here */
	$('#quick_search').liveSearch();
	
	//$('#postcode').SportliveSearch();
	
	/*	
	$("#navigation li a").click(function(){
		$("#discoveryoursport").attr('class','');
		$("#discoveryoursport").attr('class', $(this).attr('id'));	
		return false;	
	})
	*/

	$(".jumpoffs").equalHeights();

	//quick find which is highest then set border to that one
	$('#content').css("border", "none");
	$('#secondary-content').css("border", "none");
	if ( $('#content').length > 0 && $('#secondary-content').length) {
    	if($('#content').height() > $('#secondary-content').height()){
			$('#content').css("border-right", "1px solid #B0B1B1");
		}else{
			$('#secondary-content').css("border-left", "1px solid #B0B1B1");	
		}
	}

	$(".item").click(function() {
	  	window.location = $(this).find("p.read-more-link a:first").attr("href");
	});
	$(".item").hover(
 		function() {
        $(this).addClass("hover");
      },
      function() {
        $(this).removeClass("hover");
      }
    );
	
        
    $('#navigation li')
            .removeClass('highlight')
            .find('a.fade')
            .append('<span class="hover" />').each(function () {
                    var $span = $('> span.hover', this).css('opacity', 0);
                    $(this).hover(function () {
                        // on hover
                        $span.stop().fadeTo(500, 1);
                    }, function () {
                        // off hover
                        $span.stop().fadeTo(500, 0);
                    });
                });

	// better tool tips for the two searches
	$('.tooltip').betterTooltip({speed: 150, delay: 300});
	
	//limit the words in the textarea
 	$('#ClubDescription').keyup(function(){
 		limitChars('ClubDescription', 1000, 'description-note');
 	})


	//Close button:	
	$(".close").click(
		function () {
			$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
				$(this).slideUp(600);
			});
			return false;
		}
	);

	
	
});
