$(document).ready(function() {
	// popups
	openInNewWindow();
	
   	$('#tabs-wrapper').tabs();
   	
   	$('#stafButton').click(function()
   	{
   		// reset error fields
   		$('#stafSenderNameError').hide();
   		$('#stafRecipientNameError').hide();
   		$('#stafEmailError').hide();
   		
   		if($('#your-name').val() != '' && $('#colleague-name').val() != '' && $('#colleague-email').val() != '')
   		{
	   		// fetch mediaId
	   		mediaId = $('#mediaId').val();
	   		
	   		// fetch mediatype
	   		mediaType = $('#mediaType').val();
	   		
	   		// fetch emailaddress
	   		email = $('#colleague-email').val();
	   		
	   		// fetch sender name
	   		stafSenderName = $('#your-name').val();
	   		
	   		// fetch recipient name
	   		stafRecipientName = $('#colleague-name').val();
	   		
	   		// ajax call to send email and receive response
	   		$.post("/medialibrary/staf_ajax",
				{ mediaId: mediaId, mediaType: mediaType, email: email, stafSenderName: stafSenderName, stafRecipientName: stafRecipientName },
				function(response){
					$('#stafMessage').show();
					
					$('#stafMessage').html('<p>' + response + '</p>'); //.fadeOut(5000)
					
					$('#colleague-email').val('');
					$('#colleague-name').val('');
					
				}
			);
   		}else
   		{
   			if($('#your-name').val() == '') $('#stafSenderNameError').show();
   			if($('#colleague-name').val() == '') $('#stafRecipientNameError').show();
   			if($('#colleague-email').val() == '') $('#stafEmailError').show();
   		}
		return false;
   	});
});

function rateVideo(videoId, userId)
{
	var rating = $("input[@name='rating']:checked").val();
	
	$.post("/videos/rate_ajax",
		{ rating: rating, videoId: videoId, userId: userId },
		function(response){
			$('#section-3').html('<p>' + response + '</p>');
		}
	);
}

function rateArticle(articleId, userId)
{
	var rating = $("input[@name='rating']:checked").val();
	
	$.post("/articles/rate_ajax",
		{ rating: rating, articleId: articleId, userId: userId },
		function(response){
			alert(response);
			$('#section-3').html('<p>' + response + '</p>');
		}
	);
}

function showSlide(slideId)
{
	$('.slides').hide();
	$('#slide' + slideId).show();
}

function openInNewWindow() {
	$("a[@rel=external]").attr('target', '_blank');
	return false;
}

// makes buttons work in IE
function submitAction(value)
{
    document.forms["bonacForm"].action.value = value;
    document.forms["bonacForm"].submit();
}