/*
 * Dracon AJAX Shout 0.9 Effects
 * http://www.dracon.biz/
 *
 * Copyright (c) 2009 dracon.biz
 * Licensed under the Dracon license.
 * http://www.dracon.biz/license.php
 */

/* Default Functions */
function gE(Id) {
  return document.getElementById(Id);
}

function OkCancel() {
  Msg = (arguments[0]) ? arguments[0] : 'Are you sure?';
  this.blur();
  if (confirm(Msg)) return true;
  return false;
}

function compareNumbers(a,b) {  // sort numerical array - descending
   return b-a;
}

function strReplace(source,input,output) {
  var temp = source.split(input);
  return temp.join(output);
}

/* jQuery onReady */
$(document).ready(function () {

  /* jQuery Plugin - Delay */
  jQuery.fn.delay = function(time,fx) {
    this.each(function() {
      setTimeout(fx,time);
    });
    return this;
  };

  /* jQuery Plugin - Tooltip */
  jQuery.fn.tooltip = function(top,left) {
    this.hover(function(e) {     
      this.xtitle = this.title; this.title = '';
      $(this).parent().append('<div id="tooltip">'+ this.xtitle +'</div>');
      //$('#tooltip').css({opacity:0.8, display:"none"}).fadeIn(400);
      $('#tooltip').css("top",(e.pageY + top) + "px").css("left",(e.pageX + left) + "px");    
    }, function(){
      this.title = this.xtitle;
      $("#tooltip").remove();
    });  
    this.mousemove(function(e){
      $("#tooltip")
        .css("top",(e.pageY + top) + "px")
        .css("left",(e.pageX + left) + "px");
    });    
  };
  
  /* jQuery Plugin - Key Press */
  jQuery.fn.key = function(key,func) {
    $(this).keypress(function(event) {
      if (event.keyCode == key) {
        eval(func);
      }
    });
  };  

  /* Button blur */
  $('a, button').live('click', function() {
    this.blur();
  });
  
  /* Shout Options */ 
  $('.dracon_shout_options_btn').live('click', function() {
    $(this).parent().addClass('dracon_shout_options_on');
    $(this).parent().children('div').not(':first').fadeIn(300, function(){
      $(this).children('ul').slideDown(500);  
    });
  })
  $('.dracon_shout_options_close').live('click', function() {
    var shoutOptions = $(this).parent().parent();
    shoutOptions.children('ul').toggle(500, function(){
      shoutOptions.parent().removeClass('dracon_shout_options_on');
      shoutOptions.fadeOut(300);  
    });
  })
  
  /* Reply Window */
  $('.dracon_shout_reply > span').live('click', function() {
    $('.dracon_shout_add_comment').clone().appendTo($(this).parent());
    $(this).parent().children('.dracon_shout_add_comment').fadeIn(300, function() {
      if (window.scrollbars.visible === true) window.scrollBy(300,0);
    });
    // set subject as a reply
    $(this).parent().find('input').eq(0).val('Re: ' + $(this).parent().prev().attr('title'));
    // set forumId
    $(this).parent().find('input').eq(5).val($(this).parent().prev().parent().parent().attr('id').substring(13));
  });
  $('.dracon_shout_cancel_btn').live('click', function() {
    $(this).parent().fadeOut(300, function() { $(this).remove(); });
  });
  $('.dracon_shout_reset_btn').live('click', function() {
    $(this).parent().find('textarea').eq(0).val('Message');
    $(this).parent().find('input').eq(0).val('Subject');
    $(this).parent().find('input').eq(1).val('Icon');
    $(this).parent().find('input').eq(2).val('Name');
    $(this).parent().find('input').eq(3).val('Email (will not be published)');
    $(this).parent().find('input').eq(4).val('Website (optional)');
  });
  $('.dracon_shout_send_btn').live('click', function() {
    var commentBox = $(this).parent();
    var name = $(this).parent().find('input').eq(2).val();
    var subject = $(this).parent().find('input').eq(0).val();
    var message = $(this).parent().find('textarea').eq(0).val();
    var email = $(this).parent().find('input').eq(3).val();
    var website = $(this).parent().find('input').eq(4).val();
    var forumId = $(this).parent().find('input').eq(5).val();
    if (!message || message == 'Message' || message == 'Please enter a message!' ) {
      $(this).parent().find('textarea').eq(0).val('Please enter a message!').select().focus();
      return false;
    }
    if (!name || name == 'Name' || name == 'Admin' || name == 'Administrator' || name == 'Name please!' ) {
      $(this).parent().find('input').eq(2).val('Name please!').select().focus();
      return false;
    }
    // display loader and hide send button
    $('.dracon_shout_send_load').show();
    $(this).html('Sending').css('visibility','hidden');
    $('#dracon_shout_loading').load(webRoot+'?ajax=add_comment', { shoutForumId:forumId, subject:subject, name:name, message:message, email:email, website:website }, function(jsCode) {
      alert(jsCode)
      $('.dracon_shout_send_load').hide();
      commentBox.fadeOut(300, function() { $(this).remove(); });
      if (jsCode == 'ok') {
        // first a flash: new comment added
        // display the new comment
      }
    });
  });
  
  /* Smileys */
  $('.dracon_shout_smileys > img').live('click', function() {
    var title = ':' + $(this).attr('title') + ':';
    var textObj = $(this).parent().prev().find('textarea').eq(0);
    textObj.val(textObj.val() + ' ' + title);
  });
  
  /* Voting */
  $('.dracon_shout_vote_add').live('click', function() {
    var voteInf = $(this).next().next();
    var shoutId = $(this).parent().parent().parent().attr('id').substring(16);
    voteInf.fadeOut(200, function() {
      $('#dracon_shout_loading').load(webRoot+'?ajax=add_vote', { shoutId:shoutId, status:'1' }, function(jsCode) {
        var newVote = parseInt(voteInf.html()) + 1;
        if (newVote > 0) { newVote = '+' + newVote; voteInf.css('color','green'); }
        if (newVote == 0) voteInf.css('color','gray');
        voteInf.html(newVote);
        voteInf.fadeIn(200);
      });
    });
  });
  $('.dracon_shout_vote_del').live('click', function() {
    var voteInf = $(this).next();
    var shoutId = $(this).parent().parent().parent().attr('id').substring(16);
    voteInf.fadeOut(200, function() {
      $('#dracon_shout_loading').load(webRoot+'?ajax=del_vote', { shoutId:shoutId, status:'-1' }, function(jsCode) {
        var newVote = parseInt(voteInf.html()) - 1;
        if (newVote > 0) newVote = '+' + newVote;
        if (newVote == 0) voteInf.css('color','gray');
        if (newVote < 0) voteInf.css('color','red');
        voteInf.html(newVote);
        voteInf.fadeIn(200);
      });
    });
  });
  
  /* Paging */
  $('.dracon_shout_paging > a').live('click', function() {
    if (!$(this).attr('class')) {
      var shoutForumId = $(this).parent().parent().attr('id').substring(13);
      var page = $(this).html();
      // next page
      if (page == 'Next') { page = parseInt($(this).siblings('.dracon_shout_paging_current').html())+1; }
      // prev page
      if (page == 'Previous') { page = parseInt($(this).siblings('.dracon_shout_paging_current').html())-1; }
      var showMin = $('.dracon_shout_showmin').html();
      var shoutsNum = $('.dracon_shout_total').html();
      var pageLimit = 10;  // optional
      // replace paging
      $('.dracon_shout_paging').animate({ opacity: 0.1 }, 500, function() {
        $('#dracon_shout_loading').load(webRoot+'?ajax=paging', { shoutForumId:shoutForumId, pageLimit:pageLimit, page:page }, function(jsCode) {
          $('.dracon_shout_paging').html(jsCode).animate({ opacity: 1 }, 300);
        });
      });
      // load new page
      $('.dracon_shout_display').slideUp(1000, function() {
        $('#dracon_shout_loading').load(webRoot+'?ajax=turn_page', { shoutForumId:shoutForumId, pageLimit:pageLimit, page:page }, function(jsCode) {
          var newMin = page * pageLimit - pageLimit + 1;
          // change min
          $('.dracon_shout_showmin').fadeOut(300, function() {
            $(this).html(newMin);
            $(this).fadeIn();
            if (shoutsNum > newMin+pageLimit) var newMax = newMin+pageLimit;
            else var newMax = shoutsNum;
            // change max
            $('.dracon_shout_showmax').fadeOut(300, function() {
              $(this).html(newMax);
              $(this).fadeIn();
              // display page
              $('.dracon_shout_display').html(jsCode).slideDown(2000);
            });
          });
        });
      });
    }
  });
  
  /* Input Magic */
  $('.input_magic input, .select_magic input').before('<div class="input_magic_left"></div>');
  $('.textarea_magic textarea').before('<div class="textarea_magic_left"></div>');
  $('.input_magic input').after('<div class="input_magic_right"></div>');
  $('.textarea_magic textarea').after('<div class="textarea_magic_right"></div>');
  $('.select_magic input').after('<div class="select_magic_btn"></div>');
  $('.input_magic input').live('click', function() {
    $(this).select().addClass('input_magic_active');
    $(this).prev().addClass('input_magic_left_active');
    $(this).next().addClass('input_magic_right_active');
  });  
  $('.select_magic input').live('click', function() {
    $(this).select().addClass('input_magic_active');
    $(this).prev().addClass('input_magic_left_active');
    $(this).next().addClass('select_magic_btn_active');
  });  
  $('.textarea_magic textarea').live('click', function() {
    $(this).select().addClass('textarea_magic_active');
    $(this).prev().addClass('textarea_magic_left_active');
    $(this).next().addClass('textarea_magic_right_active');
  });  
  $('.input_magic input, .select_magic input').live('mouseout', function() {
    $(this).removeClass('input_magic_active');
    $(this).prev().removeClass('input_magic_left_active');
    $(this).next().removeClass('select_magic_btn_active');
  });
  $('.textarea_magic textarea').live('mouseout', function() {
    $(this).removeClass('textarea_magic_active');
    $(this).prev().removeClass('textarea_magic_left_active');
    $(this).next().removeClass('textarea_magic_right_active');
  });

 
  // admin loading icon
  function dpa_lg() {
    if ($('#dracon_poll_admin_loading').css('visibility') == 'hidden') {
      $('#dracon_poll_admin_loading').css('visibility','visible');
    }
    else $('#dracon_poll_admin_loading').css('visibility','hidden');
  }

  // admin area reload
  function dpa_area(page) {
    $('#dracon_poll_admin_area').fadeIn(300, function() {
      switch (page) {
        case 1 : 
          dracon_poll_admin_buttons();
          break;
        case 2 : 
          dracon_poll_admin_buttons();
          dracon_poll_admin_option_buttons();
          break;
      }
      dracon_poll_tooltips();
      dpa_lg();
    });
  }
  
  // input onclick select
  /*
  $('input').click(function() { 
    this.select();
  });
  */
  
  // tooltips
  function dracon_poll_tooltips() {
    $("img.dracon_poll_admin_info").tooltip(-20,15);
    $("span.dracon_poll_admin_info_obj").tooltip(-20,15);
  }

  // admin login init
  $('#dracon_poll_admin_user').focus();
  
  // login function
  function dracon_poll_admin_login() {
    if (!$('#dracon_poll_admin_user').attr('value')) {
      $('#dracon_poll_admin_user').attr('value', 'enter login');
      $('#dracon_poll_admin_user').addClass($('#dracon_poll_admin_user').attr('class')+'_on');
      $('#dracon_poll_admin_user').focus().select();
      return false;
    }
    if (!$('#dracon_poll_admin_pass').attr('value')) {
      $('#dracon_poll_admin_pass').attr('value', 'xxx');
      $('#dracon_poll_admin_pass').addClass($('#dracon_poll_admin_pass').attr('class')+'_on');
      $('#dracon_poll_admin_pass').focus().select();
      return false;
    }
    oldHtml = $('#dracon_poll_admin_login_btn').html();
    $('#dracon_poll_admin_login_btn').html('Loading...');
    dpa_lg();
    $('#dracon_poll_admin_login_btn').load('?login', { login:$('#dracon_poll_admin_user').attr('value'), password:$('#dracon_poll_admin_pass').attr('value') }, function(jsCode) {
      $(this).html(oldHtml);
      switch (jsCode) {
        case 'login' :
          $('#dracon_poll_admin_user').addClass($('#dracon_poll_admin_user').attr('class')+'_err');
          $('#dracon_poll_admin_user').attr('value', 'incorrect login');
          $('#dracon_poll_admin_user').focus();
          dpa_lg();
          break;
        case 'password' :
          $('#dracon_poll_admin_pass').attr('value', 'xxxxx');
          $('#dracon_poll_admin_pass').addClass($('#dracon_poll_admin_pass').attr('class')+'_err');
          $('#dracon_poll_admin_pass').focus();
          dpa_lg();
          break;
        case 'ok' :
          $('#dracon_poll_admin_area').fadeOut(500, function() {
            $('#dracon_poll_admin_logout_btn').css('opacity', '0').css('visibility', 'visible');
            $('#dracon_poll_admin_logout_btn').animate({ opacity:1 }, 300);
            $('#dracon_poll_admin_area').load('?admin', function() {
              dpa_area(1);
            })
          })
          break;
      }
    });
  }
  
  // flexible admin button actions
  function dracon_poll_admin_buttons() {

    // login input enter
    $("#dracon_poll_admin_user").key(13,'dracon_poll_admin_login()');
    $("#dracon_poll_admin_pass").key(13,'dracon_poll_admin_login()');
    
    // login button
    $('#dracon_poll_admin_login_btn').click(function() {
      this.blur();
      dracon_poll_admin_login();
    });
    
    // admin input control
    var dracon_poll_admin_inputs = new Array('40','120','200');
    for (i=0; i<dracon_poll_admin_inputs.length; i++) {
      $('input.dracon_poll_admin_input_'+dracon_poll_admin_inputs[i]).click(function() {
        if (this.className.indexOf('_on') == -1) this.className = this.className+'_on';
      });
      $('input.dracon_poll_admin_input_'+dracon_poll_admin_inputs[i]).focus(function() {
        if (this.className.indexOf('_on') == -1) this.className = this.className+'_on';
      });
      $('input.dracon_poll_admin_input_'+dracon_poll_admin_inputs[i]).blur(function() {
        this.className = this.className.replace('_on', '');
      });
    }

    // admin checkbox control
    var dracon_poll_admin_checkboxes = new Array('1','2','3');
    for (i=0; i<dracon_poll_admin_checkboxes.length; i++) {
      $('img.dracon_poll_admin_checkbox_'+dracon_poll_admin_checkboxes[i]).click(function() {
        if (this.className.indexOf('_on') == -1) this.className = this.className+'_on';
        else this.className = this.className.replace('_on', '');
      });
      $('img.dracon_poll_admin_checkbox_'+dracon_poll_admin_checkboxes[i]+'_on').click(function() {
        if (this.className.indexOf('_on') == -1) this.className = this.className+'_on';
        else this.className = this.className.replace('_on', '');
      });
    }
    
    // save all
    $('#dracon_poll_admin_save_all').click(function() {
      $('img.dracon_poll_admin_checkbox_1').each(function() {
        this.className = 'dracon_poll_admin_checkbox_1_on';
      });
    });
    
    // add new poll
    $('#dracon_poll_admin_add_new').click(function() {
      this.blur();
      $(this).html('Adding...');
      dpa_lg();
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        $('#dracon_poll_admin_area').load('?addNewPoll', function() {
          dpa_area(1);
        });
      });
    });
    
    // delete poll
    $('img.dracon_poll_admin_del').click(function() {
      this.blur();
      var pollId = this.alt;
      if (OkCancel('Are you sure? Poll #'+pollId+' will be removed and all related options and votes destroyed!') === false) return false;
      dpa_lg();
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        $('#dracon_poll_admin_area').load('?delPoll', { pollId:pollId }, function() {
          dpa_area(1);
        });
      });
    });
    
    // save poll details
    var dracon_poll_admin_save_data = new Array('count','pollId','title','multiline','width','height','skin','effect','fxspeed','status','votes');
    $('#dracon_poll_admin_poll_save').click(function() {
      this.blur();
      $(this).html('Saving...');
      dpa_lg();
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        var fullData = '';
        var pollData = new Array();
        var dataCounter = 0;
        $('tr.dracon_poll_admin_tr').each(function() {
          var pollCounter = 0;  // within poll
          dataCounter++;  // global array
          $(this).children('td').each(function() {
            var newData = '';
            // input values
            if ($(this).children().attr('value')) pollData[pollCounter] = $(this).children().attr('value');
            // checkboxes & non-inputs
            else {
              var checkBox = $(this).children().attr('class');
              pollData[pollCounter] = (checkBox && checkBox.indexOf('_on') != -1) ? 1 : 0;
            }
            // save checked
            if (pollCounter == 11 && pollData[11] == 1) {
              for (i=1; i<11; i++) {
                //pollData[i] = strReplace(pollData[i].toString(), '&', '%26');
                fullData += '&'+dracon_poll_admin_save_data[i]+'[]='+escape(pollData[i]);
              }
            }
            pollCounter++;
          });
        });
        $('#dracon_poll_admin_area').load('?savePollData', { data:fullData }, function() {
          dpa_area(1);
        });
      });
    });


    // load options
    $('.dracon_poll_text_link').click(function() {
      this.blur();
      var pollId = this.value;
      dpa_lg();
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        $('#dracon_poll_admin_area').load('?loadOptions', { pollId:pollId }, function() {
          dpa_area(2);
        });
      });
    });
    // load options double click on title
    $('.dracon_poll_admin_input_200').dblclick(function() {
      this.blur();
      var pollId = $(this).parent().prev().children('input:first').attr('value');
      dpa_lg();
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        $('#dracon_poll_admin_area').fadeOut(300).load('?loadOptions', { pollId:pollId }, function() {
          dpa_area(2);
        });
      });
    });

    // go back to polls
    $('.dracon_poll_admin_options_link').click(function() {
      this.blur();
      dpa_lg();
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        $('#dracon_poll_admin_area').load('?admin', function() {
          dpa_area(1);
        });
      });
    });
  
  }
  
  // flexible admin button actions - options only
  function dracon_poll_admin_option_buttons() {
    // remove interference
    $('.dracon_poll_admin_input_200').unbind('dblclick');
    
    // add new option
    $('#dracon_poll_admin_add_new').unbind('click').click(function() {
      this.blur();
      var pollId = $(this).parent().children('input:first').val();
      $(this).html('Adding...');
      dpa_lg();
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        $('#dracon_poll_admin_area').load('?addNewOption', { pollId:pollId }, function() {
          dpa_area(2);
        });
      });
    });
    
    // delete option
    $('img.dracon_poll_admin_del').unbind('click').click(function() {
      this.blur();
      var idList = this.alt.split(',');
      if (OkCancel('Are you sure? Option #'+idList[0]+' will be removed from Poll #'+idList[1]+' and all related votes destroyed!') === false) return false;
      dpa_lg();
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        $('#dracon_poll_admin_area').load('?delOption', { optionId:idList[0], pollId:idList[1] }, function() {
          dpa_area(2);
        });
      });
    });
    
    // save option details
    var dracon_poll_admin_save_data = new Array('count','optionId','title','bullet','position','status','votes');
    $('#dracon_poll_admin_poll_save').unbind('click').click(function() {
      this.blur();
      var pollId = $(this).parent().children('input:first').val();
      $(this).html('Saving...');
      dpa_lg();

      $('#dracon_poll_admin_area').fadeOut(300, function() {

        var fullData = '';
        var optionData = new Array();
        var dataCounter = 0;
        $('tr.dracon_poll_admin_tr').each(function() {
          var optionCounter = 0;  // within poll
          dataCounter++;  // global array
          $(this).children('td').each(function() {
            var newData = '';
            // input values
            if ($(this).children().attr('value')) optionData[optionCounter] = $(this).children().attr('value');
            // checkboxes & non-inputs
            else {
              var checkBox = $(this).children().attr('class');
              optionData[optionCounter] = (checkBox && checkBox.indexOf('_on') != -1) ? 1 : 0;
            }
            // save checked
            var optionLength = dracon_poll_admin_save_data.length;
            if (optionCounter == optionLength && optionData[optionLength] == 1) {
              for (i=1; i<optionLength; i++) {
                fullData += '&'+dracon_poll_admin_save_data[i]+'[]='+escape(optionData[i]);
              }
            }
            optionCounter++;
          });
        });
        $('#dracon_poll_admin_area').load('?saveOptionData', { pollId:pollId, data:fullData }, function() {
          dpa_area(2);
        });

      });
    });
    
  }
  
  // admin button actions - logout
  $('#dracon_poll_admin_logout_btn').click(function() {
    this.blur();
    oldHtml = $(this).html();
    $(this).html('Closing...');
    dpa_lg();
    $(this).load('?logout', function() {
      $(this).html(oldHtml);
      $(this).animate({ opacity:0 }, 500)
      $('#dracon_poll_admin_area').fadeOut(300, function() {
        $('#dracon_poll_admin_area').load('?relogin', function() {
          dpa_area(1);
        });
      });
    });
  });
  
  // initialize buttons
  dracon_poll_admin_buttons();
  // initialize tooltips
  dracon_poll_tooltips();
  
  
  /* Poll Installation Effects */ 
  function dracon_poll_install_btn(page) {
    this.blur();
    $('#dracon_poll_install_div').animate({ opacity:0.1 }, 300, function() {
      $('#dracon_poll_install_loading').show();
      $('#dracon_poll_install_div').load('?'+page, function() {
        $('#dracon_poll_install_loading').hide();
        $('#dracon_poll_install_div').animate({ opacity:1 }, 300);
        dracon_poll_admin_buttons();
        dracon_poll_install_buttons();
      });
    });
  }
  // all installation buttons ~ code optimization planned  
  function dracon_poll_install_buttons() {
    $('#dracon_poll_install_inst').unbind('click').click(function() { dracon_poll_install_btn('inst'); });
    $('#dracon_poll_install_begin').unbind('click').click(function() { dracon_poll_install_btn('check'); });
    $('#dracon_poll_install_check').unbind('click').click(function() { dracon_poll_install_btn('check'); });
    $('#dracon_poll_install_read').unbind('click').click(function() { dracon_poll_install_btn('readme'); });
    $('#dracon_poll_install_chlog').unbind('click').click(function() { dracon_poll_install_btn('chlog'); });
    $('#dracon_poll_install_lic').unbind('click').click(function() { dracon_poll_install_btn('lic'); });
    $('#dracon_poll_install_conf').unbind('click').click(function() { dracon_poll_install_btn('conf'); });
    // save config file
    $('#dracon_poll_install_save').unbind('click').click(function() { 
      this.blur();
      var cfgInfo = new Array();
      var fullData = '';
      $(this).html('saving...');
      $('#dracon_poll_install_info').html($('#dracon_poll_install_loading').html());
      $('#dracon_poll_install_div input').each(function(cfgCount) { cfgInfo[cfgCount] = $(this).val(); });
      for (i=0; i<cfgInfo.length; i++) { fullData += '&'+i+'='+escape(cfgInfo[i]); }
      // add data select
      fullData += '&'+i+'='+$('#dracon_poll_data').val();
      // add checkbox
      var checkBox = $('#dracon_poll_install_voted_skip img').attr('class');
      fullData += (checkBox && checkBox.indexOf('_on') != -1) ? '&'+(i+1)+'='+true : '&'+(i+1)+'='+false;
      var checkBox2 = $('#dracon_poll_install_voted_once img').attr('class');
      fullData += (checkBox2 && checkBox2.indexOf('_on') != -1) ? '&'+(i+2)+'='+true : '&'+(i+2)+'='+false;
      $('#dracon_poll_install_div').animate({ opacity:0.1 }, 300, function() {
        $('#dracon_poll_install_loading').show();
        $('#dracon_poll_install_div').load('?save', { data:fullData }, function() {
          $('#dracon_poll_install_loading').hide();
          $('#dracon_poll_install_div').animate({ opacity:1 }, 300);
          dracon_poll_admin_buttons();
          dracon_poll_install_buttons();
        });
      });
    });
    // install db
    $('#dracon_poll_install_db').unbind('click').click(function() { 
      this.blur();
      var oldHtml = $(this).html();
      var dbInfo = new Array();
      var fullData = '';
      $(this).html('installing...');
      $('#dracon_poll_install_info').html($('#dracon_poll_install_loading').html());
      $('#poll_mysql_details input').each(function(dbCount) { dbInfo[dbCount] = $(this).val(); });
      for (i=0; i<dbInfo.length; i++) { fullData += '&'+i+'='+escape(dbInfo[i]); }
      $('#dracon_poll_install_db').load('?db', { data:fullData }, function(jsCode) {
        $(this).html(oldHtml);
        $('#dracon_poll_install_info').css('color', 'green').html(jsCode);
        $('#dracon_poll_install_drop').show();
      });
    });
    // drop tables
    $('#dracon_poll_install_drop').unbind('click').click(function() { 
      this.blur();
      var oldHtml = $(this).html();
      var dbInfo = new Array();
      var fullData = '';
      $(this).html('removing...');
      $('#dracon_poll_install_info').html($('#dracon_poll_install_loading').html());
      $('#poll_mysql_details input').each(function(dbCount) { dbInfo[dbCount] = $(this).val(); });
      for (i=0; i<dbInfo.length; i++) { fullData += '&'+i+'='+escape(dbInfo[i]); }
      $('#dracon_poll_install_drop').load('?db', { drop:true, data:fullData }, function(jsCode) {
        $(this).html(oldHtml).hide();
        $('#dracon_poll_install_info').css('color', 'red').html(jsCode);
      });
    });
    // show & hide mysql fields
    $('#dracon_poll_data').unbind('change').change(function() { 
      this.blur();
      if ($('#poll_mysql_details').css('display') == 'none') $('#poll_mysql_details').show();
      else $('#poll_mysql_details').hide();
    });
    // password generator
    $('#dracon_poll_install_genpass').unbind('click').click(function() { 
      this.blur();
      window.open('http://www.dracon.biz/password_generator.php');
      return false;
    });
  }
  
  // init all buttons
  dracon_poll_install_buttons();

  // already voted polls
  $('div.dracon_poll_voted').each(function() { 
    eval($(this).html());
  });
  
  // display already voted polls on click
  $('span.dracon_poll_show_votes').click(function() {
    eval($(this).children('div').html());
  });
  
});


