(function($) {

	$.SAWDropDown = function() {}

	$.SAWDropDown.downClick = function( $img, $input, $value, $listBox, $items )
	{
		var minWidth = $input.outerWidth() + $img.outerWidth();

		$listBox.css("left",$input.eq(0).offset().left).css("min-width",minWidth);
		if($listBox.css("display")=="none") {
			$listBox.show("fast", function() {
				$listBox.scrollTop(0).eq(0).focus();
			});
		}
		else
		{
			$listBox.hide("fast");
		}
	};

	$.SAWDropDown.InitListItems = function( $img, $items, $value, $input, $listBox )
	{
		$items.click(function(e)
		{
			$value.val( $(this).attr("title") );
			$input.val( $(this).text() );
			$input.change();
			$listBox.hide("fast");
		});
		$items.hover(function()
		{
			$(this).addClass("highLight");
		}, function()
		{
			$(this).removeClass("highLight");
		});
	};

	$.SAWDropDown.Init = function( element )
	{
		var $items = $( '.listBox ul li.selectable', element );
		var $listBox = $( '.listBox', element );

		var $input = $( '.ddTextBox', element );
		var $value = $( '.ddValueBox', element );

		var $img = $( '.arrowImg', element );

		$.SAWDropDown.InitListItems( $img, $items, $value, $input, $listBox );

		$( '.arrowImg', element ).click( function()
		{
			$.SAWDropDown.downClick( $img, $input, $value, $listBox, $items )
		});
		$( '.ddTextBox', element ).click( function()
		{
			$.SAWDropDown.downClick( $img, $input, $value, $listBox, $items )
		});

		$listBox.blur( function(e)
		{
			$listBox.hide("fast");
		});

	}

	$.fn.SAWDropDown = function()
	{
		//var $items = $('.listBox ul li', this);

		$('.ddTextBox', this)

		$.SAWDropDown.Init( $(this) );
	}

})(jQuery);

$(document).ready(function()
{
	$('.SAWDropDown').each(function(){
		$(this).SAWDropDown( {} );
	});
});