$(document).ready(function(){
	//Preload images
	$("img.himg").each(function(i){
		var preimg = $(this).attr("src").replace('.jpg', '_hover.jpg');
		jQuery("<img>").attr("src", preimg);
		if($(this).hasClass("selected")){
			$(this).attr("src", $(this).attr("src").replace('.jpg', '_hover.jpg'));
		}
	});
	setTimeout("setvotes()",1500);
	$("img.himg").mouseover(function(){
		if(!$(this).hasClass("selected")){
			$(this).attr("src", $(this).attr("src").replace('.jpg', '_hover.jpg'));
		}
	});
	
	$("img.himg").mouseout(function(){
		if(!$(this).hasClass("selected")){
			$(this).attr("src", $(this).attr("src").replace('_hover.jpg', '.jpg'));
		}
	});
	$("#btn_vote").bind("click",vote);
	$(".news_item").hover(function(){$(this).addClass("hover").find("span").animate({marginLeft:"6px"})},function (){$(this).removeClass("hover").find("span").animate({marginLeft:"0px"})});
   	$(".agenda_item").hover(function(){$(this).addClass("hover").find("span.text").css({"display":"block"}).animate({marginLeft:"6px"})},function (){$(this).removeClass("hover").find("span.text").animate({marginLeft:"0px"})});
});

function setvotes(){
	$(".votes").each(function(){
		$(this).animate({ width: $(this).attr("title") }, 1000,function(){
			$(this).html($(this).attr("title"));
		});

	});
}
function vote(){
	if($(".awnser:checked").length!=0){
		$.post(document.location.href,{awnser:$(".awnser:checked").val()}, function(ref) {
			$(".poll").html(ref);
			setvotes();
		});
	}
}
