function starrating(id,r,c) 
{
	$.get("utils/rating.php",
        {rateID:id, r:r, c:c},
        function(returned_data)
        {
        	if(returned_data)
        	{
				$('#ratingblock_'+id).html(returned_data);
       		}
        });
}

$(document).ready(function() {

 	$(".favlink").click(function(event){
   
   	id = ($(this).attr('id'));
	id = id.substring(7);
	
	var link = $('#favlink'+id).attr('href');

	$.get("utils/fav.php",  link, function(data)
	{
		if(data.status=='error') { alert(data.message); }
		else 
		{ 
			alert(data.message);
			$(".favcount").html(data.count);
			if(data.page!=='detail') { 
			$("#favlink"+id).html("<img src=\"pic/icon-ok.gif\" style=\"border:0;float:none;vertical-align:top;margin:0px;padding:0;\">");
			}
			if(data.fade==1) { $("div.item#vid"+id).fadeOut("slow"); }
		}
		
	}, 'json');
	});	
	
 	$("#broken").click(function(event){
	var answer = confirm ("Jste si jistý ?")
	if(!answer) 
	{
		return false;
	}

	var link = $('#broken').attr('href');
		
	$.get("utils/broken.php",  { broken: link }, function(data)
	{
		alert(data.message);
		
	}, 'json');
	});	

 	$(".cabc").click(function(event){
	var link = $(this).attr('href');
	var iLen = String(link).length;
	var topCat = String(link).substring(iLen-1, iLen);

	$("#loading"+topCat).ajaxStart(function() { $(".loading").hide(); $(".res").hide(); $(this).show(); });
	$("#loading"+topCat).ajaxStop(function() { $(this).hide(); });	

	$('.cabc').removeClass('active');
	$(this).addClass('active');

	$.get("utils/cat_abc.php", { url:link }, function(data)
	{
		$("#res"+topCat).show();	
		$("#res"+topCat).html(data.message);
		
	}, 'json');
	});


	// topcall	
	$(".topcall").click(function(event){ 
	cat = ($(this).attr('id'));
	// alert(cat);
	
		// $(".topcall").each(function(){this.onmouseup = this.blur();});
		$(".topcall").removeClass("active");
		$("#"+cat).addClass("active");		
		
		$("#loading").ajaxStart(function() {
		   $(this).show();
		});
		$("#loading").ajaxStop(function() {
		   $(this).hide();
		});
	
		$.get("utils/topcall.php", {cat: cat}, function(data)
		{
			$("#topcallres").html(data);			
			
		}, 'txt');  
	});



	$("#cPager a").click(function(event) {
 
		var id = ($(this).attr('id')).substring(6);
	 	// alert(id);
		$("#loading").ajaxStart(function() {
		   $(this).show();
		   // $("#commentsData").hide();	
		});
		$("#loading").ajaxStop(function() {
		   $(this).hide();
		}); 	

		$("#cPager a").removeClass("active");
		$("#cPager"+id).addClass("active");		
		$.get("utils/comments.php", {id: id}, function(data)
		{
			$("#commentsData").html(data);			
			
		}, 'txt');  


    });

	

});

/*
	function displayComments(cPage){
	
		alert(cPage);
		 
	}
*/


function showSocials(i) {
	var links = document.getElementById("social-links-" + i);
	links.style.display = 'block';
}
function hideSocials(i) {
	var links = document.getElementById("social-links-" + i);
	links.style.display = 'none';
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
     anchor.target = "_blank";
    }

}
}

