$(function() {	
	$('nav ul li').hover(
		function () {
			//show its submenu
			$(this).addClass('current');
			$('> ul', this).stop(true, true).slideDown('fast');
		}, 
		function () {
			//hide its submenu
			$(this).removeClass("current");
			$('> ul', this).stop(true, true).slideUp('slow');			
		}
	);
	$('.featured').slides({
		generatePagination: false,
		play: 5000
	});

	$('.backtotop').click(function() {
		$("html, body").animate({scrollTop: 0}, 500);
	});
	$("li.embed").click(function() {
		$("#embedPopup").fadeIn('fast');
	});
	$('span.close').click(function() {
		$(this).parent().parent().fadeOut('fast');
	});
	$('a#embed').click(function() {
		$(this).parent().parent().parent().find('#embedPopup').fadeIn('fast');
		return false;
	});
	var container = $('div.latestMedia');
	var ul = $('.postWidth', container);    
	var itemsWidth = ul.innerWidth() - container.outerWidth();   
	$('.slider', container).slider({
		min: 0,
		max: itemsWidth,
		handle: '.handle',
		stop: function (event, ui) {
			ul.animate({'left' : ui.value * -1}, 500);
		},
		slide: function (event, ui) {
			ul.css('left', ui.value * -1);
		}
	});
});
