/*!
 * jQuery JavaScript Library v1.5
 * http://jquery.com/
 *
 * Copyright 2011, Navdeep Singh, Zanetine
 * Released under the MIT, BSD, and GPL Licenses.
 *
 * Date: Tue Feb 08 17:55:25 2011 -0500
 * 
 */
jQuery.fn.combo = function() {
	 var args = arguments[0] || {}; // It's your object of arguments
	var speed = args.speed;
	if( speed == null ){
	speed = 'medium';	
	}
   $(this).each(function() {
		var comboid = $(this).attr("id");
                var onchange1 = $(this).attr("onchange");
                if (onchange1 != undefined && onchange1 != null){
                    onchange1 = onchange1.toString();
                    onchange1 = onchange1.replace("function onchange(event) {", "");
                    onchange1 = onchange1.replace("}", "");
                }else{
                    onchange1 = undefined;
                }
                var searchmenu;
		var a_sign = '&#9660;';
		var a_sign = '';
		searchmenu = '<ul id="search-menu" class="drop-down-list">';
		$("#"+comboid+" option").each(function() {
			
				value = $(this).val();
				display_value = $(this).text();	
				selected_value = $("#"+comboid+" option:selected").val();
				
				if( value != 0 ) {
					if( value == selected_value ) {
						searchmenu += '<li><a class="selected" title="'+value+'" href="javascript:void(0);">'+display_value+'</a></li>';									
					} else {
						searchmenu += '<li><a title="'+value+'" href="javascript:void(0);">'+display_value+'</a></li>';															
					}
				}
				
		});
		searchmenu += '</ul>';

		if(  $("#"+comboid+" option:selected").val() == '' ){
				default_value = '';
				default_selected_display_value = $("#"+comboid+" option:selected").text();	
		} else {
				default_value = $("#"+comboid+" option:selected").val();
				default_selected_display_value = $("#"+comboid+" option:selected").text();
		}
		
		$(this).after('<div class="search-menu-column" id="Select-'+comboid+'"><p class="search-field"><input type="hidden" value="'+default_value+'" id="'+comboid+'" name="'+comboid+'" /></p><p class="search-type">'+default_selected_display_value+'</p><p class="search-menu-link"><a id="combo-arrow" href="javascript:void(0);">'+a_sign+'</a></p>'+searchmenu+'</div>');
		
		$("select#"+comboid).remove();			

		$("#Select-"+comboid+" .search-menu-link a,#Select-"+comboid+" .search-type").live("click",function() {                    
                    $("#Select-"+comboid+" .drop-down-list").toggle(speed);
		});
		
		$("#Select-"+comboid+" #search-menu a").click( function() {
                    if (onchange1 != undefined){
                        zmianaOceny($(this).attr("title"));
                    }
                    var text = $(this).text();
                    var title = $(this).attr("title");
                    $("#Select-"+comboid+" #search-menu a").removeClass("selected");
                    $(this).addClass("selected");
                    $("#Select-"+comboid+" .search-type").html(text);
                    $("#Select-"+comboid+" #SearchField").val(title);
                    $("#Select-"+comboid+" input[name="+comboid+"]").val(title);
                    $("#Select-"+comboid+" #search-menu").hide("medium");
		});			
		
	});
};

