$(document).ready(function() {
	
	// Video navigation
	
	$(".video-nav ul").jScrollPane({
		showArrows: true,
		scrollbarWidth: 12
	});
	
	$(".video-nav dd").each(panelInit);
	$(".video-nav dt a").click(panelToggle);
	
	// Hover for IE6
	
	$(".video-grid li a").mouseover(function(){
		$(this).find("span.hover").show();
	}).mouseout(function(){
		$(this).find("span.hover").hide();	
	});
	
	// Share video
	
	$(".video-tool-share a").click(function(){
		$("#share-video").slideDown("fast");
		$("#share-video-result").hide();
		return false;
	});
	
	$("#share-video .cancel").click(function(){
		$("#share-video").slideUp("fast");
		return false;
	});
	
	$("#share-video a.send").click(function() {
		current = $(this).parents("#share-video");
		$.post("/ajax/sharethis_send.asp", {
			sharethis_to: current.find(".sharethis-to").val(),
			sharethis_name: current.find(".sharethis-name").val(),
			sharethis_email: current.find(".sharethis-email").val(),
			sharethis_url: 	current.find(".sharethis-url").val(),
			submitted: -1
		},function(result) {
			current.hide();
			$("#share-video-result").html(result).show();
		});
		return false;
	});
		
});

function panelInit() {
    // Check cookies and set the panel state
    var id = $(this).attr("id");
    var state = $.cookie(id);
    if(state == "none") {
        $(this).css("display","none");
        $(this).prev().addClass("closed");
    }
}

function panelToggle() {
    // Toggle the visibility of the panel
    var id = $(this).attr("href");
    $(this).parents("dt").toggleClass("closed");
    $(id).slideToggle("fast",panelState);
    return false; 
}

function panelState() {
    // Record the state of the panel to a cookie
    $.cookie($(this).attr("id"),$(this).css("display"));
}
