/**
 * Styled Dropdown - jQuery Plugin v1.0
 * Easily converts SELECT elements to eventful and styleable DL, DT, DD elements.
 * Requires jQuery 1.3.x +
 * 
 * Copyright 2010, Andres Vidal (code@andresvidal.com)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://www.andresvidal.com/license/styledDropdown
 *
 * Instructions: Call $(selector).styledDropdown(options) on an element with a jQuery type selector 
 * @example: $('select').styledDropdown(); // <select name="test"><option value="good">Good</option><option value="bad">Bad</option> ... </select>
 * 
 */
 
(function(d){d.fn.styledDropdown=function(l){function m(b){var e=d(b).find("dt"),f=d(b).find("dd"),h=d(b).children("a");d(e).each(function(){d(this).focus(function(){c.focusFunction(this);c.focusFunction(e)}).blur(function(){c.blurFunction(this);return c.blurFunction(e)}).hover(function(){return c.hoverOverFunction(this)},function(){return c.hoverOutFunction(this)}).click(function(){if(e.parent().hasClass(c.hoverClass)===!1){var b=this;d("body").bind("click.styledDropdown",function(){c.dlCloseFunction(b);
d(this).unbind("click.styledDropdown")})}return c.dtClickFunction(this)})});d(f).each(function(){d(this).focus(function(){c.focusFunction(this);c.focusFunction(b)}).blur(function(){c.blurFunction(this);return c.blurFunction(b)}).hover(function(){return c.hoverOverFunction(this)},function(){return c.hoverOutFunction(this)}).click(function(){return c.clickFunction(this)})});d(h).each(function(){d(this).focus(function(){return c.focusFunction(this)}).blur(function(){return c.blurFunction(this)}).hover(function(){return c.hoverOverFunction(this)},
function(){return c.hoverOutFunction(this)}).click(function(){return c.clickFunction(this)})})}function g(b){return d(b).closest("dl")}function i(b){return d(b).closest("dd")}function k(b){var e=g(b),b=d(e).find("dd."+c.selectedClass),e=d(e).find("dt:first-child"),f=d(b).html();d(e).text()!=d(f).text()&&(d(e).empty().append(f),j(b,e,c.attrsToCopy),d(e).removeClass(c.optionClass).removeClass(c.selectedClass).removeClass(c.hoverClass));return!1}function n(b){var e=document.createElement("a"),f=document.createElement("dd"),
h=d(b).html();e.href="#"+d(b).val();e.rel=d(b).val();e.innerHTML=h;d(f).append(e);j(b,f,c.attrsToCopy);d(b).attr("selected")&&d(f).addClass(c.selectedClass);return f}function j(b,e,f){for(a in f){var h=c.attrsToCopy[a],g=d(b).attr(f[a]);g&&d(e).attr(h,g)}return e}var c=jQuery.extend({selectClass:"select",optionClass:"option",selectedClass:"selected",focusClass:"focus",hoverClass:"hover",attrsToCopy:["title","name","class"],focusFunction:function(b){var d=i(b),f=g(b);d.addClass(c.focusClass);f.addClass(c.focusClass);
c.hoverOverFunction(b)},blurFunction:function(b){var d=i(b);g(b);d.removeClass(c.focusClass);c.hoverOutFunction(b)},hoverOverFunction:function(b){i(b).addClass(c.hoverClass)},hoverOutFunction:function(b){i(b).removeClass(c.hoverClass)},clickFunction:function(b){var e=i(b),f=g(b);e.addClass(c.selectedClass).siblings().removeClass(c.selectedClass);k(b);f.removeClass(c.hoverClass);f.removeClass(c.focusClass);e=d(f).find("a").attr("href");e=e.substring(e.lastIndexOf("#")+1);c.debug&&window.console?(console.log("update select name"),
console.log(e)):c.debug&&(alert("update select name"),alert(e));f=d(f).attr("name");d("select[name="+f+"]").val(e);c.onChangeCallback({name:f,value:e});d(c.currentSelect).change();return c.onClickCallback(b)},dtClickFunction:function(b){g(b).toggleClass(c.hoverClass);return!1},dlCloseFunction:function(b){g(b).removeClass(c.hoverClass);return!1},onClickCallback:function(){return!1},onChangeCallback:function(){return!1},callback:function(){return!1},debug:!1,currentSelect:{}},l);this.each(function(){var b=
document.createElement("dl"),e=document.createElement("dt");j(this,b,c.attrsToCopy);d(b).prepend(e);d(this).find(c.optionClass).each(function(c,e){d(b).append(n(e))});k(b);m(b);d(b).insertAfter(this);d(this).hide();c.callback(b)});return this}})(jQuery);
