 // MSDropDown - jquery.dd.js
// author: Marghoob Suleman
// Date: 12th Aug, 2009
// Version: 2.1 {date: 3rd Sep 2009}
// Revision: 25
// web: www.giftlelo.com | www.marghoobsuleman.com
/* 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}(';(5($){3 D="";$.2h.10=5(v){$O=O;v=$.2T({S:2U,1o:7,2i:23,1h:J,1i:2V,M:\'\'},v);3 w="";3 x={};x.1F=J;x.1p=H;x.1q=1G;3 y=H;2j={1H:\'2W\',1r:\'2X\',1I:\'2Y\',18:\'2Z\',T:\'31\',2k:\'32\',2l:\'33\',34:\'35\',1s:\'36\',2m:\'3a\'};11={10:\'10\',1J:\'1J\',1K:\'1K\',1L:\'1L\',1M:.30};2n={2o:"2p,2q,1N,1O,1P,1Q,1j,1R,1S,1T,3b,1U,1V",3c:"1W,1X,12,3d"};3 z=$(O).8("E");3 A=$(O).8("M");v.M+=(A==Q)?"":A;3 B=$(O).2r();y=($(O).8("1W")>0||$(O).8("1X")==J)?J:H;4(y){v.1o=$(O).8("1W")};3 C={};2s();5 9(a){U z+2j[a]};5 1Y(a){3 b=a;3 c=$(b).8("M");U c};5 1Z(a){3 b=$("#"+z+" 1t:6");4(b.I>1){Y(3 i=0;i<b.I;i++){4(a==b[i].K){U J}}}N 4(b.I==1){4(b[0].K==a){U J}};U H}5 2t(){3 r=B;3 s="";3 t=9("2k");3 u=9("2l");r.2u(5(i){3 j=r[i];4(j.3e=="3f"){s+="<V W=\'3g\'>";s+="<19 M=\'2v-3h:3i;2v-M:3j; 3k:3l;\'>"+$(j).8("3m")+"</19>";3 k=$(j).2r();k.2u(5(a){3 b=k[a];3 c=u+"20"+(i)+"20"+(a);3 d=$(b).8("21");d=(d.I==0)?"":\'<22 24="\'+d+\'" 25="26" /> \';3 e=$(b).R();3 f=$(b).2w();3 g=($(b).8("12")==J)?"12":"1k";C[c]={1a:d+e,28:f,R:e,K:b.K,E:c};3 h=1Y(b);4(1Z(b.K)==J){s+=\'<a 1u="1v:1w(0);" W="6 \'+g+\'"\'}N{s+=\'<a  1u="1v:1w(0);" W="\'+g+\'"\'};4(h!=H)s+=\' M="\'+h+\'"\';s+=\' E="\'+c+\'">\';s+=d+e+\'</a>\'});s+="</V>"}N{3 l=t+"20"+(i);3 m=$(j).8("21");m=(m.I==0)?"":\'<22 24="\'+m+\'" 25="26" /> \';3 n=$(j).R();3 o=$(j).2w();3 p=($(j).8("12")==J)?"12":"1k";C[l]={1a:m+n,28:o,R:n,K:j.K,E:l};3 q=1Y(j);4(1Z(j.K)==J){s+=\'<a 1u="1v:1w(0);" W="6 \'+p+\'"\'}N{s+=\'<a  1u="1v:1w(0);" W="\'+p+\'"\'};4(q!=H)s+=\' M="\'+q+\'"\';s+=\' E="\'+l+\'">\';s+=m+n+\'</a>\'}});U s};5 2x(){3 a=9("1r");3 b=9("T");3 c=v.M;1b="";1b+=\'<V E="\'+b+\'" W="\'+11.1L+\'"\';4(!y){1b+=(c!="")?\' M="\'+c+\'"\':\'\'}N{1b+=(c!="")?\' M="3n-1x:3o 3p #3q;2y:3r;1y:3s;\'+c+\'"\':\'\'}1b+=\'>\';U 1b};5 2z(){3 a=9("1I");3 b=9("1s");3 c=9("18");3 d=9("2m");3 e=$("#"+z+" 1t:6").R();3 f=$("#"+z+" 1t:6").8("21");f=(f.I==0||f==Q||v.1h==H)?"":\'<22 24="\'+f+\'" 25="26" /> \';3 g=\'<V E="\'+a+\'" W="\'+11.1J+\'"\';g+=\'>\';g+=\'<19 E="\'+b+\'" W="\'+11.1K+\'"></19><19 W="3t" E="\'+c+\'">\'+f+e+\'</19></V>\';U g};5 2s(){3 d=H;3 e=9("1r");3 f=9("1I");3 g=9("18");3 h=9("T");3 i=9("1s");3 j=$("#"+z).29();3 k=v.M;4($("#"+e).I>0){$("#"+e).3u();d=J}3 l=\'<V E="\'+e+\'" W="\'+11.10+\'"\';l+=(k!="")?\' M="\'+k+\'"\':\'\';l+=\'>\';4(!y)l+=2z();l+=2x();l+=2t();l+="</V>";l+="</V>";4(d==J){3 m=9("1H");$("#"+m).2a(l)}N{$("#"+z).2a(l)}$("#"+e).P("29",j+"2b");$("#"+h).P("29",(j-2)+"2b");4(B.I>v.1o){3 n=1l($("#"+h+" a:2A").P("2B-3v"))+1l($("#"+h+" a:2A").P("2B-1x"));3 o=((v.2i)*v.1o)-n;$("#"+h).P("S",o+"2b")}4(d==H){2C();2D(z)}4($("#"+z).8("12")==J){$("#"+e).P("2E",11.1M)}N{2F();4(!y){$("#"+f).G("1c",5(a){2c(1)});$("#"+f).G("1z",5(a){2c(0)})};$("#"+h+" a.1k").G("2d",5(a){a.1m();2G(O);4(!y){$("#"+h).14("1c");1d(H);3 b=(v.1h==H)?$(O).R():$(O).1a();1A(b);1B()};1e()});$("#"+h+" a.12").P("2E",11.1M);4(y){$("#"+h).G("1c",5(c){4(!x.1p){x.1p=J;$(F).G("1C",5(a){3 b=a.2H;x.1q=b;4(b==39||b==2I){a.1m();a.1D();2e();1e()};4(b==37||b==38){a.1m();a.1D();2f();1e()}})}})};$("#"+h).G("1z",5(a){1d(H);$(F).14("1C");x.1p=H;x.1q=1G});4(!y){$("#"+f).G("2d",5(b){1d(H);4($("#"+h+":3w").I==1){$("#"+h).14("1c")}N{$("#"+h).G("1c",5(a){1d(J)});2J()}})};$("#"+f).G("1z",5(a){1d(H)})}};5 2K(a){Y(3 i 3x C){4(C[i].K==a){U C[i]}}}5 2G(a){3 b=9("T");4(!y){$("#"+b+" a.6").1f("6")}3 c=$("#"+b+" a.6").8("E");4(c!=Q){3 d=(x.1g==Q||x.1g==1G)?C[c].K:x.1g};4(a&&!y){$(a).15("6")};4(y){3 e=x.1q;4($("#"+z).8("1X")==J){4(e==17){x.1g=C[$(a).8("E")].K;$(a).3y("6")}N 4(e==16){$("#"+b+" a.6").1f("6");$(a).15("6");3 f=$(a).8("E");3 g=C[f].K;Y(3 i=2L.3z(d,g);i<=2L.3A(d,g);i++){$("#"+2K(i).E).15("6")}}N{$("#"+b+" a.6").1f("6");$(a).15("6");x.1g=C[$(a).8("E")].K}}N{$("#"+b+" a.6").1f("6");$(a).15("6");x.1g=C[$(a).8("E")].K}}};5 2D(a){F.L(a).3B=5(e){$("#"+O.E).10(v)}};5 1d(a){x.1F=a};5 2M(){U x.1F};5 2F(){3 b=9("1r");3 c=2n.2o.3C(",");Y(3 d=0;d<c.I;d++){3 e=c[d];3 f=$("#"+z).8(e);4(f!=Q){3D(e){Z"2p":$("#"+b).G("3E",5(a){F.L(z).2N()});X;Z"1O":$("#"+b).G("2d",5(a){F.L(z).1O()});X;Z"1P":$("#"+b).G("3F",5(a){F.L(z).1P()});X;Z"1Q":$("#"+b).G("3G",5(a){F.L(z).1Q()});X;Z"1j":$("#"+b).G("1n",5(a){F.L(z).1j()});X;Z"1R":$("#"+b).G("1c",5(a){F.L(z).1R()});X;Z"1S":$("#"+b).G("3H",5(a){F.L(z).1S()});X;Z"1T":$("#"+b).G("1z",5(a){F.L(z).1T()});X}}}};5 2C(){3 a=9("1H");$("#"+z).2a("<V M=\'S:3I;3J:3K;1y:3L;\' E=\'"+a+"\'></V>");$("#"+z).3M($("#"+a))};5 1A(a){3 b=9("18");$("#"+b).1a(a)};5 2e(){3 a=9("18");3 b=9("T");3 c=$("#"+b+" a.1k");Y(3 d=0;d<c.I;d++){3 e=c[d];3 f=$(e).8("E");4($(e).2O("6")&&d<c.I-1){$("#"+b+" a.6").1f("6");$(c[d+1]).15("6");3 g=$("#"+b+" a.6").8("E");4(!y){3 h=(v.1h==H)?C[g].R:C[g].1a;1A(h)}4(1l(($("#"+g).1y().1x+$("#"+g).S()))>=1l($("#"+b).S())){$("#"+b).1E(($("#"+b).1E())+$("#"+g).S()+$("#"+g).S())};X}}};5 2f(){3 a=9("18");3 b=9("T");3 c=$("#"+b+" a.1k");Y(3 d=0;d<c.I;d++){3 e=c[d];3 f=$(e).8("E");4($(e).2O("6")&&d!=0){$("#"+b+" a.6").1f("6");$(c[d-1]).15("6");3 g=$("#"+b+" a.6").8("E");4(!y){3 h=(v.1h==H)?C[g].R:C[g].1a;1A(h)}4(1l(($("#"+g).1y().1x+$("#"+g).S()))<=0){$("#"+b).1E(($("#"+b).1E()-$("#"+b).S())-$("#"+g).S())};X}}};5 1e(){3 a=9("T");3 b=$("#"+a+" a.6");4(b.I==1){3 c=$("#"+a+" a.6").R();3 d=$("#"+a+" a.6").8("E");4(d!=Q){3 e=C[d].28;F.L(z).3N=C[d].K}}N 4(b.I>1){3 f=$("#"+z+" > 1t:6").3O("6");Y(3 i=0;i<b.I;i++){3 d=$(b[i]).8("E");3 g=C[d].K;F.L(z).3P[g].6="6"}}};5 2J(){3 c=9("T");4(D!=""&&c!=D){$("#"+D).2P("2g");$("#"+D).P({1i:\'0\'})};4($("#"+c).P("2y")=="3Q"){w=C[$("#"+c+" a.6").8("E")].R;$(F).G("1C",5(a){3 b=a.2H;4(b==39||b==2I){a.1m();a.1D();2e()};4(b==37||b==38){a.1m();a.1D();2f()};4(b==27||b==13){1B();1e()};4($("#"+z).8("1U")!=Q){F.L(z).1U()}});$(F).G("2Q",5(a){4($("#"+z).8("1V")!=Q){F.L(z).1V()}});$(F).G("1n",5(a){4(2M()==H){1B()}});$("#"+c).P({1i:v.1i});$("#"+c).3R("2g");4(c!=D){D=c}}};5 1B(){3 b=9("T");$(F).14("1C");$(F).14("2Q");$(F).14("1n");$("#"+b).2P("2g",5(a){2R();$("#"+b).P({1i:\'0\'})})};5 2R(){3 b=9("T");4($("#"+z).8("1N")!=Q){3 c=C[$("#"+b+" a.6").8("E")].R;4(w!=c){F.L(z).1N()}}4($("#"+z).8("1j")!=Q){F.L(z).1j()}4($("#"+z).8("2q")!=Q){$(F).G("1n",5(a){$("#"+z).2N();$("#"+z)[0].3S();1e();$(F).14("1n")})}};5 2c(a){3 b=9("1s");4(a==1)$("#"+b).P({2S:\'0 3T%\'});N $("#"+b).P({2S:\'0 0\'})}};$.2h.3U=5(a){3 b=$(O);Y(3 c=0;c<b.I;c++){3 d=$(b[c]).8("E");4(a==Q){$("#"+d).10()}N{$("#"+d).10(a)}}}})(3V);',62,244,'|||var|if|function|selected||attr|getPostID|||||||||||||||||||||||||||||||id|document|bind|false|length|true|index|getElementById|style|else|this|css|undefined|text|height|postChildID|return|div|class|break|for|case|dd|styles|disabled||unbind|addClass|||postTitleTextID|span|html|sDiv|mouseover|setInsideWindow|setValue|removeClass|oldIndex|showIcon|zIndex|onmouseup|enabled|parseInt|preventDefault|mouseup|visibleRows|keyboardAction|currentKey|postID|postArrowID|option|href|javascript|void|top|position|mouseout|setTitleText|closeMe|keydown|stopPropagation|scrollTop|insideWindow|null|postElementHolder|postTitleID|ddTitle|arrow|ddChild|disbaled|onchange|onclick|ondblclick|onmousedown|onmouseover|onmousemove|onmouseout|onkeydown|onkeyup|size|multiple|getOptionsProperties|matchIndex|_|title|img||src|align|left||value|width|after|px|hightlightArrow|click|next|previous|fast|fn|rowHeight|config|postAID|postOPTAID|postInputhidden|attributes|actions|onfocus|onblur|children|createDropDown|createATags|each|font|val|createChildDiv|display|createTitleDiv|first|padding|setOutOfVision|addNewEvents|opacity|applyEvents|manageSelection|keyCode|40|openMe|getByIndex|Math|getInsideWindow|focus|hasClass|slideUp|keyup|checkMethodAndApply|backgroundPosition|extend|120|9999|_msddHolder|_msdd|_title|_titletext||_child|_msa|_msopta|postInputID|_msinput|_arrow||||_inp|onkeypress|prop|tabindex|nodeName|OPTGROUP|opta|weight|bold|italic|clear|both|label|border|1px|solid|54af4f|block|relative|textTitle|remove|bottom|visible|in|toggleClass|min|max|refresh|split|switch|mouseenter|dblclick|mousedown|mousemove|0px|overflow|hidden|absolute|appendTo|selectedIndex|removeAttr|options|none|slideDown|blur|100|msDropDown|jQuery'.split('|'),0,{}))
*/

// MSDropDown - jquery.dd.js
// author: Marghoob Suleman
// Date: 12th Aug, 2009
// Version: 2.1 {date: 3rd Sep 2009}
// Revision: 25
// web: www.giftlelo.com | www.marghoobsuleman.com
// MSDropDown - jquery.dd.js
// author: Marghoob Suleman
// Date: 12th Aug, 2009
// Version: 2.1 {date: 3rd Sep 2009}
// Revision: 25
// 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 oldDiv = "";
    $.fn.dd = function(options) {
        $this =  this;
        options = $.extend({
            height:120,
            visibleRows:7,
            rowHeight:23,
            showIcon:true,
            zIndex:9999,
            style:''
        }, options);
        var selectedValue = "";
        var actionSettings ={};
        actionSettings.insideWindow = true;
        actionSettings.keyboardAction = false;
        actionSettings.currentKey = null;
        var ddList = false;
        config = {postElementHolder:'_msddHolder', postID:'_msdd', postTitleID:'_title',postTitleTextID:'_titletext',postChildID:'_child',postAID:'_msa',postOPTAID:'_msopta',postInputID:'_msinput', postArrowID:'_arrow', postInputhidden:'_inp'};
        styles = {dd:'dd', ddTitle:'ddTitle', arrow:'arrow', ddChild:'ddChild', disbaled:.30};
        attributes = {actions:"onfocus,onblur,onchange,onclick,ondblclick,onmousedown,onmouseup,onmouseover,onmousemove,onmouseout,onkeypress,onkeydown,onkeyup", prop:"size,multiple,disabled,tabindex"};
        var elementid = $(this).attr("id");
        var inlineCSS = $(this).attr("style");
        options.style += (inlineCSS==undefined) ? "" : inlineCSS;
        var allOptions = $(this).children();
        ddList = ($(this).attr("size")>0 || $(this).attr("multiple")==true) ? true : false;
        if(ddList) {options.visibleRows = $(this).attr("size");};
        var a_array = {};//stores id, html & value etc
        //create wrapper
        createDropDown();
    
    function getPostID(id) {
        return elementid+config[id];
    };
    function getOptionsProperties(option) {
        var currentOption = option;
        var styles = $(currentOption).attr("style");
        return styles;
    };
    function matchIndex(index) {
        var selectedIndex = $("#"+elementid+" option:selected");
        if(selectedIndex.length>1) {
            for(var i=0;i<selectedIndex.length;i++) {
                if(index == selectedIndex[i].index) {
                    return true;
                };
            };
        } else if(selectedIndex.length==1) {
            if(selectedIndex[0].index==index) {
                return true;
            };
        };
        return false;
    }
    function createATags() {
        var childnodes = allOptions;
        var aTag = "";
        var aidfix = getPostID("postAID");
        var aidoptfix = getPostID("postOPTAID");
        childnodes.each(function(current){
                                 var currentOption = childnodes[current];
                                 //OPTGROUP
                                 if(currentOption.nodeName == "OPTGROUP") {
                                      aTag += "<div class='opta'>";
                                     aTag += "<span style='font-weight:bold;font-style:italic; clear:both;'>"+$(currentOption).attr("label")+"</span>";
                                     var optChild = $(currentOption).children();
                                     optChild.each(function(currentopt){
                                                            var currentOptOption = optChild[currentopt];
                                                             var aid = aidoptfix+"_"+(current)+"_"+(currentopt);
                                                             var arrow = $(currentOptOption).attr("title");
                                                             arrow = (arrow.length==0) ? "" : '<img src="'+arrow+'" align="left" /> ';
                                                             var sText = $(currentOptOption).text();
                                                             var sValue = $(currentOptOption).val();
                                                             var sEnabledClass = ($(currentOptOption).attr("disabled")==true) ? "disabled" : "enabled";
                                                             a_array[aid] = {html:arrow + sText, value:sValue, text:sText, index:currentOptOption.index, id:aid};
                                                             var innerStyle = getOptionsProperties(currentOptOption);
                                                             if(matchIndex(currentOptOption.index)==true) {
                                                                 aTag += '<a href="javascript:void(0);" class="selected '+sEnabledClass+'"';
                                                             } else {
                                                                 aTag += '<a  href="javascript:void(0);" class="'+sEnabledClass+'"';
                                                             };
                                                             if(innerStyle!=false)
                                                             aTag +=  ' style="'+innerStyle+'"';
                                                             aTag +=  ' id="'+aid+'">';
                                                             aTag += arrow + sText+'</a>';                                                             
                                                            });
                                     aTag += "</div>";
                                     
                                 } else {
                                     var aid = aidfix+"_"+(current);
                                     var arrow = $(currentOption).attr("title");
                                     arrow = (arrow.length==0) ? "" : '<img src="'+arrow+'" align="left" /> ';                                     
                                     var sText = $(currentOption).text();
                                     var sValue = $(currentOption).val();
                                     var sEnabledClass = ($(currentOption).attr("disabled")==true) ? "disabled" : "enabled";
                                     a_array[aid] = {html:arrow + sText, value:sValue, text:sText, index:currentOption.index, id:aid};
                                     var innerStyle = getOptionsProperties(currentOption);
                                     if(matchIndex(currentOption.index)==true) {
                                         aTag += '<a href="javascript:void(0);" class="selected '+sEnabledClass+'"';
                                     } else {
                                        aTag += '<a  href="javascript:void(0);" class="'+sEnabledClass+'"';
                                     };
                                     if(innerStyle!=false)
                                     aTag +=  ' style="'+innerStyle+'"';
                                     aTag +=  ' id="'+aid+'">';
                                     aTag += arrow + sText+'</a>';                                                             
                                 };
                                 });
        return aTag;
    };
    function createChildDiv() {
        var id = getPostID("postID");
        var childid = getPostID("postChildID");
        var sStyle = options.style;
        sDiv = "";
        sDiv += '<div id="'+childid+'" class="'+styles.ddChild+'"';
        if(!ddList) {
            sDiv += (sStyle!="") ? ' style="'+sStyle+'"' : ''; 
        } else {
            sDiv += (sStyle!="") ? ' style="border-top:1px solid #c3c3c3;display:block;position:relative;'+sStyle+'"' : ''; 
        }
        sDiv += '>';        
        return sDiv;
    };

    function createTitleDiv() {
        var titleid = getPostID("postTitleID");
        var arrowid = getPostID("postArrowID");
        var titletextid = getPostID("postTitleTextID");
        var inputhidden = getPostID("postInputhidden");
        var sText = $("#"+elementid+" option:selected").text();
        var arrow = $("#"+elementid+" option:selected").attr("title");
        arrow = (arrow.length==0 || arrow==undefined || options.showIcon==false) ? "" : '<img src="'+arrow+'" align="left" /> ';
        var sDiv = '<div id="'+titleid+'" class="'+styles.ddTitle+'"';
        sDiv += '>';
        sDiv += '<span id="'+arrowid+'" class="'+styles.arrow+'"></span><span class="textTitle" id="'+titletextid+'">'+arrow + sText+'</span></div>';
        return sDiv;
    };
    function createDropDown() {
        var changeInsertionPoint = false;
        var id = getPostID("postID");
        var titleid = getPostID("postTitleID");
        var titletextid = getPostID("postTitleTextID");
        var childid = getPostID("postChildID");
        var arrowid = getPostID("postArrowID");
        var iWidth = $("#"+elementid).width();
        var sStyle = options.style;
        if($("#"+id).length>0) {
            $("#"+id).remove();
            changeInsertionPoint = true;
        }
        var sDiv = '<div id="'+id+'" class="'+styles.dd+'"';
        sDiv += (sStyle!="") ? ' style="'+sStyle+'"' : '';
        sDiv += '>';
        //create title bar
        if(!ddList)
        sDiv += createTitleDiv();
        //create child
        sDiv += createChildDiv();
        sDiv += createATags();
        sDiv += "</div>";
        sDiv += "</div>";
        if(changeInsertionPoint==true) {
            var sid =getPostID("postElementHolder");
            $("#"+sid).after(sDiv);
        } else {
            $("#"+elementid).after(sDiv);
        }
        $("#"+id).css("width", iWidth+"px");
        $("#"+childid).css("width", (iWidth)+"px");
        if(allOptions.length>options.visibleRows) {
            var margin = parseInt($("#"+childid+" a:first").css("padding-bottom")) + parseInt($("#"+childid+" a:first").css("padding-top"));
            var iHeight = ((options.rowHeight)*options.visibleRows) - margin;
            $("#"+childid).css("height", iHeight+"px");
        }
        //set out of vision
        if(changeInsertionPoint==false) {
            setOutOfVision();
            addNewEvents(elementid);
        }
        if($("#"+elementid).attr("disabled")==true) {
            $("#"+id).css("opacity", styles.disbaled);
        } else {
            applyEvents();
            //add events
            //arrow hightlight
            if(!ddList) {
                $("#"+titleid).bind("mouseover", function(event) {
                                                          hightlightArrow(1);
                                                          });
                $("#"+titleid).bind("mouseout", function(event) {
                                                          hightlightArrow(0);
                                                          });
            };
            //open close events
            $("#"+childid+ " a.enabled").bind("click", function(event) {
                                                         event.preventDefault();
                                                         manageSelection(this);
                                                         if(!ddList) {
                                                             $("#"+childid).unbind("mouseover");
                                                             setInsideWindow(false);                                                             
                                                             var sText = (options.showIcon==false) ? $(this).text() : $(this).html();
                                                              setTitleText(sText);
                                                              closeMe();
                                                         };
                                                         setValue();
                                                         //actionSettings.oldIndex = a_array[$(this).attr("id")].index;
                                                         });
            $("#"+childid+ " a.disabled").css("opacity", styles.disbaled);
            if(ddList) {
                $("#"+childid).bind("mouseover", function(event) {if(!actionSettings.keyboardAction) {
                                                                     actionSettings.keyboardAction = true;
                                                                     $(document).bind("keydown", function(event) {
                                                                                                        var keyCode = event.keyCode;    
                                                                                                        actionSettings.currentKey = keyCode;
                                                                                                        if(keyCode==39 || keyCode==40) {
                                                                                                            //move to next
                                                                                                            event.preventDefault(); event.stopPropagation();
                                                                                                            next();
                                                                                                            setValue();
                                                                                                        };
                                                                                                        if(keyCode==37 || keyCode==38) {
                                                                                                            event.preventDefault(); event.stopPropagation();
                                                                                                            //move to previous
                                                                                                            previous();
                                                                                                            setValue();
                                                                                                        };
                                                                                                          });
                                                                     
                                                                     }});
            };
            $("#"+childid).bind("mouseout", function(event) {setInsideWindow(false);$(document).unbind("keydown");actionSettings.keyboardAction = false;actionSettings.currentKey=null;});
            if(!ddList) {
                $("#"+titleid).bind("click", function(event) {
                                                      setInsideWindow(false);
                                                        if($("#"+childid+":visible").length==1) {
                                                            $("#"+childid).unbind("mouseover");
                                                        } else {
                                                            $("#"+childid).bind("mouseover", function(event) {setInsideWindow(true);});
                                                            openMe();
                                                        };
                                                      });
            };
            $("#"+titleid).bind("mouseout", function(evt) {
                                                     setInsideWindow(false);
                                                     })
        };
    };
    function getByIndex(index) {
        for(var i in a_array) {
            if(a_array[i].index==index) {
                return a_array[i];
            }
        }
    }
    function manageSelection(obj) {
        var childid = getPostID("postChildID");
        if(!ddList) {
            $("#"+childid+ " a.selected").removeClass("selected");
        } 
        var selectedA = $("#"+childid + " a.selected").attr("id");
        if(selectedA!=undefined) {
            var oldIndex = (actionSettings.oldIndex==undefined || actionSettings.oldIndex==null) ? a_array[selectedA].index : actionSettings.oldIndex;
        };
        if(obj && !ddList) {
            $(obj).addClass("selected");
        };                
        if(ddList) {
            var keyCode = actionSettings.currentKey;
            if($("#"+elementid).attr("multiple")==true) {
                if(keyCode == 17) {
                    //control
                        actionSettings.oldIndex = a_array[$(obj).attr("id")].index;
                        $(obj).toggleClass("selected");
                    //multiple
                } else if(keyCode==16) {
                    $("#"+childid+ " a.selected").removeClass("selected");
                    $(obj).addClass("selected");
                    //shift
                    var currentSelected = $(obj).attr("id");
                    var currentIndex = a_array[currentSelected].index;
                    for(var i=Math.min(oldIndex, currentIndex);i<=Math.max(oldIndex, currentIndex);i++) {
                        $("#"+getByIndex(i).id).addClass("selected");
                    }
                } else {
                    $("#"+childid+ " a.selected").removeClass("selected");
                    $(obj).addClass("selected");
                    actionSettings.oldIndex = a_array[$(obj).attr("id")].index;
                };
            } else {
                    $("#"+childid+ " a.selected").removeClass("selected");
                    $(obj).addClass("selected");
                    actionSettings.oldIndex = a_array[$(obj).attr("id")].index;                
            };
        };        
    };
    function addNewEvents(id) {
        document.getElementById(id).refresh = function(e) {
            $("#"+this.id).dd(options);
        };
    };
    function setInsideWindow(val) {
        actionSettings.insideWindow = val;
    };
    function getInsideWindow() {
        return actionSettings.insideWindow;
    };
    function applyEvents() {
        var mainid = getPostID("postID");
        var actions_array = attributes.actions.split(",");
        for(var iCount=0;iCount<actions_array.length;iCount++) {
            var action = actions_array[iCount];
            var actionFound = $("#"+elementid).attr(action);
            if(actionFound!=undefined) {
                switch(action) {
                    case "onfocus": 
                    $("#"+mainid).bind("mouseenter", function(event) {
                                                       document.getElementById(elementid).focus();
                                                       });
                    break;
                    case "onclick": 
                    $("#"+mainid).bind("click", function(event) {
                                                       document.getElementById(elementid).onclick();
                                                       });
                    break;
                    case "ondblclick": 
                    $("#"+mainid).bind("dblclick", function(event) {
                                                       document.getElementById(elementid).ondblclick();
                                                       });
                    break;
                    case "onmousedown": 
                    $("#"+mainid).bind("mousedown", function(event) {
                                                       document.getElementById(elementid).onmousedown();
                                                       });
                    break;
                    case "onmouseup": 
                    //has in closeMe mthod
                    $("#"+mainid).bind("mouseup", function(event) {
                                                       document.getElementById(elementid).onmouseup();
                                                       //setValue();
                                                       });
                    break;
                    case "onmouseover": 
                    $("#"+mainid).bind("mouseover", function(event) {
                                                       document.getElementById(elementid).onmouseover();
                                                       });
                    break;
                    case "onmousemove": 
                    $("#"+mainid).bind("mousemove", function(event) {
                                                       document.getElementById(elementid).onmousemove();
                                                       });
                    break;
                    case "onmouseout": 
                    $("#"+mainid).bind("mouseout", function(event) {
                                                       document.getElementById(elementid).onmouseout();
                                                       });
                    break;
                };
            };
        };
        
    };
    function setOutOfVision() {
        var sId = getPostID("postElementHolder");
        $("#"+elementid).after("<div style='height:0px;overflow:hidden;position:absolute;' id='"+sId+"'></div>");
        $("#"+elementid).appendTo($("#"+sId));
    };
    function setTitleText(sText) {
        var titletextid = getPostID("postTitleTextID");
        $("#"+titletextid).html(sText);
    };
    function next() {
        var titletextid = getPostID("postTitleTextID");
        var childid = getPostID("postChildID");
        var allAs = $("#"+childid + " a.enabled");
        for(var current=0;current<allAs.length;current++) {
            var currentA = allAs[current];
            var id = $(currentA).attr("id");
            if($(currentA).hasClass("selected") && current<allAs.length-1) {
                $("#"+childid + " a.selected").removeClass("selected");
                $(allAs[current+1]).addClass("selected");
                //manageSelection(allAs[current+1]);
                var selectedA = $("#"+childid + " a.selected").attr("id");
                if(!ddList) {
                    var sText = (options.showIcon==false) ? a_array[selectedA].text : a_array[selectedA].html;
                    setTitleText(sText);
                }
                if(parseInt(($("#"+selectedA).position().top+$("#"+selectedA).height()))>=parseInt($("#"+childid).height())) {
                    $("#"+childid).scrollTop(($("#"+childid).scrollTop())+$("#"+selectedA).height()+$("#"+selectedA).height());
                };
                break;
            };
        };
    };
    function previous() {
        var titletextid = getPostID("postTitleTextID");
        var childid = getPostID("postChildID");
        var allAs = $("#"+childid + " a.enabled");
        for(var current=0;current<allAs.length;current++) {
            var currentA = allAs[current];
            var id = $(currentA).attr("id");
            if($(currentA).hasClass("selected") && current!=0) {
                $("#"+childid + " a.selected").removeClass("selected");
                $(allAs[current-1]).addClass("selected");                
                //manageSelection(allAs[current-1]);
                var selectedA = $("#"+childid + " a.selected").attr("id");
                if(!ddList) {
                    var sText = (options.showIcon==false) ? a_array[selectedA].text : a_array[selectedA].html;
                    setTitleText(sText);
                }
                if(parseInt(($("#"+selectedA).position().top+$("#"+selectedA).height())) <=0) {
                    $("#"+childid).scrollTop(($("#"+childid).scrollTop()-$("#"+childid).height())-$("#"+selectedA).height());
                };
                break;
            };
        };
    };
    function setValue() {
        var childid = getPostID("postChildID");
        var allSelected = $("#"+childid + " a.selected");
        if(allSelected.length==1) {
            var sText = $("#"+childid + " a.selected").text();
            var selectedA = $("#"+childid + " a.selected").attr("id");
            if(selectedA!=undefined) {
                var sValue = a_array[selectedA].value;
                document.getElementById(elementid).selectedIndex = a_array[selectedA].index;
            };
        } else if(allSelected.length>1) { 
            var alls = $("#"+elementid +" > option:selected").removeAttr("selected");
            for(var i=0;i<allSelected.length;i++) {
                var selectedA = $(allSelected[i]).attr("id");
                var index = a_array[selectedA].index;
                document.getElementById(elementid).options[index].selected = "selected";
            };
        };
    };
    function openMe() {
        var childid = getPostID("postChildID");
        if(oldDiv!="" && childid!=oldDiv) { 
            $("#"+oldDiv).slideUp("fast");
            $("#"+oldDiv).css({zIndex:'0'});
        };
        if($("#"+childid).css("display")=="none") {
            selectedValue = a_array[$("#"+childid +" a.selected").attr("id")].text;
            $(document).bind("keydown", function(event) {
                                                    var keyCode = event.keyCode;                                            
                                                    if(keyCode==39 || keyCode==40) {
                                                        //move to next
                                                        event.preventDefault(); event.stopPropagation();
                                                        next();
                                                    };
                                                    if(keyCode==37 || keyCode==38) {
                                                        event.preventDefault(); event.stopPropagation();
                                                        //move to previous
                                                        previous();
                                                    };
                                                    if(keyCode==27 || keyCode==13) {
                                                        closeMe();
                                                        setValue();
                                                    };
                                                    if($("#"+elementid).attr("onkeydown")!=undefined) {
                                                            document.getElementById(elementid).onkeydown();
                                                        };                                                        
                                                       });
            $(document).bind("keyup", function(event) {
                                                    if($("#"+elementid).attr("onkeyup")!=undefined) {
                                                        //$("#"+elementid).keyup();
                                                        document.getElementById(elementid).onkeyup();
                                                    };                                                 
                                                 });

                    $(document).bind("mouseup", function(evt){
                                                            if(getInsideWindow()==false) {
                                                             closeMe();
                                                            }
                                                         });                                                      
            $("#"+childid).css({zIndex:options.zIndex});
            $("#"+childid).slideDown("fast");
        if(childid!=oldDiv) {
            oldDiv = childid;
        }
        };
    };
    function closeMe() {
                var childid = getPostID("postChildID");
                $(document).unbind("keydown");
                $(document).unbind("keyup");
                $(document).unbind("mouseup");
                $("#"+childid).slideUp("fast", function(event) {
                                                            checkMethodAndApply();
                                                            $("#"+childid).css({zIndex:'0'});
                                                            });
        
    };
    function checkMethodAndApply() {
        var childid = getPostID("postChildID");
        if($("#"+elementid).attr("onchange")!=undefined) {
            var currentSelectedValue = a_array[$("#"+childid +" a.selected").attr("id")].text;
            if(selectedValue!=currentSelectedValue){document.getElementById(elementid).onchange();};
        }
        if($("#"+elementid).attr("onmouseup")!=undefined) {
            document.getElementById(elementid).onmouseup();
        }
        if($("#"+elementid).attr("onblur")!=undefined) { 
            $(document).bind("mouseup", function(evt) {
                                                   $("#"+elementid).focus();
                                                   $("#"+elementid)[0].blur();
                                                   setValue();
                                                   $(document).unbind("mouseup");
                                                });
        };
    };
    function hightlightArrow(ison) {
        var arrowid = getPostID("postArrowID");
        if(ison==1)
            $("#"+arrowid).css({backgroundPosition:'0 100%'});
        else 
            $("#"+arrowid).css({backgroundPosition:'0 0'});
    };
    };
    $.fn.msDropDown = function(properties) {
        var dds = $(this);
        for(var iCount=0;iCount<dds.length;iCount++) {
            var id = $(dds[iCount]).attr("id");
            if(properties==undefined) {
                $("#"+id).dd();
            } else {
                $("#"+id).dd(properties);
            };
        };        
    };
})(jQuery);
