/* Dropdown Skinner v1.0 by Akufen (C) 2011 */

/* Dropdown Skinner v1.0 by Akufen (C) 2011 */
/* Development version */

var current_zindex = 9999;

if ($.browser.msie && $.browser.version == "6.0") {
} else {
	(function($) 
	{		
		$.fn.extend({
		   style_dropdown: function (options) 
		    {
		    	var parent = $(this);
		    	var select = $('select', this); 
		    	var num = 0;
				
		    	var children = select.children();
		    	parent.html('');
		    	parent.addClass(options.parent_class);
		    	parent.append('<input type="hidden" name="' + select.attr('name') + '" id="' + parent.attr('id') + '_value" value="" />');
		     	
		    	parent.append('<div id="' + parent.attr('id') + '_label" class="' + options.label_class + '" style="position: relative;"></div><div id="' + parent.attr('id') + '_container" class="' + options.container_class + '" style="z-index: ' + current_zindex.toString() + '; position: absolute; display: none;"></div>');
		    	var container = $('#' + parent.attr('id') + '_container');
		    	children.each(function()
		    	{
		    		var id = parent.attr('id') + '_option_' + num;
								
					if (typeof($(this).attr('selected')) != 'undefined') {
						$('#' + parent.attr('id') + '_value').val($(this).attr('value'));
						$('#' + parent.attr('id') + '_label').html($(this).attr('name'));
					}
		
		    		container.append('<div id="' + id + '" class="' + options.item_class + '" _val="' + $(this).attr('value') + '" style="cursor: pointer;">' + $(this).attr('name') + '</div>');
		    		num++;
		    	});
		    	
		    	$('.' + options.item_class).click(function()
		    	{
		    		set_selected($(this), $(this).parent().parent());
		    		open_dropdown($(this).parent().parent(), options.speed);
		    	});
		    	
		    	$('#' + parent.attr('id') + '_label').click(function()
		    	{
		    		container.topZIndex();
		    		parent.topZIndex();
		    		parent.parent().topZIndex();
		    		open_dropdown($(this).parent(), options.speed);
		    	});
		    	
		    	current_zindex--;
		    }
		});
	}(jQuery));
	
	function set_selected(obj, parent)
	{
		var value = obj.attr('_val');
		var label = obj.text();
		$('#' + parent.attr('id') + '_value').val(value);
		parent.children('div:first').html(label);
	}
	
	function open_dropdown(parent, speed)
	{
		var box = $('#' + parent.attr('id') + '_container');
		
		if (box.css('display') == 'none') {
			if ($.browser.msie && $.browser.version == "7.0") {
				box.css('display', '');
			} else {
				box.slideDown(speed);
			}
			return false;
		} else {
			if ($.browser.msie && $.browser.version == "7.0") {
				box.css('display', 'none');
			} else {
				box.slideUp(speed);
			}
			return false;
		}
		
	}
}
