$(document).ready(function() { 
	
	if($('#type').val()=="")
	{
		$('#type').val('F');
	}
	
	if($('#search').val() =="" && $('#type').val()!='A')
	{
		$('#results').html("Welcome to UnderstandingTV.com, your gateway to "+ 
						"On Demand Messages from God's Word to help you in your daily life."+
						"<br/><br/>Search our message database by entering keywords for the subject or title that you are interested in.");
	}
	else
	{
		swapTab($('#type').val());
	}
																		
	$('#frmSearch').ajaxForm({ 
    // target identifies the element(s) to update with the server response 
    target: '#results', 
 
    // success identifies the function to invoke when the server response 
    // has been received; here we apply a fade-in effect to the new content 
    success: function() { 

    } 
    
	});  
});   

function swapTab(t)
{
	/*remove active tab background for all elements*/
	$("#searchTabs A").attr('class', "");
	
	/*set active tab background for the chosen element*/
	if (t=='F')
	{ 
		$('#full').attr("class", "current"); 
		$('#btnSubmit').show();
		$('#search').show();
	}
	
	else if (t=='A')
	{ 
		$('#top').attr("class", "current"); 
		$('#btnSubmit').hide();
		$('#search').hide();
	}
	
	else if (t=='B')
	{ 
		$('#broadcasts').attr("class", "current"); 
	}
	
	else if (t=='C')
	{ 
		$('#clips').attr("class", "current"); 
	}
	$('#type').val(t);
}


function switchTab(t)
{	
	/*remove active tab background for all elements*/
	$("#searchTabs A").attr('class', "");
	
	/*set active tab background for the chosen element*/
	if (t=='F')
	{ 
		$('#full').attr("class", "current"); 
		$('#btnSubmit').show();
		$('#search').show();
	}
	
	else if (t=='A')
	{ 
		$('#top').attr("class", "current"); 
	}
	
	else if (t=='B')
	{ 
		$('#broadcasts').attr("class", "current"); 
	}
	
	else if (t=='C')
	{ 
		$('#clips').attr("class", "current"); 
	}
	$('#type').val(t);


	/*if it's a top n search then no search value is needed to perform a lookup*/
	if (t =='A')
	{
		$('#btnSubmit').hide();
		$('#search').hide();
		$.get("lookup.php", {type: t, search: $('#search').val()}, function(data){
			if(data.length >0) {
				$('#results').html(data);     
			};
		});
	}
	else
	{
		/*if the search field is empty don't hit the server to do a lookup*/ 
		if($('#search').val() !="")
		{
			$.get("lookup.php", {type: t, search: $('#search').val()}, function(data){
				if(data.length >0) {
					$('#results').html(data);     
				};
			});
		}
	}
}
