combo = function () {
    var _this = this;
    //console.log(2)
   // $(document).ready (function () {console.log(1);_this.initialize();}) 
    
    _this.initialize();
    
}
combo.prototype.getTags = function (tagname, parent) {  
    //var element = parent ? parent : document;
    
    var elements =  (parent.getElementsByTagName("my:" + tagname).length>0) 
		? parent.getElementsByTagName("my:" + tagname) 
		: parent.getElementsByTagName(tagname) ;
    return elements;
}

combo.prototype.show = function (_combo,_tags) {
    var _this = this;
    
    for (var t=1;t<_tags.length;t++) {
        
        var id = _tags[t].getAttribute("id")
        if (id !=  _combo.parent().attr("id")) {
            $(_tags[t]).find("ul").slideUp();
        }
    }
    _combo.parent().find("ul").slideToggle()
}

combo.prototype.initialize = function () {
    
    var _this = this;
     
        
        var tags = _this.getTags("combo", document);
        
        for (var t=0; t<tags.length; t++) {
            var _tag = tags[t];
            
            
            
            var image = _this.getTags("combo_image",_tag)[0];
           
            
            $(image).click(function () {
                _this.show($(this),tags) 
            })  
            
            
            var _data = _this.getTags("data", _tag)[0];
            
            var _data_value = ($.jStorage.get($(_data).attr("id")) != undefined) ? $.jStorage.get($(_data).attr("id")) : "Not specified";
            
            $(_data).html(_data_value);
            
           
            $(_data).click (function () {
               _this.show($(this),tags)
            })
            
            $(_tag).find("li").each(function (){
                var _main = tags[t];
                
                //if ($(this).attr("selected") == "selected") {
                 //   var data = _this.getTags("data", _main)[0];
                //    $(data).html($(this).html())
                //    $.jStorage.set($(data).attr("id"), $(this).html())
                //    console.log( $.jStorage.get($(data).attr("id")))
               // }
                
                $(this).click(function () {
        
                    var data = _this.getTags("data", _main)[0];
                    $(data).html($(this).html())
                    $.jStorage.set($(data).attr("id"), $(this).html())
                    
                    
                    $(this).parent().slideToggle()
                })
                
                
                $(this).mouseenter(function () {
                    if(! $(this).parent().is(':animated'))
                    $(this).addClass("over");
                })
                
                $(this).mouseleave(function () {
                    $(this).removeClass("over");
                })

            })
        }
}

