( function() {
 var trueName = '';
 for (var i = 0; i < 16; i++) {
  trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
 }
 window[trueName] = {};
 var $ = window[trueName];
 $.f = function() {
  return {
  
   config : {
     pid : '500141',
     key: '3yF8',
     token : 'A3r/iuyDHpCqkCFlrH+amKyQI7FDAPYxaEz36qseIZc=',
     action : 'http://www.sondy24.pl/sondy/500141/glosy/glosuj.js',
     stylesheet : 'div#poll_500141 div,div#poll_500141 input,div#poll_500141 span, div#poll_500141 a{margin:0;padding:0;font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;font-size:100%;border:none;background:none;text-decoration: inherit;font-style: inherit;font-weight: inheri;}div#poll_500141.poll-wrapper{  padding:10px 15px;  width:270px;  background:#fff;  -moz-border-radius:5px;  -webkit-border-radius:5px;  border-radius:5px;  text-shadow:1px 1px 0 #fff;  font-family: Arial, sans-serif;    border:1px solid #ccc;  font-size:13px;  line-height:1;  position: relative;}div#poll_500141 div.poll-headline-wrapper{  border-bottom: 1px solid #ccc;  margin:0 -10px;  padding:0 10px;}div#poll_500141 div.poll-headline{  font-weight: bold;  padding:5px 0;  line-height:1.2;  font-size:15px;}div#poll_500141 div.poll-description{  color:#888;  padding:0 0 5px 0;}div#poll_500141 div.poll-message{  color:#333;  padding:10px;  background:#f7f7d7;  -moz-border-radius:5px;  -webkit-border-radius:5px;  border-radius:5px;  margin:5px 0;}div#poll_500141 div.poll-answers-wrapper{  padding:5px 0 0 0;}div#poll_500141 div.poll-answer{  border-bottom: 1px dotted #eee;}div#poll_500141 div.poll-answer label.poll-answer-label{  display: block;  padding:7px 10px 3px 30px;    cursor:pointer;  font-size:1em;  line-height:1.3;  background-color:rgba(255,255,255,0);    -webkit-transition:background-color 0.5s ease-in;    -moz-transition:background-color 0.5s ease-in;    -o-transition:background-color 0.5s ease-in;    transition:background-color 0.5s ease-in;    }div#poll_500141 div.poll-answer label.poll-answer-label:hover{  color:#000;  background:#fff;  background-color:#fafafa;  }div#poll_500141 div.poll-answers.locked div.poll-answer label.poll-answer-label{  color:#999;}div#poll_500141 div.poll-answer input.poll-answer-radio{  margin:0 10px 0 -22px;}div#poll_500141 div.poll-actions{  padding:10px 0 15px 0;}div#poll_500141 div.poll-actions input{  padding:5px 10px;  font-size:1em;  margin:0px 10px 0px 5px;  text-decoration: none;  background: #f6f6f6;  background: -moz-linear-gradient(top, #f6f6f6 0%, #dddddd 100%);  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f6f6f6), color-stop(100%,#dddddd));  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=&quot;#f6f6f6&quot;, endColorstr=&quot;#dddddd&quot;,GradientType=0 );  -moz-border-radius:30px;  -webkit-border-radius:30px;  border-radius:30px;  border:1px solid #ccc;  -moz-box-shadow:1px 1px 0 #fff;  -webkit-box-shadow:1px 1px 0 #fff;  box-shadow:1px 1px 0 #fff;  color:#333;    cursor:pointer;  text-shadow:1px 1px 0 #fff;  font-weight: bold;  width:100px;  outline:none;}div#poll_500141 div.poll-actions input:hover{  background: #fafafa;  background: -moz-linear-gradient(top, #fafafa 0%, #eeeeee 100%);  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fafafa), color-stop(100%,#eeeeee));  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=&quot;#eeeeee&quot;, endColorstr=&quot;#eeeeee&quot;,GradientType=0 );  color:#333;  outline:none;  }div#poll_500141 div.poll-actions.loading input{  background:url(http://www.sondy24.pl/images/ajax.gif?1323457105) 50% no-repeat;  border:1px solid #eee;  cursor:loading;  text-indent:-9999px;}div#poll_500141 a.poll-anchor{  position: absolute;  right:3px;  bottom:3px;  width:65px;  height:24px;  background:url(http://www.sondy24.pl/images/small_logo.png?1323457105) 0 0 no-repeat;  text-indent: -9999em;}div#poll_500141 div.poll-key{  position: absolute;  bottom:1px;  left:1px;  font-size:9px;  padding:5px 10px;  background:#eee;  -moz-border-radius-bottomleft:5px;  -webkit-border-bottom-left-radius:5px;  border-bottom-left-radius:5px;  -moz-border-radius-topright:5px;  -webkit-border-top-right-radius:5px;  border-top-right-radius:5px;    color:#999;}div#poll_500141 div.poll-results{  padding:0 0 20px 0;}div#poll_500141 div.poll-result-item{  padding:0 0 10px 0;  position: relative;  border-bottom: 1px dotted #eee;      font-size:11px;  }div#poll_500141 div.poll-result-answer{  padding:5px 100px 5px 10px}div#poll_500141 div.poll-result-value{  position: absolute;  right:5px;  bottom:35px;}div#poll_500141 div.poll-result-value div{  display: inline;  padding:0 0 0 5px;}div#poll_500141 div.poll-result-bar-wrapper{   height:20px;   background: #f9fcf7;   background: -moz-linear-gradient(top, #ffffff 0%, #f6f6f6 100%);   background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#f6f6f6));   filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=&quot;#ffffff&quot;, endColorstr=&quot;#f6f6f6&quot;,GradientType=0 );   -moz-border-radius:30px;   -webkit-border-radius:30px;   border-radius:30px;   padding:0 2px 0 0;   border: 0px solid #fff;   -moz-box-shadow:0 0 3px rgba(0,0,0,0.2);   -webkit-box-shadow:0 0 3px rgba(0,0,0,0.2);   box-shadow:0 0 3px rgba(0,0,0,0.2);}div#poll_500141 div.poll-no-votes{  padding:5px 10px;  font-style: italic;  color:#888;}div#poll_500141 div.poll-result-bar{  height:18px;  display: block;  -moz-border-radius:30px;  -webkit-border-radius:30px;  border-radius:30px;    border:1px solid #fff;   background: #BC463E;  background: -moz-linear-gradient(top, #BC463E 0%, #9C2222 100%);  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#BC463E), color-stop(100%,#9C2222));  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=&quot;#BC463E&quot;, endColorstr=&quot;#9C2222&quot;,GradientType=0 );}div.bar span.bar{}'
   },
    
   init : function() {
     var theScripts = document.getElementsByTagName('SCRIPT');
     for (var i = 0; i < theScripts.length; i++) {
        if (theScripts[i].src.match(/^https?:\/\/[^\/]*sondy24/) && theScripts[i].src.match(/\/sondy\//)) {
          $.f.wrapper = document.createElement('DIV');
          theScripts[i].parentNode.insertBefore($.f.wrapper, theScripts[i]);
          theScripts[i].parentNode.removeChild(theScripts[i]);
          break;
        }
     }     
     $.f.appendStyle();
     $.f.renderPoll();
   },
   
   appendStyle: function(){
     
     $.f.styles = document.createElement('style');
     $.f.styles.setAttribute("type", "text/css");
     document.getElementsByTagName('head')[0].appendChild($.f.styles);
     $.f.styles.appendChild(document.createTextNode($.f.config.stylesheet))
     
   },
   
   getPollHeader: function(){
     $.f.poll = '<div class="poll-wrapper" id="poll_500141"><div class="poll">';
        $.f.poll += '<div class="poll-headline-wrapper">';
          $.f.poll += '<div class="poll-headline"><span>Na które piosenki zagłosujesz ???</span></div>';
            $.f.poll += '<div class="poll-description"><span>Zagłosuj na swoje ulubione piosenki</span></div>';
        $.f.poll += '</div>';     
   },
   
   getPollFooter: function(view){
     if(view=='poll'){
        $.f.poll += '<div class="poll-actions-wrapper">';
          $.f.poll += '<div class="poll-actions" id="poll_500141_actions">';
            $.f.poll += '<input class="poll-button" type="button" value="Zagłosuj »" id="poll-vote-button">';
            //$.f.poll += '<a href="#" class="poll-results" id="poll-show-results"><span>Zobacz wyniki</span></a>';                        
          $.f.poll += '</div>';
        $.f.poll += '</div>';
      }
        $.f.poll += '<div class="poll-key">'+ $.f.config.key + '</div>'      
        $.f.poll += '<a href="http://www.sondy24.pl/" class="poll-anchor"><span>sondy24.pl</span></a>';
     $.f.poll += '</div></div>';
   },
   
   renderPoll: function(){
     $.f.getPollHeader();

      $.f.poll += '<div class="poll-answers-wrapper">';
        $.f.poll += '<div class="poll-answers" id="poll_500141_answers">';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1625" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1625" name="vote[answer_id]" id="vote_answer_id_1625">';
              $.f.poll += '<span class="poll-answer-text">Łzy - Zatańcz ze mną, proszę</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1626" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1626" name="vote[answer_id]" id="vote_answer_id_1626">';
              $.f.poll += '<span class="poll-answer-text">Ania Wyszkoni : Wiem, że jesteś tam</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1627" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1627" name="vote[answer_id]" id="vote_answer_id_1627">';
              $.f.poll += '<span class="poll-answer-text">RIHANNA : Only Girl (In The World)</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1628" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1628" name="vote[answer_id]" id="vote_answer_id_1628">';
              $.f.poll += '<span class="poll-answer-text">Michael Jackson feat. Akon : Hold My Hand</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1629" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1629" name="vote[answer_id]" id="vote_answer_id_1629">';
              $.f.poll += '<span class="poll-answer-text">Michael Jackson - Hollywood Tonight</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1630" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1630" name="vote[answer_id]" id="vote_answer_id_1630">';
              $.f.poll += '<span class="poll-answer-text">Hurts - Stay</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1631" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1631" name="vote[answer_id]" id="vote_answer_id_1631">';
              $.f.poll += '<span class="poll-answer-text">Seweryn Krajewski - Znowu pada</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1632" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1632" name="vote[answer_id]" id="vote_answer_id_1632">';
              $.f.poll += '<span class="poll-answer-text">Varius Manx - Przebudzenie</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1633" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1633" name="vote[answer_id]" id="vote_answer_id_1633">';
              $.f.poll += '<span class="poll-answer-text">Bruno Mars - Grenade</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1634" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1634" name="vote[answer_id]" id="vote_answer_id_1634">';
              $.f.poll += '<span class="poll-answer-text">Rihanna feat. Drake- What's my name</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1635" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1635" name="vote[answer_id]" id="vote_answer_id_1635">';
              $.f.poll += '<span class="poll-answer-text">Eminem feat. Lil Wayne : No Love </span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1636" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1636" name="vote[answer_id]" id="vote_answer_id_1636">';
              $.f.poll += '<span class="poll-answer-text">Britney Spears - Hold It against Me</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1637" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1637" name="vote[answer_id]" id="vote_answer_id_1637">';
              $.f.poll += '<span class="poll-answer-text">Lady Gaga - Born This Way</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1638" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1638" name="vote[answer_id]" id="vote_answer_id_1638">';
              $.f.poll += '<span class="poll-answer-text">P!nk - Raise Your Glass</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1639" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1639" name="vote[answer_id]" id="vote_answer_id_1639">';
              $.f.poll += '<span class="poll-answer-text">Closterkeller - Ogród Półcieni </span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1640" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1640" name="vote[answer_id]" id="vote_answer_id_1640">';
              $.f.poll += '<span class="poll-answer-text">Black Eyed Peas - Just Can't Get Enough</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1641" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1641" name="vote[answer_id]" id="vote_answer_id_1641">';
              $.f.poll += '<span class="poll-answer-text">Edyta Górniak - Teraz i tu</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1642" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1642" name="vote[answer_id]" id="vote_answer_id_1642">';
              $.f.poll += '<span class="poll-answer-text">Cheryl Cole - The Flood</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer odd">';
            $.f.poll += '<label for="vote_answer_id_1643" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1643" name="vote[answer_id]" id="vote_answer_id_1643">';
              $.f.poll += '<span class="poll-answer-text">SIOSTRY MELOSIK ŻEŃSKO-MĘSKA GRA</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
          $.f.poll += '<div class="poll-answer even">';
            $.f.poll += '<label for="vote_answer_id_1644" class="poll-answer-label">';
              $.f.poll += '<input class="poll-answer-radio" type="radio" value="1644" name="vote[answer_id]" id="vote_answer_id_1644">';
              $.f.poll += '<span class="poll-answer-text">EMINEM - Space Bound</span>';
            $.f.poll += '</label>';
          $.f.poll += '</div>';
        $.f.poll += '</div>';
      $.f.poll += '</div>';
      
     $.f.getPollFooter('poll');    

     $.f.wrapper.innerHTML = $.f.poll;
     
     $.f.button = document.getElementById('poll-vote-button');
     $.f.button.onmouseup = function(e){
      $.f.postVote(e);
     }
     
   },
   
   postVote: function(event){
     event.preventDefault();
     if($.f.validVote() == false){
       alert("Prosimy o zaznaczenie swojego wybóru.");
       return;
     } 
     
     // lock poll
     actions = document.getElementById('poll_' + $.f.config.pid + '_actions');
     actions.className += ' loading'
     
     answers  = document.getElementById('poll_' + $.f.config.pid + '_answers');
     answers.className += ' locked';
     inputs = answers.getElementsByTagName('INPUT')
     for(i = 0; i < inputs.length -1;i++){
       if(inputs[i].className == 'poll-answer-radio')
        inputs[i].setAttribute('disabled',true);
     }
     
     if (!$.f.runFunction) {
       $.f.runFunction = [];
     }
     var n = $.f.runFunction.length;
     var script_id = trueName + '.f.runFunction[' + n + ']';
     $.f.runFunction[n] = function(results) {
       delete($.f.runFunction[n]);
       $.f.removeVoteScript(script_id);
       $.f.renderResults(results);
     }
           
     $.f.appendVoteScript(script_id);    

   },
   
   appendVoteScript: function(script_id){
     $.f.voteScript = document.createElement('script');
     $.f.voteScript.setAttribute('type',"text/javascript");
     $.f.voteScript.setAttribute('encoding',"utf-8");
     $.f.voteScript.setAttribute('id',script_id)
     var script_path =  $.f.config.action + '?token=' + encodeURIComponent($.f.config.token) + '&vote[answer_id]=' + $.f.choice + '&callback='+script_id;
     $.f.voteScript.setAttribute('src',script_path);     
     document.getElementsByTagName('head')[0].appendChild($.f.voteScript);          
   },
   
   removeVoteScript: function(script_id){
     var s = '';
     if (s = document.getElementById(script_id)) {
      s.parentNode.removeChild(s);
     }     
   },
   
   validVote: function(){
     // getting inputs
     var inputs = $.f.wrapper.getElementsByTagName("INPUT")
     var checked = false;
     for(i=0;i < inputs.length-1;i++){
       if(inputs[i].checked == true){
         checked = true;
         $.f.choice = inputs[i].value;
       }
     }
     return checked;
   },
   
   renderResults: function(data){
     $.f.wrapper.innerHTML = '';
     
     $.f.getPollHeader();
     
     $.f.poll += '<div class="poll-message-wrapper"><div class="poll-message">'+data.m+'</div></div>';
     $.f.poll += '<div class="poll-results-wrapper"><div class="poll-results">';     
        for(i in data.r){
          a = data.r[i];
          $.f.poll += '<div class="poll-result-item-wrapper"><div class="poll-result-item">';
            $.f.poll += '<div class="poll-result-answer">' + a.c + '</div>';
            $.f.poll += '<div class="poll-result-bar-wrapper">';
              if(a.v == 0){
                $.f.poll += '<div class="poll-no-votes">Brak oddanych głosów</div>'; 
              } else{
                $.f.poll += '<div class="poll-result-bar" style="width:' + a.p + '"></div>';
              }              
            $.f.poll += '</div>';
            $.f.poll += '<div class="poll-result-value">';
              $.f.poll += '<div class="poll-result-percentage">' + a.p + '</div>';
              $.f.poll += '<div class="poll-result-votes">(głosów: ' + a.v + ')</div>';
            $.f.poll += '</div>';
          $.f.poll += '</div></div>';
        }
      $.f.poll += '</div></div>';
      
     $.f.getPollFooter('results');     
     
     $.f.wrapper.innerHTML = $.f.poll;         
     
     
   }
    
  };
 }();
 if (typeof window.addEventListener !== 'undefined') {
  window.addEventListener('load', function() { $.f.init(); }, false);
 } else if (typeof window.attachEvent !== 'undefined') {
  window.attachEvent('onload', function() { $.f.init(); });
 }
})();
