/*  
* 		jCombox 1.0b | 2008.08.25
*		jQuery: HTML Select Tag Replacement Plugin 1.0b
*		Licensed under a Creative Commons Attribution 3.0 License
*
*		Tested to work on Firefox2/3, IE6/7, Safari3.1(Win) and Opera9.5 versions
*		Limitations: no keyboard usage + no multiple selections > checkout next version
*		_______________________________________________
* 		http://jquerylab.com | Sponsored by http://12tb.com
*		ruvanepa@gmail.com
*
*		How-to use: $('.select').jcombox();
*			or replce all <select> tags: $('select').jcombox();
*/
/*
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(8($){$.l.C=8(a){D b=5.1C();7($(1D).p()+(10.1E.1l||10.1F.1l)<b.R().S+5.p()+b.p()){11=b.R().S-($.t.w?3:1)-5.p()}x{11=b.R().S+($.t.w?-1:1)+b.p()}q 5.f({12:b.R().12-($.t.w?2:0),S:11,k:b.k()+($.t.w?2:0)})};$.l.y=8(o){q 5.13({14:o},0,8(){7(o==1&&$.t.w){5.1G.1H("1I")}})};$.l.15=8(o){o=$.1J({l:16,1m:"E",1n:"1K",K:0,T:L,z:"1L",1o:16},o||{});q 5.1p(8(){D b=$(5),U="",A=b.n("17"),18=$("19",b).V(0).g(),W=$("19",b).V(0).r(),6="#"+A,F=b.n("1M"),1a=b.n("1N")||0,1b=b.n("k")||0,1O=b.n("1c")||0,M=b.n("1P")||b.n("1Q")||0;$("19",b).1p(8(){7($(5).n("1R")){18=$(5).g();W=$(5).r()}U+=("<a 1d=\'"+(o.1o!=16?"?"+A+"="+$(5).r():"#")+"\' G=\'"+$(5).r()+"\' >"+$(5).g()+"</a>")});7(F>0){b.1e("<9 N=\'15-m "+o.z+"\' 1q=\'"+A+"\'><1r 1s=\'u\' 17=\'"+A+"\' 1t=\'"+W+"\' /><9>"+U+"</9></9>");$(6).f("v-B","1u");7(!$("9 a",6).V(0).g()){$("9 a",6).V(0).g("-")}$(6).k($("9",6).k()+1v+"H");$(6).p($("9 a",6).p()*F+($.t.w?4:2)+"H")}x{b.1e("<9 N=\'15 "+o.z+"\' 1q=\'"+A+"\'><h>"+18+"</h><1r 1s=\'u\' 17=\'"+A+"\' 1t=\'"+W+"\' /><9 N=\'1S\'>"+U+"</9></9>");D c=$(6);7($("h",6).k()>$("9",6).k()){$(6).k($("h",6).k()+1T+"H")}x{$(6).k($("9",6).k()+1v+"H")}7(1a>1){$("9",6).p($("h",6).p()*1a+($.t.w?2:0)+"H")}$(10).s(8(e){7($("9",6).f("1f")=="1g"){$("9",6).1w()}});c.X(8(){1U(5.1x)},8(){5.1x=1V(8(){7($("9",6).f("1f")=="1g"){c.O("s")}},1W)});7(!$("h",6).g()){$("h",6).g("-")}7(o.T){c.f({"1y":"1h","v-1i":"1h","1z-1X":"1Y"});$("h",6).f({"1y":"1h","v-B":c.f("v-B"),"v-1Z":"12 20","1z":"0 21 22 23"})}}$("9",6).24("a[G=\'"+$(":u",6).r()+"\']").1j("j");$(6).I("1k",8(){$(":u",6).r("");7($("9",6).f("1f")=="1g"&&!F>0){$("9",6).1w()}$(6).y(0.3).Y("s");$("9 a",6).Y("s").I("s",8(){q L})});$(6).I("J",8(){$(5).y(1);$(":u",5).r($(".j",5).n("G"));7(!F>0){$(6).Y("s").I("s",8(e){D a=$("9",6);25(o.1m){P"E":a.C().E();Q;P"26":a.C().1A(o.K);Q;P"27":a.C().13({14:"E"},o.K).y(1);Q;P"28":a.C().13({14:"E",p:"E"},o.K).y(1);Q;P"29":a.C().1A(o.K,o.1n);Q}e.2a()})}$("a",6).Y("s").I("s",8(){7($(5).2b("1c")){q L}$("a",6).Z("j");$(5).1j("j");7($.t.2c){$(5).y(0.2d).y(1)}7(!F>0){$("h",6).g($(5).g());$(6).O("s")}$(":u",6).r($(5).n("G"));7(o.l){o.l()}7($.t.w&&M){1B(M())}x{7(M){1B(M)}}q L});$("a",5).f("1i",$("."+o.z).f("1i"));$("h",5).f("2e","u")});7(b.n("1c")){$(6).O("1k")}x{$(6).O("J")}$(6).I("2f 2g",8(){q L}).f("2h","1u");$(6).X(8(){$(5).1j(o.z+"-X");7(o.T){$("h",6).f("v-B",c.f("v-B"))}},8(){$(5).Z(o.z+"-X");7(o.T){$("h",6).f("v-B",$("."+o.z).f("v-B"))}});7(1b){$(6).k(1b+"H")}})};D d=["J","1k"];2i(D i=0;i<d.2j;i++){$.l[d[i]]=(8(a){q 8(){5.O(a)}})(d[i])}$.l.2k=8(a){7(a){q $(".j",5).g()}x{q $(":u",5).r()}};$.l.2l=8(a,b,c){7(c){$("a.j",5).Z()}$("9",5).2m("<a "+(c?"N=\'j\'":"")+" 1d=\'#\' G=\'"+a+"\' >"+b+"</a>");7(c){$("h",5).g($(".j",5).g())}5.J()};$.l.2n=8(a,b){$(".j",5).1e("<a N=\'j\' 1d=\'#\' G=\'"+a+"\' >"+b+"</a>");5.J();7($(".j",5).g()){$("h",5).g($(".j",5).g())}};$.l.2o=8(a){7(a){$("a.j",5).Z()}x{$(".j",5).2p(8(){$(5).2q()})}5.J();$("h",5).g("-");$(":u",5).r("")}})(2r);',62,152,'|||||this|_b|if|function|div||||||css|text|span||current|width|fn||attr||height|return|val|click|browser|hidden|background|msie|else|fadesTo|theme|_8|image|setOffCss|var|toggle|_c|rel|px|bind|jcEnable|fxDelay|false|_10|class|trigger|case|break|offset|top|set|_7|eq|_a|hover|unbind|removeClass|document|objTop|left|animate|opacity|jcombox|null|name|_9|option|_d|_e|disabled|href|replaceWith|display|block|transparent|color|addClass|jcDisable|scrollTop|fx|fxType|linkUrl|each|id|input|type|value|none|40|hide|timeout|border|padding|slideToggle|eval|parent|window|documentElement|body|style|removeAttribute|filter|extend|easeOutBounce|default|size|rows|_f|onchange|onChange|selected|menu|35|clearTimeout|setTimeout|750|right|2px|position|center|0px|3px|5px|find|switch|slide|fade|slideFade|easing|stopPropagation|hasClass|safari|99|overflow|selectstart|mousedown|MozUserSelect|for|length|jcSelected|jcAdd|append|jcEdit|jcClear|slideUp|remove|jQuery'.split('|'),0,{}))
*/

(function($)
	{
	$.fn.setOffCss=function(a)
		{
		var b=this.parent();
		if($(window).height()+(document.documentElement.scrollTop||document.body.scrollTop)<b.offset().top+this.height()+b.height())
			{
			objTop=b.offset().top-($.browser.msie?3:1)-this.height()
		}
		else
			{
			objTop=b.offset().top+($.browser.msie?-1:1)+b.height()
		}
		return this.css(
			{
			//left:b.offset().left-($.browser.msie?2:0),top:objTop,width:b.width()+($.browser.msie?2:0)
		}
		)
	};
	$.fn.fadesTo=function(o)
		{
		return this.animate(
			{
			opacity:o
		}
		,0,function()
			{
			if(o==1&&$.browser.msie)
				{
				this.style.removeAttribute("filter")
			}
		}
		)
	};
	$.fn.jcombox=function(o)
		{
		o=$.extend(
			{
			fn:null,fx:"toggle",fxType:"easeOutBounce",fxDelay:0,set:false,theme:"default",linkUrl:null
		}
		,o||
			{
		}
		);
		return this.each(function()
			{
			var b=$(this),_7="",_8=b.attr("name"),_9=$("option",b).eq(0).text(),_a=$("option",b).eq(0).val(),_b="#"+_8,_c=b.attr("size"),_d=b.attr("rows")||0,_e=b.attr("width")||0,_f=b.attr("disabled")||0,_10=b.attr("onchange")||b.attr("onChange")||0;
			$("option",b).each(function()
				{
				if($(this).attr("selected"))
					{
					_9=$(this).text();
					_a=$(this).val()
				}
				_7+=("<a href='"+(o.linkUrl!=null?"?"+_8+"="+$(this).val():"#")+"' rel='"+$(this).val()+"' >"+$(this).text()+"</a>")
			}
			);
			if(_c>0)
				{
				b.replaceWith("<div class='jcombox-m "+o.theme+"' id='"+_8+"'><input type='hidden' name='"+_8+"' id='"+_8+"' value='"+_a+"' /><div>"+_7+"</div></div>");
				$(_b).css("background-image","none");
				if(!$("div a",_b).eq(0).text())
					{
					$("div a",_b).eq(0).text("-")
				}
				$(_b).width($("div",_b).width()+40+"px");
				$(_b).height($("div a",_b).height()*_c+($.browser.msie?4:2)+"px")
			}
			else
				{
				b.replaceWith("<div class='jcombox "+o.theme+"' id='"+_8+"'><span>"+_9+"</span><input type='hidden' name='"+_8+"' id='"+_8+"' value='"+_a+"' /><div class='menu'>"+_7+"</div></div>");
				var c=$(_b);
				if($("span",_b).width()>$("div",_b).width())
					{
					$(_b).width($("span",_b).width()+35+"px")
				}
				else
					{
					//$(_b).width($("div",_b).width()+40+"px") //auto width removed
				}
				if(_d>1)
					{
					$("div",_b).height($("span",_b).height()*_d+($.browser.msie?2:0)+"px")
				}
				$(document).click(function(e)
					{
					if($("div",_b).css("display")=="block")
						{
						$("div",_b).hide()
					}
				}
				);
				c.hover(function()
					{
					clearTimeout(this.timeout)
				}
				,function()
					{
					this.timeout=setTimeout(function()
						{
						if($("div",_b).css("display")=="block")
							{
							c.trigger("click")
						}
					}
					,750)
				}
				);
				if(!$("span",_b).text())
					{
					$("span",_b).text("-")
				}
				if(o.set)
					{
					c.css(
						{
						"border":"transparent","background-color":"transparent","padding-right":"2px"
					}
					);
					$("span",_b).css(
						{
						"border":"transparent","background-image":c.css("background-image"),"background-position":"left center","padding":"0 0px 3px 5px"
					}
					)
				}
			}
			$("div",_b).find("a[rel='"+$(":hidden",_b).val()+"']").addClass("current");
			$(_b).bind("jcDisable",function()
				{
				$(":hidden",_b).val("");
				if($("div",_b).css("display")=="block"&&!_c>0)
					{
					$("div",_b).hide()
				}
				$(_b).fadesTo(0.3).unbind("click");
				$("div a",_b).unbind("click").bind("click",function()
					{
					return false
				}
				)
			}
			);
			$(_b).bind("jcEnable",function()
				{
				$(this).fadesTo(1);
				$(":hidden",this).val($(".current",this).attr("rel"));
				if(!_c>0)
					{
					$(_b).unbind("click").bind("click",function(e)
						{
						var a=$("div",_b);
						switch(o.fx)
							{
							case"toggle":a.setOffCss().toggle();
							break;
							case"slide":a.setOffCss().slideToggle(o.fxDelay);
							break;
							case"fade":a.setOffCss().animate(
								{
								opacity:"toggle"
							}
							,o.fxDelay).fadesTo(1);
							break;
							case"slideFade":a.setOffCss().animate(
								{
								opacity:"toggle",height:"toggle"
							}
							,o.fxDelay).fadesTo(1);
							break;
							case"easing":a.setOffCss().slideToggle(o.fxDelay,o.fxType);
							break
						}
						e.stopPropagation()
					}
					)
				}
				$("a",_b).unbind("click").bind("click",function()
					{
					if($(this).hasClass("disabled"))
						{
						return false
					}
					$("a",_b).removeClass("current");
					$(this).addClass("current");
					if($.browser.safari)
						{
						$(this).fadesTo(0.99).fadesTo(1)
					}
					if(!_c>0)
						{
						$("span",_b).text($(this).text());
						$(_b).trigger("click")
					}
					$(":hidden",_b).val($(this).attr("rel"));
					if(o.fn)
						{
						o.fn()
					}
					if($.browser.msie&&_10)
						{
						eval(_10())
					}
					else
						{
						if(_10)
							{
							eval(_10)
						}
					}
					return false
				}
				);
				//$("a",this).css("color",$("."+o.theme).css("color"));
				$("span",this).css("overflow","hidden")
			}
			);
			if(b.attr("disabled"))
				{
				$(_b).trigger("jcDisable")
			}
			else
				{
				$(_b).trigger("jcEnable")
			}
			$(_b).bind("selectstart mousedown",function()
				{
				return false
			}
			).css("MozUserSelect","none");
			$(_b).hover(function()
				{
				$(this).addClass(o.theme+"-hover");
				if(o.set)
					{
					$("span",_b).css("background-image",c.css("background-image"))
				}
			}
			,function()
				{
				$(this).removeClass(o.theme+"-hover");
				if(o.set)
					{
					$("span",_b).css("background-image",$("."+o.theme).css("background-image"))
				}
			}
			);
			if(_e)
				{
				$(_b).width(_e+"px")
			}
		}
		)
	};
	var d=["jcEnable","jcDisable"];
	for(var i=0;
	i<d.length;
	i++)
		{
		$.fn[d[i]]=(function(a)
			{
			return function()
				{
				this.trigger(a)
			}
		}
		)(d[i])
	}
	$.fn.jcSelected=function(a)
		{
		if(a)
			{
			return $(".current",this).text()
		}
		else
			{
			return $(":hidden",this).val()
		}
	};
	$.fn.jcAdd=function(a,b,c)
		{
		if(c)
			{
			$("a.current",this).removeClass()
		}
		$("div",this).append("<a "+(c?"class='current'":"")+" href='#' rel='"+a+"' >"+b+"</a>");
		if(c)
			{
			$("span",this).text($(".current",this).text())
		}
		this.jcEnable()
	};
	$.fn.jcEdit=function(a,b)
		{
		$(".current",this).replaceWith("<a class='current' href='#' rel='"+a+"' >"+b+"</a>");
		this.jcEnable();
		if($(".current",this).text())
			{
			$("span",this).text($(".current",this).text())
		}
	};
	$.fn.jcClear=function(a)
		{
		if(a)
			{
			$("a.current",this).removeClass()
		}
		else
			{
			$(".current",this).slideUp(function()
				{
				$(this).remove()
			}
			)
		}
		this.jcEnable();
		$("span",this).text("-");
		$(":hidden",this).val("")
	}
}
)(jQuery);