$(function(){
	$(document).scrollTop(Math.ceil(($(document).height()*10)/100));	
	var loader=$('#loader');
	var pollcontainer=$('#pollcontainer');
	loader.fadeIn();
	//Load the poll form
	$.get(sprintf(ajaxUrlFormat,lang,'pollerAjax'),function(data, status){
		pollcontainer.html(data);
		animateResults(pollcontainer);
		pollcontainer.find('#viewresult').click(function(){
			//if user wants to see result
			loader.fadeIn();
			$.post(sprintf(ajaxUrlFormat,lang,'pollerAjax'), {result:'1',currentCheckId:$('#currentCheckId').val()}, function(data,status){
				pollcontainer.fadeOut(1000, function(){
					$(this).html(data);
					animateResults(this);
				});
				loader.fadeOut();
			});
			//prevent default behavior
			return false;
		}).end()
		//	.find('#pollform').submit(
		pollcontainer.find('#votetome').click(function(){
			var mainform=pollcontainer.find('#pollform');
			var selected_val=mainform.find('input[name=poll]:checked').val();
			if(selected_val!=''){
				//post data only if a value is selected
				loader.fadeIn();
				$.post(sprintf(ajaxUrlFormat,lang,'pollerAjax'), mainform.serialize(), function(data, status){
					$('#formcontainer').fadeOut(100, function(){
						mainform.html(data);
						animateResults(this);
						loader.fadeOut();
					});
				});
			}
			//prevent form default behavior
			return false;
		});
		loader.fadeOut();
	});

	///=====================
	
		function fillNewsTabsByAjax(type){
		$(type+" ul").html('<li style="margin-top:20px;clear:both;padding-right:90px;background:none;" >'+$('#loader').html()+'</li>');
		$.post(sprintf(ajaxUrlFormat,lang,'tabsAjax'),{type :type,currentCheckId:'2'},
		   function(data){ 
		   $(type+" ul").html("");
		   for(var i=0;i<data.length;i++){
			   if(data[i].author== null)
			   data[i].author="";
		$(type+" ul").append("<li><h3><a title='"+data[i].title+"' href='"+sprintf(newsUrlFormat,lang,data[i].cat,data[i].id,data[i].title)+"'>"+data[i].title+"</a></h3>"+
			"<span>"+data[i].visits+"</span></li><div class='tabBorder'> </div>");
		   }
		   },"json");
}

		function fillViewsTabsByAjax(type){
		$(type+" ul").html('<li style="margin-top:20px;clear:both;padding-right:90px;background:none;" >'+$('#loader').html()+'</li>');			
		$.post(sprintf(ajaxUrlFormat,lang,'tabsAjax'),{type :type,currentCheckId:'2'},
		   function(data){ 
		   $(type+" ul").html("");
		   for(var i=0;i<data.length;i++){
			   if(data[i].author== null)
			   data[i].author="";
		$(type+" ul").append("<li><h3><a title='"+data[i].title+"' href='"+sprintf(newsUrlFormat,lang,data[i].cat,data[i].id,data[i].title)+"'>"+data[i].title+"</a></h3>"+
			"<span>"+data[i].author+"</span></li><div class='tabBorder'> </div>");
		   }
		   },"json");
}
	
	$("ul.tabs li").click(function(){
								   
		fillViewsTabsByAjax($(this).find("a").attr("href"));
		
								  });
		$("ul.tabs1 li").click(function(){
								   
		fillNewsTabsByAjax($(this).find("a").attr("href"));
		
								  });
		

	//=========|| Tabs ||============

//////

	
	
//		fillTabsByAjax($("ul.tabs li:first").find("a").attr("href"),"sadaMostNews");

	

	});
	

	
