/**
*	Add all the necessary CSS and JS to the page.
*	These are style sheets that are only ever required if js is enabled
*/
jQuery(document).ready(function() {
	$('#t-and-t-thumbs').css('display', 'none').remove();
	prepareOverlayLinks();
	wrapForm();
	prepareSubmits();
	makeFormAction();	
	$('head').append('<link rel="stylesheet" type="text/css" href="/css/hom/showFlash.css" />');
	$('head').append('<link rel="stylesheet" type="text/css" href="/css/hom/hideInlineContent.css" />');	
	$('head').append('<link rel="stylesheet" type="text/css" href="/css/hom/thickbox.css" />');
	$('head').append('<script src="/includes/hom/jquery/jquery.thickbox.js" type="text/javascript" charset="utf-8"></script>');
});
/**
*	Prepare all Thickbox links
*/

function prepareOverlayLinks(){
	$('.smoothbox').each(function(){
		var nodes = $(this).attr('href').split("#"); 
		$(this).attr("href","#TB_inline?height=250&amp;width=450&amp;inlineId="+nodes[1]);
	});	
}

/**********************************************************************************************************
*	Functions for the select drop downs
*/


/**
*	Removes the individaul forms, and wraps all the selects in one form
*/

function wrapForm(){
	// Get the contents of each of the forms
	$('.selectForm').each(function(){
		var formContents = $('#'+this.id).contents();
		$('#'+this.id).replaceWith(formContents);		
	});
	$('#selects').wrap('<form id="selectsForm"></form>');
}

/**
*	Adds the URL from the value of the selected drop down to the form action.
*	When the form is then submitted, it will submit to this URL
*/
function makeFormAction(){
	$('#selects select').each(function(){
		$('#'+this.id).change(function(){
			resetSelects(this.id);
			var selectedValue = $('#'+this.id).val();
			var formAction = selectedValue !== '' ? selectedValue : '';
			$('#'+this.id).parents('form:first').attr('action', formAction);
		});
	});
}
/**
*	Resets all the drop downs to their default values
*/
function resetSelects(changedId){
	// Reset all select boxes
	$('#selects select').each(function(){
		if(this.id !== changedId){
			$('#'+this.id).attr('value', '');
		}		
	});	
}
/**
*	Removes the individual submit buttons, and builds one 
*	to be used for the newly built wrapper form
*/
function prepareSubmits(){
	// Remove the individual slect buttons
	$('.fifth p.button').remove();
	// Append the single submit button
	var dynamicButton = $('#selects').append('<p class="button" id="hello"><button type="submit" id="submitFind_5" name="submitFind_5"><span>Find</span></button></p>');	
}

