$(document).ready(function() {
	/* Home cycle */
 	$('.cta_items').cycle({ 
	    fx:     'scrollRight', 
		easing: 'easeout',
		pager:  '#more_sports', 
		pagerAnchorBuilder: function(idx, slide){
	        return "#more_sports a[rel='cta_"+idx+"']";
	    },
	    random:  1,
		timeout: 5000
	});
	
	/* Droppy */
	$('.button_more_sports').droppy();
	
	/* Columns hover state */
	$(".actAsButton").actAsButton();
	
	/* tBlank */
	$("a[rel='tBlank']").tBlank();
	
	/* Logo hover */
	$("#logo").logoHover();
});

jQuery.fn.actAsButton = function() {
	$(this).hover(
		function(){
			$(this).addClass("actAsButton_active");
			$(this).find(".actAsButton_bg").show().fadeTo("fast",0.3);
			$(this).find(".button_read_more").addClass("active");
		},
		function(){
			$(this).removeClass("actAsButton_active");
			$(this).find(".actAsButton_bg").fadeTo("fast",0).hide();
			$(this).find(".button_read_more").removeClass("active");
		}
	);
	$(this).click(
		function(){
			var target = $(this).find(".button").attr("href");
			window.location = target;
		}
	);
};

jQuery.fn.logoHover = function(){
	var target_html;
	var hovering = false;
	$(this).children("a").addClass("original");
	target_html = $("#logo").html();
	target_html = target_html.replace("original","hover");
	target_html = target_html.replace("<a","<a style=\"display:none;\"");
	$(this).append(target_html);
	
	$(this).hover(
		function(){
			if(!hovering){
				hovering = true;
				$(this).children(".original").fadeOut('fast');	
				$(this).children(".hover").fadeIn('fast',function(){
					hovering = false;
				});
			}		
		},
		function(){
			if(!hovering){
				$(this).children(".original").fadeIn('fast');	
				$(this).children(".hover").fadeOut('fast',function(){
					hovering = false;
				});
			}
		}
	);
};

jQuery.fn.tBlank = function() {
	$(this).each(function(){
		$(this).attr("target","_blank");
	});
};
