/**
 * Styled Dropdown - jQuery Plugin v0.1.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(m){function n(b){var e=d(b).find("dt"),f=d(b).find("dd"),g=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(){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(g).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 h(b){return d(b).closest("dl")}function i(b){return d(b).closest("dd")}
function k(b){var e=h(b);b=d(e).find("dd."+c.selectedClass);e=d(e).find("dt:first-child");var f=d(b).html();if(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 false}function o(b){var e=d(b).find("a").attr("href");e=e.substring(e.lastIndexOf("#")+1);p(e,"update select name");b=d(b).attr("name");d("select[name="+b+"]").val(e);c.onChangeCallback({name:b,value:e})}function p(b,e){if(c.debug&&
window.console){e&&console.log(e);console.log(b)}else if(c.debug){e&&alert(e);alert(b)}return false}function q(b){var e=document.createElement("a"),f=document.createElement("dd"),g=d(b).html();e.href="#"+d(b).val();e.rel=d(b).val();e.innerHTML=g;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 g=c.attrsToCopy[a],l=d(b).attr(f[a]);l&&d(e).attr(g,l)}return e}var c=jQuery.extend({selectClass:"select",optionClass:"option",
selectedClass:"selected",focusClass:"focus",hoverClass:"hover",attrsToCopy:["title","name","class"],focusFunction:function(b){var e=i(b),f=h(b);d(e).addClass(c.focusClass);d(f).addClass(c.focusClass);c.hoverOverFunction(b)},blurFunction:function(b){var e=i(b);h(b);d(e).removeClass(c.focusClass);c.hoverOutFunction(b)},hoverOverFunction:function(b){b=i(b);d(b).addClass(c.hoverClass)},hoverOutFunction:function(b){b=i(b);d(b).removeClass(c.hoverClass)},clickFunction:function(b){var e=i(b),f=h(b);d(e).addClass(c.selectedClass).siblings().removeClass(c.selectedClass);
k(b);d(f).removeClass(c.hoverClass);d(f).removeClass(c.focusClass);o(f);d(c.currentSelect).change();return c.onClickCallback(b)},dtClickFunction:function(b){b=h(b);d(b).toggleClass(c.hoverClass);return false},onClickCallback:function(){return false},onChangeCallback:function(){return false},callback:function(){return false},debug:false,currentSelect:{}},m);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(f,
g){d(b).append(q(g))});k(b);n(b);d(b).insertAfter(this);d(this).hide();c.callback(b)});return this}})(jQuery);