$(document).ready(function() {
	//info overlay for featured videos/series
	var orig_pos = new Array();
	$('.featured.video').hover(function() {
		if( orig_pos[$(this).index('.featured.video')] == undefined ) {
			orig_pos[$(this).index('.featured.video')] = $('.title', this).css('top');
		}
		
		var pos = 0;
		if($(this).hasClass('main')) {
			var new_pos = $(this).height() - $('.title', this).outerHeight();
			pos = (new_pos < 0) ? 0 : new_pos;
		}
		
		$('.title', this).stop(true).animate({'top': pos+'px'}, 500);
	}, function() {
		$('.title', this).stop(true).animate({'top': orig_pos[$(this).index('.featured.video')]}, 500);
	});
	
	//activate tabs for homepage
	$('.tabs a').click(function(event){
		event.preventDefault();
		if( !$(this).hasClass('selectedtab') ) {
			switch_tabs($(this));
		}
	});
	
	$(".scrollable").scrollable({
		items: '.videos',
		keyboard: false
		/*onBeforeSeek: function(e, index) {
			//stop anything overriding this
			var test = event;
			
			// if content isn't already loaded
			if( $('.videos div:nth-child(' + (index+1) + ')', $(test.target).parent().parent()).html() == "" ) {
				var offset = (index * 6) + 1;
				var test = event;
				
				$.ajax({
					url: '/home/tabs/latest/6/' + offset,
					data: null,
					success: function(data) {
						$('.videos div:nth-child(' + (index+1) + ')', $(test.target).parent().parent()).append(data);
					},
					dataType: 'html'
				});
			}
		}*/
	}).navigator();
});

function switch_tabs(obj) {
	var id = obj.attr("rel");
	
	$('.selectedtab').removeClass("selectedtab");
	obj.addClass("selectedtab");
	
	$('.activetab').stop(true, true).fadeOut(200, function(){
		$('.activetab').removeClass("activetab");
		$('#'+id).addClass("activetab").fadeIn(500);
	});
}

