// MSDropDown - jquery.dd.js
// author: Marghoob Suleman - Search me on google
// Date: 12th Aug, 2009
// Version: 2.36 {date: 18 Dec, 2010}
// Revision: 31
// web: www.giftlelo.com | www.marghoobsuleman.com
/*
// msDropDown is free jQuery Plugin: you can redistribute it and/or modify
// it under the terms of the either the MIT License or the Gnu General Public License (GPL) Version 2
*/
;(function($){var bh="";var bi=function(p,q){var r=p;var s=this;var q=$.extend({height:120,visibleRows:7,rowHeight:23,showIcon:true,zIndex:9999,mainCSS:'dd',useSprite:false,animStyle:'slideDown',onInit:'',style:''},q);this.ddProp=new Object();var t="";var u={};u.insideWindow=true;u.keyboardAction=false;u.currentKey=null;var v=false;var w={postElementHolder:'_msddHolder',postID:'_msdd',postTitleID:'_title',postTitleTextID:'_titletext',postChildID:'_child',postAID:'_msa',postOPTAID:'_msopta',postInputID:'_msinput',postArrowID:'_arrow',postInputhidden:'_inp'};var x={dd:q.mainCSS,ddTitle:'ddTitle',arrow:'arrow',ddChild:'ddChild',ddTitleText:'ddTitleText',disabled:.30,ddOutOfVision:'ddOutOfVision',borderTop:'borderTop',noBorderTop:'noBorderTop'};var y={actions:"focus,blur,change,click,dblclick,mousedown,mouseup,mouseover,mousemove,mouseout,keypress,keydown,keyup",prop:"size,multiple,disabled,tabindex"};this.onActions=new Object();var z=$(r).attr("id");if(typeof(z)=="undefined"||z.length<=0){z="msdrpdd"+$.msDropDown.counter++;$(r).attr("id",z)};var A=$(r).attr("style");q.style+=(A==undefined)?"":A;var B=$(r).children();v=($(r).attr("size")>1||$(r).attr("multiple")==true)?true:false;if(v){q.visibleRows=$(r).attr("size")};var C={};var D=function(a){return z+w[a]};var E=function(a){var b=a;var c=$(b).attr("style");return c};var F=function(a){var b=$("#"+z+" option:selected");if(b.length>1){for(var i=0;i<b.length;i++){if(a==b[i].index){return true}}}else if(b.length==1){if(b[0].index==a){return true}};return false};var G=function(a,b,c,d){var e="";var f=(d=="opt")?D("postOPTAID"):D("postAID");var g=(d=="opt")?f+"_"+(b)+"_"+(c):f+"_"+(b);var h="";var i="";if(q.useSprite!=false){i=' '+q.useSprite+' '+a.className}else{h=$(a).attr("title");h=(h.length==0)?"":'<img src="'+h+'" align="absmiddle" /> '};var j=$(a).text();var k=$(a).val();var l=($(a).attr("disabled")==true)?"disabled":"enabled";C[g]={html:h+j,value:k,text:j,index:a.index,id:g};var m=E(a);if(F(a.index)==true){e+='<a href="javascript:void(0);" class="selected '+l+i+'"'}else{e+='<a  href="javascript:void(0);" class="'+l+i+'"'};if(m!==false&&m!==undefined){e+=" style='"+m+"'"};e+=' id="'+g+'">';e+=h+'<span class="'+x.ddTitleText+'">'+j+'</span></a>';return e};var H=function(){var f=B;if(f.length==0)return"";var g="";var h=D("postAID");var i=D("postOPTAID");f.each(function(c){var d=f[c];if(d.nodeName=="OPTGROUP"){g+="<div class='opta'>";g+="<span style='font-weight:bold;font-style:italic; clear:both;'>"+$(d).attr("label")+"</span>";var e=$(d).children();e.each(function(a){var b=e[a];g+=G(b,c,a,"opt")});g+="</div>"}else{g+=G(d,c,"","")}});return g};var I=function(){var a=D("postID");var b=D("postChildID");var c=q.style;sDiv="";sDiv+='<div id="'+b+'" class="'+x.ddChild+'"';if(!v){sDiv+=(c!="")?' style="'+c+'"':''}else{sDiv+=(c!="")?' style="border-top:1px solid #c3c3c3;display:block;position:relative;'+c+'"':''};sDiv+='>';return sDiv};var J=function(){var a=D("postTitleID");var b=D("postArrowID");var c=D("postTitleTextID");var d=D("postInputhidden");var e="";var f="";if(document.getElementById(z).options.length>0){e=$("#"+z+" option:selected").text();f=$("#"+z+" option:selected").attr("title")};f=(f.length==0||f==undefined||q.showIcon==false||q.useSprite!=false)?"":'<img src="'+f+'" align="absmiddle" /> ';var g='<div id="'+a+'" class="'+x.ddTitle+'"';g+='>';g+='<span id="'+b+'" class="'+x.arrow+'"></span><span class="'+x.ddTitleText+'" id="'+c+'">'+f+'<span class="'+x.ddTitleText+'">'+e+'</span></span></div>';return g};var K=function(){var c=D("postChildID");$("#"+c+" a.enabled").unbind("click");$("#"+c+" a.enabled").bind("click",function(a){a.preventDefault();N(this);if(!v){$("#"+c).unbind("mouseover");P(false);var b=(q.showIcon==false)?$(this).text():$(this).html();T(b);s.close()};X()})};var L=function(){var d=false;var e=D("postID");var f=D("postTitleID");var g=D("postTitleTextID");var h=D("postChildID");var i=D("postArrowID");var j=$("#"+z).width();j=j+2;var k=q.style;if($("#"+e).length>0){$("#"+e).remove();d=true};var l='<div id="'+e+'" class="'+x.dd+'"';l+=(k!="")?' style="'+k+'"':'';l+='>';l+=J();l+=I();l+=H();l+="</div>";l+="</div>";if(d==true){var m=D("postElementHolder");$("#"+m).after(l)}else{$("#"+z).after(l)};if(v){var f=D("postTitleID");$("#"+f).hide()};$("#"+e).css("width",j+"px");$("#"+h).css("width",(j-2)+"px");if(B.length>q.visibleRows){var n=parseInt($("#"+h+" a:first").css("padding-bottom"))+parseInt($("#"+h+" a:first").css("padding-top"));var o=((q.rowHeight)*q.visibleRows)-n;$("#"+h).css("height",o+"px")}else if(v){var o=$("#"+z).height();$("#"+h).css("height",o+"px")};if(d==false){S();O(z)};if($("#"+z).attr("disabled")==true){$("#"+e).css("opacity",x.disabled)};R();$("#"+f).bind("mouseover",function(a){bj(1)});$("#"+f).bind("mouseout",function(a){bj(0)});K();$("#"+h+" a.disabled").css("opacity",x.disabled);if(v){$("#"+h).bind("mouseover",function(c){if(!u.keyboardAction){u.keyboardAction=true;$(document).bind("keydown",function(a){var b=a.keyCode;u.currentKey=b;if(b==39||b==40){a.preventDefault();a.stopPropagation();U();X()};if(b==37||b==38){a.preventDefault();a.stopPropagation();V();X()}})}})};$("#"+h).bind("mouseout",function(a){P(false);$(document).unbind("keydown");u.keyboardAction=false;u.currentKey=null});$("#"+f).bind("click",function(b){P(false);if($("#"+h+":visible").length==1){$("#"+h).unbind("mouseover")}else{$("#"+h).bind("mouseover",function(a){P(true)});s.open()}});$("#"+f).bind("mouseout",function(a){P(false)});if(q.showIcon&&q.useSprite!=false){W()}};var M=function(a){for(var i in C){if(C[i].index==a){return C[i]}};return-1};var N=function(a){var b=D("postChildID");if($("#"+b+" a.selected").length==1){t=$("#"+b+" a.selected").text()};if(!v){$("#"+b+" a.selected").removeClass("selected")};var c=$("#"+b+" a.selected").attr("id");if(c!=undefined){var d=(u.oldIndex==undefined||u.oldIndex==null)?C[c].index:u.oldIndex};if(a&&!v){$(a).addClass("selected")};if(v){var e=u.currentKey;if($("#"+z).attr("multiple")==true){if(e==17){u.oldIndex=C[$(a).attr("id")].index;$(a).toggleClass("selected")}else if(e==16){$("#"+b+" a.selected").removeClass("selected");$(a).addClass("selected");var f=$(a).attr("id");var g=C[f].index;for(var i=Math.min(d,g);i<=Math.max(d,g);i++){$("#"+M(i).id).addClass("selected")}}else{$("#"+b+" a.selected").removeClass("selected");$(a).addClass("selected");u.oldIndex=C[$(a).attr("id")].index}}else{$("#"+b+" a.selected").removeClass("selected");$(a).addClass("selected");u.oldIndex=C[$(a).attr("id")].index}}};var O=function(a){var b=a;document.getElementById(b).refresh=function(e){$("#"+b).msDropDown(q)}};var P=function(a){u.insideWindow=a};var Q=function(){return u.insideWindow};var R=function(){var b=D("postID");var c=y.actions.split(",");for(var d=0;d<c.length;d++){var e=c[d];var f=Y(e);if(f==true){switch(e){case"focus":$("#"+b).bind("mouseenter",function(a){document.getElementById(z).focus()});break;case"click":$("#"+b).bind("click",function(a){$("#"+z).trigger("click")});break;case"dblclick":$("#"+b).bind("dblclick",function(a){$("#"+z).trigger("dblclick")});break;case"mousedown":$("#"+b).bind("mousedown",function(a){$("#"+z).trigger("mousedown")});break;case"mouseup":$("#"+b).bind("mouseup",function(a){$("#"+z).trigger("mouseup")});break;case"mouseover":$("#"+b).bind("mouseover",function(a){$("#"+z).trigger("mouseover")});break;case"mousemove":$("#"+b).bind("mousemove",function(a){$("#"+z).trigger("mousemove")});break;case"mouseout":$("#"+b).bind("mouseout",function(a){$("#"+z).trigger("mouseout")});break}}}};var S=function(){var a=D("postElementHolder");$("#"+z).after("<div class='"+x.ddOutOfVision+"' style='height:0px;overflow:hidden;position:absolute;' id='"+a+"'></div>");$("#"+z).appendTo($("#"+a))};var T=function(a){var b=D("postTitleTextID");$("#"+b).html(a)};var U=function(){var a=D("postTitleTextID");var b=D("postChildID");var c=$("#"+b+" a.enabled");for(var d=0;d<c.length;d++){var e=c[d];var f=$(e).attr("id");if($(e).hasClass("selected")&&d<c.length-1){$("#"+b+" a.selected").removeClass("selected");$(c[d+1]).addClass("selected");var g=$("#"+b+" a.selected").attr("id");if(!v){var h=(q.showIcon==false)?C[g].text:C[g].html;T(h)};if(parseInt(($("#"+g).position().top+$("#"+g).height()))>=parseInt($("#"+b).height())){$("#"+b).scrollTop(($("#"+b).scrollTop())+$("#"+g).height()+$("#"+g).height())};break}}};var V=function(){var a=D("postTitleTextID");var b=D("postChildID");var c=$("#"+b+" a.enabled");for(var d=0;d<c.length;d++){var e=c[d];var f=$(e).attr("id");if($(e).hasClass("selected")&&d!=0){$("#"+b+" a.selected").removeClass("selected");$(c[d-1]).addClass("selected");var g=$("#"+b+" a.selected").attr("id");if(!v){var h=(q.showIcon==false)?C[g].text:C[g].html;T(h)};if(parseInt(($("#"+g).position().top+$("#"+g).height()))<=0){$("#"+b).scrollTop(($("#"+b).scrollTop()-$("#"+b).height())-$("#"+g).height())};break}}};var W=function(){if(q.useSprite!=false){var a=D("postTitleTextID");var b=document.getElementById(z).options[document.getElementById(z).selectedIndex].className;if(b.length>0){var c=D("postChildID");var d=$("#"+c+" a."+b).attr("id");var e=$("#"+d).css("background-image");var f=$("#"+d).css("background-position");var g=$("#"+d).css("padding-left");if(e!=undefined){$("#"+a).find("."+x.ddTitleText).attr('style',"background:"+e)};if(f!=undefined){$("#"+a).find("."+x.ddTitleText).css('background-position',f)};if(g!=undefined){$("#"+a).find("."+x.ddTitleText).css('padding-left',g)};$("#"+a).find("."+x.ddTitleText).css('background-repeat','no-repeat');$("#"+a).find("."+x.ddTitleText).css('padding-bottom','2px')}}};var X=function(){var a=D("postChildID");var b=$("#"+a+" a.selected");if(b.length==1){var c=$("#"+a+" a.selected").text();var d=$("#"+a+" a.selected").attr("id");if(d!=undefined){var e=C[d].value;document.getElementById(z).selectedIndex=C[d].index};if(q.showIcon&&q.useSprite!=false)W()}else if(b.length>1){var f=$("#"+z+" > option:selected").removeAttr("selected");for(var i=0;i<b.length;i++){var d=$(b[i]).attr("id");var g=C[d].index;document.getElementById(z).options[g].selected="selected"}};var h=document.getElementById(z).selectedIndex;s.ddProp["selectedIndex"]=h};var Y=function(a){if($("#"+z).attr("on"+a)!=undefined){return true};var b=$("#"+z).data("events");if(b&&b[a]){return true};return false};var Z=function(){var b=D("postChildID");if(Y('change')==true){var c=C[$("#"+b+" a.selected").attr("id")].text;if($.trim(t)!==$.trim(c)&&t!==""){$("#"+z).trigger("change")}};if(Y('mouseup')==true){$("#"+z).trigger("mouseup")};if(Y('blur')==true){$(document).bind("mouseup",function(a){$("#"+z).focus();$("#"+z)[0].blur();X();$(document).unbind("mouseup")})}};var bj=function(a){var b=D("postArrowID");if(a==1)$("#"+b).css({backgroundPosition:'0 100%'});else $("#"+b).css({backgroundPosition:'0 0'})};var bk=function(){for(var i in document.getElementById(z)){if(typeof(document.getElementById(z)[i])!='function'&&document.getElementById(z)[i]!==undefined&&document.getElementById(z)[i]!==null){s.set(i,document.getElementById(z)[i],true)}}};var bl=function(a,b){if(M(b)!=-1){document.getElementById(z)[a]=b;var c=D("postChildID");$("#"+c+" a.selected").removeClass("selected");$("#"+M(b).id).addClass("selected");var d=M(document.getElementById(z).selectedIndex).html;T(d)}};var bm=function(i,a){if(a=='d'){for(var b in C){if(C[b].index==i){delete C[b];break}}};var c=0;for(var b in C){C[b].index=c;c++}};var bn=function(){var a=D("postChildID");var b=D("postID");var c=$("#"+b).position();var d=$("#"+b).height();var e=$(window).height();var f=$(window).scrollTop();var g=$("#"+a).height();var h={zIndex:q.zIndex,top:(c.top+d)+"px",display:"none"};var i=q.animStyle;var j=false;var k=x.noBorderTop;$("#"+a).removeClass(x.noBorderTop);$("#"+a).removeClass(x.borderTop);return{opp:j,ani:i,css:h,border:k}};this.open=function(){if((s.get("disabled",true)==true)||(s.get("options",true).length==0))return;var c=D("postChildID");if(bh!=""&&c!=bh){$("#"+bh).slideUp("fast");$("#"+bh).css({zIndex:'0'})};if($("#"+c).css("display")=="none"){t=C[$("#"+c+" a.selected").attr("id")].text;$(document).bind("keydown",function(a){var b=a.keyCode;if(b==39||b==40){a.preventDefault();a.stopPropagation();U()};if(b==37||b==38){a.preventDefault();a.stopPropagation();V()};if(b==27||b==13){s.close();X()};if($("#"+z).attr("onkeydown")!=undefined){document.getElementById(z).onkeydown()}});$(document).bind("keyup",function(a){if($("#"+z).attr("onkeyup")!=undefined){document.getElementById(z).onkeyup()}});$(document).bind("mouseup",function(a){if(Q()==false){s.close()}});var d=bn();$("#"+c).css(d.css);if(d.opp==true){$("#"+c).css({display:'block'});$("#"+c).addClass(d.border);if(s.onActions["onOpen"]!=null){eval(s.onActions["onOpen"])(s)}}else{$("#"+c)[d.ani]("fast",function(){$("#"+c).addClass(d.border);if(s.onActions["onOpen"]!=null){eval(s.onActions["onOpen"])(s)}})};if(c!=bh){bh=c}}};this.close=function(){var b=D("postChildID");$(document).unbind("keydown");$(document).unbind("keyup");$(document).unbind("mouseup");var c=bn();if(c.opp==true){$("#"+b).css("display","none")};$("#"+b).slideUp("fast",function(a){Z();$("#"+b).css({zIndex:'0'});if(s.onActions["onClose"]!=null){eval(s.onActions["onClose"])(s)}})};this.selectedIndex=function(i){s.set("selectedIndex",i)};this.set=function(a,b,c){if(a==undefined||b==undefined)throw{message:"set to what?"};s.ddProp[a]=b;if(c!=true){switch(a){case"selectedIndex":bl(a,b);break;case"disabled":s.disabled(b,true);break;case"multiple":document.getElementById(z)[a]=b;v=($(r).attr("size")>0||$(r).attr("multiple")==true)?true:false;if(v){var d=$("#"+z).height();var f=D("postChildID");$("#"+f).css("height",d+"px");var g=D("postTitleID");$("#"+g).hide();var f=D("postChildID");$("#"+f).css({display:'block',position:'relative'});K()};break;case"size":document.getElementById(z)[a]=b;if(b==0){document.getElementById(z).multiple=false};v=($(r).attr("size")>0||$(r).attr("multiple")==true)?true:false;if(b==0){var g=D("postTitleID");$("#"+g).show();var f=D("postChildID");$("#"+f).css({display:'none',position:'absolute'});var h="";if(document.getElementById(z).selectedIndex>=0){var i=M(document.getElementById(z).selectedIndex);h=i.html;N($("#"+i.id))};T(h)}else{var g=D("postTitleID");$("#"+g).hide();var f=D("postChildID");$("#"+f).css({display:'block',position:'relative'})};break;default:try{document.getElementById(z)[a]=b}catch(e){};break}}};this.get=function(a,b){if(a==undefined&&b==undefined){return s.ddProp};if(a!=undefined&&b==undefined){return(s.ddProp[a]!=undefined)?s.ddProp[a]:null};if(a!=undefined&&b!=undefined){return document.getElementById(z)[a]}};this.visible=function(a){var b=D("postID");if(a==true){$("#"+b).show()}else if(a==false){$("#"+b).hide()}else{return $("#"+b).css("display")}};this.add=function(a,b){var c=a;var d=c.text;var e=(c.value==undefined||c.value==null)?d:c.value;var f=(c["title"]==undefined||c["title"]==null)?'':c["title"];var i=(b==undefined||b==null)?document.getElementById(z).options.length:b;document.getElementById(z).options[i]=new Option(d,e);if(f!='')document.getElementById(z).options[i]["title"]=f;var g=M(i);if(g!=-1){var h=G(document.getElementById(z).options[i],i,"","");$("#"+g.id).html(h)}else{var h=G(document.getElementById(z).options[i],i,"","");var j=D("postChildID");$("#"+j).append(h);K()}};this.remove=function(i){document.getElementById(z).remove(i);if((M(i))!=-1){$("#"+M(i).id).remove();bm(i,'d')};if(document.getElementById(z).length==0){T("")}else{var a=M(document.getElementById(z).selectedIndex).html;T(a)};s.set("selectedIndex",document.getElementById(z).selectedIndex)};this.disabled=function(a,b){document.getElementById(z).disabled=a;var c=D("postID");if(a==true){$("#"+c).css("opacity",x.disabled);s.close()}else if(a==false){$("#"+c).css("opacity",1)};if(b!=true){s.set("disabled",a)}};this.form=function(){return(document.getElementById(z).form==undefined)?null:document.getElementById(z).form};this.item=function(){if(arguments.length==1){return document.getElementById(z).item(arguments[0])}else if(arguments.length==2){return document.getElementById(z).item(arguments[0],arguments[1])}else{throw{message:"An index is required!"}}};this.namedItem=function(a){return document.getElementById(z).namedItem(a)};this.multiple=function(a){if(a==undefined){return s.get("multiple")}else{s.set("multiple",a)}};this.size=function(a){if(a==undefined){return s.get("size")}else{s.set("size",a)}};this.addMyEvent=function(a,b){s.onActions[a]=b};this.fireEvent=function(a){eval(s.onActions[a])(s)};var bo=function(){s.set("version",$.msDropDown.version);s.set("author",$.msDropDown.author)};var bp=function(){L();bk();bo();if(q.onInit!=''){eval(q.onInit)(s)}};bp()};$.msDropDown={version:2.36,author:"Marghoob Suleman",counter:20,create:function(a,b){return $(a).msDropDown(b).data("dd")}};$.fn.extend({msDropDown:function(b){return this.each(function(){var a=new bi(this,b);$(this).data('dd',a)})}})})(jQuery);
