                System.Extend.PollBrands = function(argsObj){
                    this.selected = '';
                    this.percentages = {};
                    this.locked = false;
                    this.langCode = window.lang_code;
                
                         this.args = {
                            percentageBarWidth: 200
                         }
                         
                    for(i in argsObj){this.args[i] = argsObj[i];}
                    
                    this.checkSelected = function(id){
                        selector = "#" + id;
                        radioSelector = "#poll-brands-" + id;
                        if(selector != this.selected){
                            jQuery(radioSelector).attr("checked", "checked");
                            jQuery(this.selected).removeClass("poll-selected");
                            jQuery(selector).addClass("poll-selected");
                            this.selected = selector;
                        }else{
                            jQuery(selector).removeClass("poll-selected");   
                            this.selected = '';
                        }
                    }
                    
                    this.init = function(){
                        this.voteEvent();
                        this.resultsEvent(); 
                        this.brandsSelectEvents();
                    }
                    
                    this.lock = function(){
                        //jQuery("#poll-controls-buttons").fadeOut(100);
                        this.controlButtonsHide();
                        this.locked = true;
                    }
                    
                    this.unlock = function(){
                        //jQuery("#poll-controls-buttons").fadeIn(100);    
                        this.controlButtonsShow();
                        this.locked = false;
                    }
                    
                    this.controlButtonsHide = function(){
                        jQuery("#poll-controls-buttons").css({opacity:0});    
                    }
                    
                    this.controlButtonsShow = function(){
                        jQuery("#poll-controls-buttons").css({opacity:1});                        
                    }
                    
                    this.controlsShow = function(){
                        jQuery("#poll-controls").fadeIn(300);                    
                    }
                    
                    this.controlsReturn = function(){
                        jQuery("#poll-controls").html(jQuery("#poll-controls-temp").clone(true));                    
                    }
                    
                    this.controlsReturnShow = function(){
                        var self = this;
                        jQuery("#poll-controls div").fadeIn(300,function(){
                            self.unlock();                        
                        }); 
                    }
                    
                    this.barAnimate = function(selector,widthMax,percent){
                        var bar = jQuery(selector + " div");
                        //alert(bar.css("width"));
                        var width  = (widthMax * percent) / 100;
                        bar.animate({
                            width: width
                        },500);                        
                    }
                    
                    this.controlsReturnFill = function(data){
                        jQuery("#poll-controls").html(data);                    
                    }
                    
                    this.displayMsg = function(msg){
                        var self = this;
                        jQuery("#poll-msg").html(msg);
                        jQuery("#poll-msg").fadeOut(1500,function(){
                            jQuery(this).html("&nbsp;");
                            jQuery(this).fadeIn(10);
                        });
                    }
                    
                    this.resultsShow = function(data){
                                var self = this;
                                var out = '<div style="color:#ff0000;margin-top:30px;font-size:12px;font-weight:bold;font-family:arial;">';
                                out += "<table cellspacing='5' cellpadding='5'>";
                                var total = data[System.objSize(data)-1]['count'];
                                for(i in data){
                                    var percentage = 0;
                                    if(data[i]['count'] != 0){
                                        percentage = Math.round((data[i]['count'] * 100) / total);
                                    }
                                    Poll.percentages[data[i]['name']] = percentage;
                                    if(data[i]['name'] != 'total' && i != "indexOf"){
                                        out += "<tr>" + "<td style=''>" + self.resolveName(data[i]['name']) + "</td>" + "<td>" + "<div style='width:"+self.args.percentageBarWidth+"px;height:20px;border:1px solid #666;float:left;' id='pollPercentageBar" + data[i]['name']  + "'><div style='width:0px;background:#000;height:20px;'></div></div>"  + "</td>" + "<td>" + "<div id='pollPercentage" + data[i]['name']  + "'>" + percentage + "&#37;</div>" + "</td></tr>";
                                    }
                                }
                                //var window = new System.UI.Window(out,{modal:true,width:400,showClose:true,isResizable:false,title:"System message:"});
                                jQuery("body").append('<div style="display:none" id="poll-controls-temp"></div>')
                                jQuery("#poll-controls-temp").html(jQuery("#poll-controls").clone(true));
                                var backBtnTitle = "Povratak";
                                if(self.langCode == "en"){backBtnTitle = "Back";}
                                var pollResultsData = out += '<tr><td colspan="3" style="padding-top:20px;"><button style="font-weight:bold;float:right" id="btnContentBack" onclick="javascript:Poll.controlsReturn();Poll.controlsReturnShow();">'+backBtnTitle+'</button></td></tr></table></div>';
                                jQuery("#poll-controls").fadeOut(10,function(){
                                    self.controlsReturnFill(pollResultsData);
                                    self.controlsShow();
                                    self.resultsAnimate();
                                });                    
                    }
                    
                    this.resultsAnimate = function(){
                        var self = this;
                        //alert(jQuery("#pollPercentageBark1x").html());
                        self.barAnimate("#pollPercentageBark1x",self.args.percentageBarWidth,this.percentages['k1x']);
                        self.barAnimate("#pollPercentageBaradidas",self.args.percentageBarWidth,this.percentages['adidas']);     
                        self.barAnimate("#pollPercentageBarben-sherman",self.args.percentageBarWidth,this.percentages['ben-sherman']);     
                        self.barAnimate("#pollPercentageBarpointer",self.args.percentageBarWidth,this.percentages['pointer']);  
                        self.barAnimate("#pollPercentageBarck",self.args.percentageBarWidth,this.percentages['ck']);  
                        self.barAnimate("#pollPercentageBarhummel",self.args.percentageBarWidth,this.percentages['hummel']);  
                        self.barAnimate("#pollPercentageBarchaps",self.args.percentageBarWidth,this.percentages['chaps']);  
                        self.barAnimate("#pollPercentageBarfred-perry",self.args.percentageBarWidth,this.percentages['fred-perry']);                     
                    }
                    
                    this.voteEventAction = function(){
                            var self = this;
                            var selectedBrand = jQuery("input[name='poll-brands']:checked").val();
                            //alert(selectedBrand);
                            if(typeof(selectedBrand) != "undefined"){
                                if(!self.locked){
                                    self.lock();
                                    jQuery.ajax({
                                        type : "POST",
                                        url : "controllers/controller.php",
                                        data : "action=PollBrandsUpdate&selectedBrand="+selectedBrand,
                                        success: function(data){
                                            if(trim(data) == "success"){
                                                self.resultsEventAction();
                                            }else{
                                                self.displayMsg("Error!");
                                            }
                                        },
                                        error: function(){
                                            self.displayMsg("Request Error!");                                            
                                        }
                                    });
                                }
                            }                    
                    }
                    
                    this.voteEvent = function(){
                        var self = this;
                        jQuery("#btnVote").click(function(){
                            self.voteEventAction();
                        });                        
                    }
                    
                    this.resultsEventAction = function(){
                                var self = this;
                                jQuery.ajax({
                                    type : "POST",
                                    url : "controllers/controller.php",
                                    data : "action=PollBrandsResults",
                                    dataType: 'json',
                                    success: function(data){
                                        //alert(data);
                                        //alert(typeof(data));
                                        self.resultsShow(data);
                                    },
                                    error: function(){
                                        self.displayMsg("Request Error!");                                        
                                    }
                                });                          
                    }
                    
                    this.resultsEvent = function(){
                        var self = this;
                        jQuery("#btnResults").click(function(){
                            self.lock();
                            self.resultsEventAction();
                        });                        
                    }
                    
                    this.resolveName = function(name){
                        displayName = '';
                        switch(name){
                        
                            case "k1x":
                            displayName = "K1X";
                            break;
                            
                            case "adidas":
                            displayName = "Adidas";
                            break;    

                            case "ben-sherman":
                            displayName = "Ben Sherman";
                            break;                    

                            case "pointer":
                            displayName = "Pointer";
                            break;  

                            case "ck":
                            displayName = "Calvin Klein Jeans";
                            break;        

                            case "hummel":
                            displayName = "Hummel";
                            break; 

                            case "chaps":
                            displayName = "Chaps";
                            break;     

                            case "fred-perry":
                            displayName = "Fred Perry";
                            break;                                 
                        }
                        
                        return displayName;
                    }
                    
                    this.brandsSelectEvents = function(){
                        var self = this;
                        jQuery("#fp-logos-k1x").click(function(){
                            self.checkSelected("fp-logos-k1x");
                        });
                        jQuery("#fp-logos-sean-john").click(function(){
                            self.checkSelected("fp-logos-sean-john");
                        });
                        jQuery("#fp-logos-adidas").click(function(){
                            self.checkSelected("fp-logos-adidas");
                        });  
                        jQuery("#fp-logos-ben-sherman").click(function(){
                            self.checkSelected("fp-logos-ben-sherman");
                        });   
                        jQuery("#fp-logos-pointer").click(function(){
                            self.checkSelected("fp-logos-pointer");
                        });   
                        jQuery("#fp-logos-ck").click(function(){
                            self.checkSelected("fp-logos-ck");
                        }); 
                        jQuery("#fp-logos-hummel").click(function(){
                            self.checkSelected("fp-logos-hummel");
                        }); 
                        jQuery("#fp-logos-converse").click(function(){
                            self.checkSelected("fp-logos-converse");
                        }); 
                        jQuery("#fp-logos-chaps").click(function(){
                            self.checkSelected("fp-logos-chaps");
                        }); 
                        jQuery("#fp-logos-fred-perry").click(function(){
                            self.checkSelected("fp-logos-fred-perry");
                        });                    
                    }
                    
                    this.init();
                    
                }
