/**
 * toggler.js
 * @author Lewis Howles
 *
 * Toggle Search Box Visibility
 */

function toggle() {
	// Save context searches
	var $searchBox = $('#search');
	var $searchFrame = $('#search-frame', $searchBox);
	var $heading = $('h2', $searchBox);
	
	// Initial Hide
	$searchFrame.fadeOut(1000, function() {
		$searchBox.animate({height : '20px'}, 1000, function() {
			$heading.css({'background-position' : '185px 0'});
			$searchBox.data('visible', false);
		});
	});
	
	
	$heading.click(function() {
		if($searchBox.data('visible')) {
			$searchFrame.fadeOut(1000, function() {
				$searchBox.animate({height : '20px'}, 1000, function() {
					$heading.css({'background-position' : '185px 0'});
					$searchBox.data('visible', false);
				});
			});
		} else {
			$searchBox.animate({height : '175px'}, 1000, function() {
				$heading.css({'background-position' : '185px 100%'});
				$searchFrame.fadeIn(1000, function() {
					$searchBox.data('visible', true);
				});
			});
		}
	});
}
