;(function($)
{
	var currentDrop = null;

	$.fn.csb = function(options)
	
{
		var opts = $.extend({}, $.fn.csb.defaults, options);
	
	return this.each(function()
	
	
{
			var input = $(this);
			
			
var container = input.data("__csb");
			
if (input.is(":hidden"))
			
{
			  
 return;	    
			 
}
			
if (container)
				
container.remove();

			
input.css("display", "inline");
			
var width = input.width();
			
input.css("display", "none");
			
var tabIndex = input.attr("tabIndex");
			
var options = this.options;
			
var selectedOption = input.find("option:selected");


		
var caption = $("<div/>").addClass("csb-caption").text(selectedOption.text()).click(function()
			
{


			btn.click();
			
});

var browserName=navigator.appName;
/*if(browserName!="Netscape")
	obj = 	"<button/>";

else
	obj = 	"<image/>";
 */

var btn;
var obj="";
//alert(browserName)

if(browserName!="Netscape")	
	btn = $("<button/>").addClass("csb-button").text(" ").click(function()
	

	//btn = $("<button/>").addClass("csb-button").text(" ").click(function()
	
 
{
				
if (currentDrop)

{

					
currentDrop.drop.remove();
					
if (currentDrop.container == container)
					
{

						
currentDrop = null;
						
return;
					
}
					
currentDrop = null;
				
}
				
var offset = container.offset();

var dropHeight=(document.body.offsetHeight) - (offset.top)
var delta = (document.body.offsetHeight) - (offset.top) - (options.length*20)

if(delta>0)
{

dropHeight = options.length*20
}	
			
var drop = $("<ul/>")
					
.addClass("csb-dropdown")





.css({ top: offset.top + container.height() + "px", left: offset.left + "px", width: (width - 2) + "px",height:dropHeight +"px"})
					
///backup without overflow///.css({ top: offset.top + container.height() + "px", left: offset.left + "px", width: (width - 2) + "px"})
					 

.appendTo($(document.body));
				
currentDrop = { drop: drop, container: container };
				
var selectedIndex = input.attr("selectedIndex");


			
for (var i = 0, l = options.length; i < l; i++)
				
{
					
var a;
					
drop.append($("<li/>").append(a = $("<a/>").attr({ href: "#", tabIndex: tabIndex }).data("index", i).text(options[i].text).click(function(event)
					
{
						
event.preventDefault();
						
var a = $(this);
						
var index = a.data("index");
						
if (index != selectedIndex)
						
{
	
					
input.attr("selectedIndex", index);
							
input.trigger("change");

				
caption.text(a.text());
	
//alert(0);					
}
	
				
drop.remove();
						
currentDrop = null;
						
btn.focus();
					
}).blur(function()

					
{
	
			
currentDrop.item = null;
						
setTimeout(function()
{
				
if (currentDrop && currentDrop.item == null && !(input.trigger("scroll")))	/////////////////////////////////////VERY VERY					
{				
currentDrop.drop.remove();								
currentDrop = null;
							
}
						
}, 8000);
					
}).focus(function()
					
{
						
currentDrop.item = $(this);

					
})));
	
				
if (i == selectedIndex)
	
{
					
a.focus();
	
}			
}
			
});







///////////////////////
if(browserName=="Netscape")	
	btn = $("<image/>").addClass("csb-button").text(" ").click(function()
	


{
				
if (currentDrop)

{

					
currentDrop.drop.remove();
					
if (currentDrop.container == container)
					
{

						
currentDrop = null;
						
return;
					
}
					
currentDrop = null;
				
}
				
var offset = container.offset();

var dropHeight=(document.body.offsetHeight) - (offset.top)
var delta = (document.body.offsetHeight) - (offset.top) - (options.length*20)

if(delta>0)
{

dropHeight = options.length*20
}	
			
var drop = $("<ul/>")
					
.addClass("csb-dropdown")





.css({ top: offset.top + container.height() + "px", left: offset.left + "px", width: (width - 2) + "px",height:dropHeight +"px"})
					
///backup without overflow///.css({ top: offset.top + container.height() + "px", left: offset.left + "px", width: (width - 2) + "px"})
					 

.appendTo($(document.body));
				
currentDrop = { drop: drop, container: container };
				
var selectedIndex = input.attr("selectedIndex");


			
for (var i = 0, l = options.length; i < l; i++)
				
{
					
var a;
					
drop.append($("<li/>").append(a = $("<a/>").attr({ href: "#", tabIndex: tabIndex }).data("index", i).text(options[i].text).click(function(event)
					
{
						
event.preventDefault();
						
var a = $(this);
						
var index = a.data("index");
						
if (index != selectedIndex)
						
{
	
					
input.attr("selectedIndex", index);
							
input.trigger("change");

				
caption.text(a.text());
	
//alert(0);					
}
	
				
drop.remove();
						
currentDrop = null;
						
btn.focus();
					
}).blur(function()

					
{
	
			
currentDrop.item = null;
						
setTimeout(function()
{
				
if (currentDrop && currentDrop.item == null && !(input.trigger("scroll")))	/////////////////////////////////////VERY VERY					
{				
currentDrop.drop.remove();								
currentDrop = null;
							
}
						
}, 8000);
					
}).focus(function()
					
{
						
currentDrop.item = $(this);

					
})));
	
				
if (i == selectedIndex)
	
{
					
a.focus();
	
}			
}
			
});

///////////////////
			
container = $("<span/>").addClass("csb-container")
				
.css("width", width + "px")
				
.append(btn)
				
.append(caption)
				
.insertAfter(input);
			
input.data("__csb", container);
		
});
	
}
	$.fn.csb.defaults =
	{
	};
	$(function()
	{
		$("select.csb").csb();
	});
})(jQuery);