jQuery(document).ready(function() {
	//Manages tabs for profile page
	var tabContainers = jQuery('div.tabs > div');
	tabContainers.hide().filter(':first').show();                  
	
	jQuery('div.tabs ul.tabset a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		jQuery('div.tabs ul.tabset a').parent().removeClass('active');
		jQuery(this).parent().addClass('active');
		return false;
	}).filter(':first').click();
	
	jQuery('.row .rating li a').click(function(){
		user_rating = $(this).attr('title');
		jQuery('#star_rating').attr('value', user_rating);
		
		//Highlight current stars
		var x = 1;
		while (x <= 5)
		{
			if (x <= user_rating){
				jQuery('.row .rating li:nth-child(' + x + ')').addClass('active');
			}else{
				jQuery('.row .rating li:nth-child(' + x + ')').removeClass('active');
			}
			x = x + 1; //Sets current star to check
		}
		
		//alert('You rated this ' + user_rating);
		return false;
	});

	if ( jQuery('.imageset').length ){
		//if this page has an image gallery, start it
		jQuery('.imageset').cycle();
	}
	
	jQuery('.announcement .hide').click(function(){
		jQuery(this).parent().parent().hide();
		return false;
	});
	
	//Home page tips
	jQuery('#process-toggle').click(function(){
		jQuery('.process').slideToggle();
		return false;
	});
	
	//Checkbox controls
	var total_checked = 0;
	
	jQuery('.results :checkbox').click(function(){
		
		total_checked = jQuery(".compare_this:checked").length;
				
		if (total_checked >= 2){
			//If 2 boxes are checked, disable all non-checked
			jQuery('.results :checkbox').not(":checked").attr('disabled','disabled');
		}else{
			//If less than two boxes are checked, enable all checkboxes
			jQuery('.results :checkbox').not(":checked").removeAttr('disabled');
		}
		
	});
	
	if( jQuery('.advanced-search').length ){
		//Hides advanced search box for index
		jQuery('.extra-options').hide();
	}
	
	jQuery('.advanced-search').click(function(){
		if(jQuery('.extra-options').css('display') == 'none')
			jQuery('.extra-options').fadeIn();
		else
			jQuery('.extra-options').fadeOut();
		return false;
	});
	
	jQuery('#submit-filter').click(function(){
		if(jQuery('#terms').val() == 'Search')
			jQuery('#terms').val('');
		return true;
	});
	
	
});
