// Dom
$(document).ready(function(){
	
	
	hoverTitles();
	
	$('#more .show').click( function(){
	
		$moreData = '<span>Showing All</span>';
		
		$('#more').html('<img src="/images/ajax-loader.gif" />')
	
		$.getJSON("ajax.php?q=show_all_musicals",
			
			function(data)
			{
	
				$('#view-all').html(data);
	
				$('#view-all').slideToggle('slow', function () {
														 
					hoverTitles();

					$('#more').html($moreData);							 
				});
			}
		);
	});

	

	$('#add_youtube').click( function(event){
									  
		$('#add_youtube_link').slideToggle('slow');
		
		// Stops duplicate animation
	  	event.stopImmediatePropagation();
	});
	
	$('#report-btn').click( function(event){

		$('#report_link').slideToggle('slow');
		
		// Stops duplicate animation
	  	event.stopImmediatePropagation();

	});

	
	$('#submit_report').click( function(event){
					
		$('.msg').fadeIn('slow');
		$('.msg').html('<img src="/images/ajax-loader.gif" />');
		
		if ( $("input[name='reason']:checked").length )
		{
			$url = $('#url').val();
			$reason = $("input[name='reason']:checked").val();
			
			$.post("/ajax.php?q=submit_report", { reason: $reason , url: $url } ,
				   
			  function(data, textStatus) {
			  
			  if (data)
				{
					$('#report_form').slideUp('slow');
					$('.msg').html('<h6>Thank you</h6><p>This track has successfully been reported and we will look into this immediately.</p>');
				}
				else
				{
					$('.msg').html('<h6>Error</h6><p>Please select a reason to submit this report.</p>');
				}
			  
			}, "json");
			
			return;
		}
		else
		{
			$('.msg').html('<h6>Error</h6><p>Please select a reason to submit this report.</p>');	
		}
		
		// Stops duplicate animation
	  	event.stopImmediatePropagation();
											  
	});
	
	
	$('#youtube_link_submit').click( function(event){

		$youtube_link = $('#youtube_link').val();
		$lyrics_id = $('#lyrics_id').val();
		$url = $('#url').val();
		
		$form_data = $('#add_youtube_link').html();
		
		$('#youtube_link_submit').css('display', 'none');
		$('#youtube_link_submitted').html('<img src="/images/ajax-loader.gif" />');
		$('#youtube_link_submitted').css('display','block');
		
		if ( $youtube_link )
		{
			$.post("/ajax.php?q=submit_youtube_link&id=" + $lyrics_id, { code: $youtube_link , url: $url} ,
				   
				function(data, textStatus) {
			  //data contains the JSON object
			  //textStatus contains the status: success, error, etc
			  
			  if (data)
				{
					$('#add_youtube_link form').html('');
					$('#add_youtube_link .msg').html('<h6>Thank you</h6><p>The music for this track has been updated.</p>');
					return;
				}
				else
				{
					$('#add_youtube_link .msg').html('<h6>Error</h6><p>There was en error with the data entered. Please try again.</p>');	
					$('#youtube_link_submitted').css('display', 'none');
					$('#youtube_link_submit').css('display', 'block');
				}

			}, "json");

		}
		else
		{
			$('#add_youtube_link .msg').html('<h6>Error</h6><p>There was en error with the data entered. Please try again.</p>');
			$('#youtube_link_submitted').css('display', 'none');
			$('#youtube_link_submit').css('display', 'block');
		}
		
		$('.msg').fadeIn('slow');
		
		// Stops duplicate animation
	  	event.stopImmediatePropagation();


	});
	
	
	
	// IE6 PNG Fix
	if (jQuery.browser.msie) { if(parseInt(jQuery.browser.version) == 6) $("img").pngfix(); }

}); 

function viewAll($target)
{					
	$moreData = '<span>Showing All</span>';
	
	$('#more').html('<img src="/images/ajax-loader.gif" />');

	
	$.getJSON("ajax.php?q=show_all_musicals",
		
		function(data)
		{

			$('#view-all').html(data);

			$('#view-all').slideToggle('slow', function () {
													 
				hoverTitles();
				
				sIFR.replace(arial_rounded, {
				  selector: 'h2',
				  tuneWidth: 2,
				   css: [
					  '.sIFR-root {color:#FFFFFF; font-size:20px; color:#E50087; text-transform:lowercase; }'
					],
				  wmode: 'transparent',
				  forceSingleLine: true
				});
				
				$('#more').html($moreData);							 
			});
			
		}
	);
}


// Hover titles for musicals
function hoverTitles()
{
	$('.item').hover(function(){
		$("div", this).stop().animate({bottom:'7px'},{queue:false,duration:160});
	}, function() {
		$("div", this).stop().animate({bottom:'-66px'},{queue:false,duration:160});
	});
}





