var img1 = basedir() + 'modules/igg/images/button1.gif';
var img2 = basedir() + 'modules/igg/images/button2.gif';
var img3 = basedir() + 'modules/igg/images/button_bg.gif';

function iggButton(id, votes) {
	var o = "";

	o+= '<div style="width: 50px; color: #fff;">';
	o+= '<div id="igg'+id+'_votes" style="font-weight: bold; background: url('+img3+'); text-align: center; padding-top: 4px; height: 24px; color:#820e0e;">';
	o+= votes;
	o+= '</div>';
	o+= '<div id="igg'+id+'_button" onclick="iggVote('+id+', '+votes+');" style="cursor:pointer; background: url('+img1+'); height: 16px; text-align: center; font-size: 11px;">VOTE</div>';
	o+= '</div>';
	// Ausgabe
	document.write(o);
}

function iggVote(id, votes) {
	var newvotes = votes+1;


    $.ajax({
      url: basedir()+"modules/igg/vote.php?id="+id,
      cache: false,
      success: function(html){

		if(html == "ok") {

            $('#igg'+id+'_votes').fadeOut('fast',function(){
                $('#igg'+id+'_votes').html( newvotes ).fadeIn('normal');
            });

            $('#igg'+id+'_button').fadeOut('fast',function(){
                $('#igg'+id+'_button').css('cursor', '').html('VOTED').css('background', 'url('+img2+')').attr('onClick', '').fadeIn('fast');
                //$('#igg'+id+'_button')
            });


        } else if (html == "already_voted") {
            $('#igg'+id+'_button').fadeOut('fast',function(){
                $('#igg'+id+'_button').css('cursor', '').html('VOTED').css('background', 'url('+img2+')').attr('onClick', '').fadeIn('fast');
                //$('#igg'+id+'_button')
            });
        } else {
        	alert(html);
        }

      }
    });




}
