<!--
$(document).ready(function(){

  var TABBED_CONTENT_URL = null;
  $('script').map(function(i) { 
    if (this.src.match(/man_gos_tabbed_content_init\.js(\?.*)?$/)) {
      TABBED_CONTENT_URL = this.src.replace(/\/man_gos_tabbed_content_init\.js(\?.*)?$/, '');
    }
  });
	
	
	//block resize textarea on safari - because need css 3.0
	if(jQuery.browser.safari && parseInt(jQuery.browser.version) >= 522){
		$('form.comments_form textarea').css({'resize':'none'});
	}

	//tabs
  if ($("#content_main_comments").tabs) {
  	$("#content_main_comments").tabs({
  		select: function(event, ui) { /*alert('k');*/ }
  	});
  }
	
	
	//view less/more elements
	$('a.button_add').click(function(){
		if( $(this).parent().parent().find('ul li').hasClass('hidden') ) {
			var tmp_h = $(this).parent().parent().find('ul li.hidden:first').outerHeight();
			$(this).parent().parent().find('ul li.hidden:first').slideDown('slow',function(){
			}).removeClass('hidden');
		}
		return false;
	});
	$('a.button_remove').click(function(){
		if( !$(this).parent().parent().find('ul li:first').hasClass('hidden') ) {
			$(this).parent().parent().find('ul li:not(:hidden):last').slideUp('slow',function(){
			}).addClass('hidden');
		}
		return false;
	});
	
	// reply comments
	$('#content_main_comments a.reply').click(function(){
		$('form.comments_form textarea').val('@'+$(this).attr('rel')+': ');
		targetOffset = $('form.comments_form').offset().top;
		$('html,body').animate({scrollTop: targetOffset-100}, 1000, 'easeOutBack');
		return false;
	});
	
	//submit comment
	$('#tab_send_comment').click(function(){
		$('form.comments_form').submit();
		return false;
	});
	
	$('form.comments_form').validate({
		rules: {
    	/*
			comment_nome: {
				required: true
			},
			comment_email: {
				required: true,
				email: true
			},
      */
			man_gos_tabbed_content_comment: {
				required: true
			}
		},
		messages: {
    	/*
			comment_nome: 'inserire il proprio nome',
			comment_email: 'inserire un indirizzo e-mail valido',
      */
			man_gos_tabbed_content_comment: 'inserire il commento'
		},
		submitHandler: function() {
			targetOffset = $('form.comments_form').offset().top;
			$('html,body').animate({scrollTop: targetOffset-100}, 1000, 'easeOutBack');
			var comment_data = 'man_gos_tabbed_content_comment=' + $('#man_gos_tabbed_content_comment').val() + '&man_gos_tabbed_content_toc_id=' + $('#man_gos_tabbed_content_toc_id').val();
			height = 100;
			$('form.comments_form').html('<p style="padding:0px; margin: 0px"><img src="'+TABBED_CONTENT_URL+'/images/ajax-loader.gif"> Invio del commento in corso...</p>').height(height);
			$.ajax({
				type: 'POST',
				url: TABBED_CONTENT_URL + '/ajax_add_comment.php',
				cache: false,
				data: comment_data,
				success: function(html){
					if ( $.trim(html) == 'OK' ) {
					$('form.comments_form').html('<p style="padding:0px; margin: 0px"><img src="'+TABBED_CONTENT_URL+'/images/accept.png"> Commento inviato.</p>').height(height);
					// Camargue.refreshNode('#content_main_comments', window.location);
					}else{
					$('form.comments_form').html('<p style="padding:0px; margin: 0px"><img src="'+TABBED_CONTENT_URL+'/images/warning.png"> Attenzione si è verificato un errore. ' + html + '</p>').height(height);
					}
				},
				error: function(html){
					$('form.comments_form').html('<p style="padding:0px; margin: 0px"><img src="'+TABBED_CONTENT_URL+'/images/warning.png"> Attenzione, si è verificato un errore. Si prega di ricaricare la pagina e riprovare.</p>').height(height);
				}
			});
		}
	});

});
//-->
