jQuery(window).bind("load", function() {
	$('#secondary').hide(0);
	$('#poll').hide(0);
	//$('ul.poll label').hide(0);
	hideContent();
	openVotes();
	
	
});

jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

};


$(function() {
	$('#pollf li').click(function (e) { 
								   //alert($(e.target).find('input[type="radio"]'));
		var inputValue = $(e.target).find('input[type="radio"]').val();
		$.post("vote.php",{
			   voteid: inputValue,
			   pollid: 1, 
			   poll: ''
			   },
			   function(data) {
				  if(data.msg!=null) {
					  $('#poll-box h4').text(data.msg);
				  }
				  else {
					  hideContent();
					  showContent(data);					 
				  }
				  //alert(data.msg);
			   },
			   'json'
	      );
		return false;
	});
	$('#scriptcode').click(function(e) {
									  							  
	});

	$('a.but_readmore').click(function(e) {
		$(e.target).prev().fadeToggle();
		$(e.target).hide();
		$('a.but_readmoree').show();
		$('a.but_readmoree').attr('style', 'display:block');
	});
	$('a.readcampaign').click(function(e) {
		$('div.more').fadeToggle();							  							  
	});



});

function showContent(data) {
	$('#votes-total').text(data.votecount);
	$('#option1text').text(data.option1);
	$('#option2text').text(data.option2);
	$('#option3text').text(data.option3);
	$('#secondary').slideDown();
	$('p#vote-option'+data.voteid).show(0);
	selectFlag(data.voteid);
	$('#poll-box h4').text("Ai ales varianta " + data.voteid);
	$('#aidreptate').text("Ai dreptate. Sau nu. Nu stim. Nu stie nimeni.");
	$('ul.poll a').click(function(e) {
		return false;
	});
	
}

function hideContent() {
	$('p#vote-option1').hide(0);
	$('p#vote-option2').hide(0);
	$('p#vote-option3').hide(0);
}
function selectFlag(id) {
	
	$('#option1').unbind('click');
	
	$('#option2').unbind('click');
	$('#option3').unbind('click');
	$('ul.poll').addClass('voted');
	$('#pollf li#option'+id).addClass('selected');
	
	
//$('ul.voted a').removeClick(e);
}
function openVotes() {
	var anchor = document.location.hash;
	var ids = anchor.split("-");
	var id = ids[1];
	if(id!=null) {
	//data.voteid = id;
	//showContent(data);
	$('#secondary').slideDown();
	$('p#vote-option'+id).show(0);
	selectFlag(id);
	$('#poll-box h4').text("Ai ales varianta " +id);
	//alert('aaa');
	}
}
function removeClick() {
	//alert('aaa');
}
function select_text()
{
var content=eval("document.getElementById('scriptcode')");
content.focus();
content.select();
}
