
/* bordi arrotondati solo per IE */
//DD_roundies.addRule('.searchNome, .searchGraduatorie, .boxEvidenzia, .contentService h3, .contentService h3.active, ul.utilityUser li a', '5px');
//DD_roundies.addRule('.associatedProf, .advanced-form fieldset, .attention, .boxPay h3 span, a.btnPay, .bodyTable tr span', '5px');
//DD_roundies.addRule('.borderRadiusTable, a.btnUp, .boxMieGraduatorie ', '5px');
//DD_roundies.addRule('ul.tab li a', '5px 5px 0px');
//DD_roundies.addRule('ul.pagination li a', '3px');

function scrollUp() {
	//var full_url = this.href;
	var full_url = '#content';
	var parts = full_url.split("#");
	var trgt = parts[1];

	var target_offset = $("#"+trgt).offset();
	var target_top = target_offset.top;
	
	$('html, body').animate({scrollTop:target_top}, 500);
}

function scrollTop() {
	$('html, body').animate({scrollTop:0});
}

/* varie */


function vir_change_list_color() {
	//$(".results li:nth-child(even)").addClass("colorLi");
	$(".history li:nth-child(even)").addClass("colorLi");
	$(".banner li:nth-child(even)").addClass("noMargin");
}


function disable_coda() {
	if($('#scorriGraduatoria_annoPubblicazione').val() == '2011') {
		$('#scorriGraduatoria_tipoGraduatoria_coda').parent().hide();
		$('#scorriGraduatoria_tipoGraduatoria_pettine').attr("checked", "checked");
	} else {
		$('#scorriGraduatoria_tipoGraduatoria_coda').parent().show();
	}
}


function switch_tab(id) {
	$(".tab_content_map").hide(); //Hide all tab content
	$(id).show();
}

// Ridefinisco il metodo trim per IE8
if(typeof String.prototype.trim !== 'function') {
	  String.prototype.trim = function() {
	    return this.replace(/^\s+|\s+$/g, ''); 
	  }
	}


// Ridefinisco il metodo show in modo che invochi gli eventi afterShow, beforeShow
var _oldShow = $.fn.show;

$.fn.show = function(speed, oldCallback) {
    return $(this).each(function() {
            var
                    obj         = $(this),
                    newCallback = function() {
                            if ($.isFunction(oldCallback)) {
                                    oldCallback.apply(obj);
                            }

                            obj.trigger('afterShow');
                    };

            // you can trigger a before show if you want
            obj.trigger('beforeShow');

            // now use the old function to show the element passing the new callback
            _oldShow.apply(obj, [speed, newCallback]);
    });
}


$(document).ready(function(){

	//effetto sulla nav
	$("#nav").lavaLamp({ fx: "backout", speed: 300 });
	
	
	// Accordion servizi
	$('.container').hide();
	$('.contentService h3:first').addClass('active').next().show(); 
	
	
	$('.contentService h3').click(function(){
		if( $(this).next().is(':hidden') ) { 
			$('.contentService h3').removeClass('active').next().slideUp('fast'); 
			$(this).toggleClass('active').next().slideDown('fast'); 
		}
		return false; 
	});
	
	//scroll to top

	$(".btnUp").click(function(event){
		event.preventDefault();
		scrollUp();
	});	
	
	// Cambia colore al tag LI nelle liste dei risultati
	vir_change_list_color();
	
	// fancybox
	$("a#loginPull").fancybox();
	$("a.fancybox").fancybox();
	$("a.youtube").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'autoDimensions':true,
			'height'		: 385,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
				'wmode'				: 'transparent',
				'allowfullscreen'	: 'true'
			},
			'onComplete': function() { 
				$('#fancybox-content').css({'padding':'0'}); 
			}
		});

	return false;
	});
	
	// Azioni per il cambio di contesto Docenti/ATA
	$("#action_change_docenti").click(function() {
		$.cookie('vir_context_genere', 'docenti');
	});
	$("#action_change_ata").click(function() {
		$.cookie('vir_context_genere', 'ata');
	});
	
	
	
//	$("ul.results li a.link").fancybox({
//		'width'				: '100%',
//		'height'			: '85%',
//	    'autoScale'     	: false,
//	    'transitionIn'		: 'none',
//		'transitionOut'		: 'none',
//		'type'				: 'iframe'
//	});	
	
	// Tooltips
	$('a.suggestion').tooltip({
		layout: "<div><span class='frecciaToolDx'></span></div>",
		
		// place tooltip on the right edge
		position: "center right",

		// a little tweaking of the position
		offset: [-2, 10],


		// use the "toggle" effect
		effect: 'toggle'

	});
	
	// History
//	$.history.init(function(hash){
//        if(hash == "") {
//            // initialize your app
//        } else {
//            // restore the state from hash
//        }
//	});	
	
	// Tabs
   //When page loads...
   //$(".tab_content").hide(); //Hide all content
   $("ul.tabs li a.selected").parent().addClass("active").show(); //Activate first tab
   //$(".tab_content:first").show(); //Show first tab content

   //On Click Event
//   $("ul.tabs li").click(function() {
//
//       $("ul.tabs li").removeClass("active"); //Remove any "active" class
//       $(this).addClass("active"); //Add "active" class to selected tab
//       $(".tab_content").hide(); //Hide all tab content
//
//       var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
//       $(activeTab).show(); //Fade in the active ID content
//       return false;
//   });	
   
	// Tabs
   //When page loads...
   $(".tab_content").hide(); //Hide all content
   $("ul.tabs_index li a.selected").parent().addClass("active").show(); //Activate first tab
   $(".tab_content:first").show(); //Show first tab content

   //On Click Event
   $("ul.tabs_index li").click(function() {

       $("ul.tabs_index li").removeClass("active"); //Remove any "active" class
       $(this).addClass("active"); //Add "active" class to selected tab
       $(".tab_content").hide(); //Hide all tab content

       var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
       $(activeTab).show(); //Fade in the active ID content
       return false;
   });	   
   
   $('#scorriGraduatoria_annoPubblicazione').change(function(){
	   disable_coda();
   });
   disable_coda();
});


