$(document).ready(function(){
	
	add_close();
	
});

function share(id) {
	$.ajax({
		type: "POST",
		cache: false,
		url: '/_videos/share/'+id+'/'+escape(window.location),
		success: function(response){
			$('#share').html(response);
			$('#share_box').hide();
			add_close();
			share_form();
			$('#share').slideDown(1500, function(){
				$('#share_box').show().center();//.hide().slideDown(1500);
			});
			//$('#share').show();
			//$('#share_box').show().center();
		}
	});
}

function share_form(){
	$('#share_submit').click(function(e){
		e.preventDefault();
		$('#share_status').html('Sending request');
		$('#share_status').slideDown('fast');
		//$('#share_status').show();
		$.ajax({
			type: "POST",
			cache: false,
			url: '/_videos/share',
			data: $("#share_form").serialize(),
			success: function(response){
				if (response != true) {
					$('#share').html(response);
					$('#share_box').center();
					$('#share_status').html('Errors encountered').addClass('error').show();
					add_close();
					share_form();
					hide_timeout = setTimeout(function(){
						$('#share_status').slideUp('slow', function() {
							$('#share_status').removeClass('error');
						});
					}, 1000);
				} else {
					$('#share_status').html('Data has been sent').addClass('success');
					hide_timeout = setTimeout(function(){
						$('#share_box').slideUp(1500, function() {
							$('#share').slideUp(1500);
						});
					}, 1500);
				}
			}
		});
		
    });
}

function add_close() {
	$('#share_close').live("click", function(e){
		$('#share_box').slideUp(1500, function() {
			$('#share').slideUp(1500);
		});
	});
}