
/*

	Global JavaScript for LFWTV
	---------------------------
	
*/

/* Init */

$(function() {
	
	// When clicking on the main nav, open the popover
	$(".topnav_popover").hoverIntent(showPopover,hidePopover);

	// Drop 'search' into the search box		
	$("input:text").labelify({
		labelledClass: "placeholder",
		text: function(input) {
			return input.getAttribute("placeholder");
		}
	});
	
	carouselInit();
	
});


/* Functions */

// Show the popovers
function showPopover() {
	
	var $thisPopover = $(".popover",this);
	
	$thisPopover.show();
	ie6ToggleSelect('hide');
}

// Hide the popovers
function hidePopover() {
	
	$(".popover").hide();
	ie6ToggleSelect('show');
}

// Show hide select boxes in IE6 (they overlap popups)
function ie6ToggleSelect(action) {

	if($.browser.msie && parseInt($.browser.version,10) < 7) {
		
		if(action == 'hide') {
			$('select').css('visibility','hidden');
		} else if(action == 'show') {
			$('select').css('visibility','visible');
		}
		
	}

}

// Init carousel

function carouselInit() {
	
	// Initialise the scroller
	$('.videolist').serialScroll({
		axis: "x",
		step: 6,
		exclude: 5,
		items: "li",
		next: '.carousel_next',
		prev: '.carousel_prev',
		cycle: false,
		constant: false,
		duration: 600,
		onBefore: disableButtons
	});
	$('.videolist').trigger('goto',[0]);
	
}

// Disables the carousel buttons
function disableButtons(e,elem,$pane,$items,pos) {
	// The object with the scroller's settings in it
	var conf = this;
	
	// Remove the existing classes
	$(conf.prev).removeClass("disabled");
	$(conf.next).removeClass("disabled");

	// Disable buttons depending on the scroller position
	if( pos == 0 )
		$(conf.prev).addClass("disabled");
	else if(pos == $items.length- conf.step)
		$(conf.next).addClass("disabled");
}
$(function() {
	$(".popover_channels .ul").columnise(".li", {numberOfColumns: 4, className: "popup_row", wrapType:"row"}); 
});