var theInt = null;
var $crosslink, $navthumb;
var curclicked = 0;
theInterval = function(cur){
	clearInterval(theInt);
	if( typeof cur != 'undefined' )
		curclicked = cur;
	$crosslink.removeClass("active-thumb");
	$navthumb.eq(curclicked).parent().addClass("active-thumb");
		$(".stripNav ul li a").eq(curclicked).trigger('click');
	theInt = setInterval(function(){
		$crosslink.removeClass("active-thumb");
		$navthumb.eq(curclicked).parent().addClass("active-thumb");
		$(".stripNav ul li a").eq(curclicked).trigger('click');
		curclicked++;
		if( 5 == curclicked )
			curclicked = 0;	
	}, 3000);
};
function init_home(){

	$('#hometxt').css('height', (docHeight-150)+'px');	
	$('.titolo').corner("round 4px");
	$('.data').corner("bottom 4px");
		$(".linkmaps").fancybox({
		'width'				: '75%',
		'height'			: '85%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'scrolling'  		: 'auto'
	});
	$("#main-photo-slider").codaSlider();
	$navthumb = $(".nav-thumb");
	$crosslink = $(".cross-link");
	$navthumb
	.click(function() {
		var $this = $(this);
		theInterval($this.parent().attr('href').slice(1) - 1);
		return false;
	});
	loadScrollers('home');
}
$(document).ready(function() {
			$("#news").html().replace(/Kali Arnis Escrima/, '<a href="javascript:loadContent(\'personal\');">Kali Arnis Escrima</a>');
	$("#news").html().replace(/Ginnastica pugilistica/, '<a href="javascript:loadContent(\'personal\',\'boxe\');">Ginnastica pugilistica</a>');
});	
//add click handler for button  
function insertComment(id) {  
  
  //define ajax config object  
 var ajaxOpts = {  
   type: "post",  
    url: "addComment.php",  
    data: "&id="+id+"&author=" + $("#leaveComment"+id).find("input").val() + "&comment=" + $("#leaveComment"+id).find("textarea").val(),  
   success: function(data) {  
alert('Inserito');
      //create a container for the new comment  
      var div = $("<div>").addClass("row").appendTo("#comments");  
     //add author name and comment to container  
    $("<label>").text($("#leaveComment"+id).find("input").val()).appendTo(div);  
      $("<div>").addClass("comment").text($("#leaveComment"+id).find("textarea").val()).appendTo(div);  
    }  
  };  
 
 $.ajax(ajaxOpts);  
}
function viewComments(id){
  $("#commenti"+id).css('display','block');
   //retrieve comments to display on page  
    $.getJSON("comments.php?id="+id+"&jsoncallback=?", function(data) {  
  
       //loop through all items in the JSON array  
      for (var x = 0; x < data.length; x++) {  
   
        //create a container for each comment  
        var div = $("<div>").addClass("row").appendTo("#comments"+id);  
   
         //add author name and comment to container  
        $("<label>").text(data[x].name).appendTo(div);  
       $("<div>").addClass("comment").text(data[x].comment).appendTo(div);  
      }  
    });  
  } 
			
