﻿var _POPUP_DEF = 'resizable=no,location=1,statusbar=0,menubar=0,toolbar=0';
var _POPUP_W = 600
var _POPUP_H = 400

// Global Ajax notifiers
$(document).ready(function(){
	$('#ajaxworking').ajaxStart(function(){$('#ajaxworking').show();$('.ajaxworking').show();}).ajaxComplete(function(){$('#ajaxworking').hide();$('.ajaxworking').hide()});
	
	// animazione in HP
	if ($('#home').length) {
		$('.intro img').animate({opacity : 0}, 1)
		$('.intro img').each(function(index, value) {
			setTimeout(function() {
				$(value).animate({opacity : 1}, 2500)
			}, 4000.0 * Math.random());
		});
	}

	//gestione box accordion su pagina contenuto
        //nascondo tutti tranne il primo e quelli esplicitamente espansi
	$('#content-body h2:gt(0)[class!=expanded]').addClass('collapsed').next().hide()
        //nascondo quelli esplicitamente collassati
        $('#content-body h2[class=collapsed]').next().hide()
	$('#content-body h2').click(function() {
	  $(this).toggleClass('collapsed').next().slideToggle('fast')
	})

        //gestione switch lingua
        $('#top-links select:first').change(function(){
            window.location = $(this).val()
        })
});
// flash Messages
var flash = {
	div:'#flashcontent',
	alert:'alert',
	notice:'notice',
	warning:'warning',
	timeout:2500,
	show:function(which,what){
		$(this.div).html(what).removeClass().addClass(which).fadeIn('fast',function(){setTimeout("$(flash.div).fadeOut('slow')",flash.timeout);});
	}
};

// utilities varie
var util = {
	changeFontSize:function(size){
		$('body').css('font-size', size + 'em')
	},
	changeStyles:function (name){
		$('#css-contrast').attr('href','/includes/css/' + name + '.css')
	},
	addToBookmark: function(){
		title = document.title;
		url = location.href;
			if (window.sidebar) {
				window.sidebar.addPanel(title, url, "");
			} else if (window.external) {
				window.external.AddFavorite(url, title);
			}
		},
	sendUrl: function(){
		var href = escape(document.location.href);
		var title =  escape(document.title);
		var wnd = window.open('/invia.aspx?urlbase=' + href + '&l=' + idlang + '&titolo=' + title, 'invia', 'menubar=1,resizable=1,width=550,height=450')
		wnd.focus();
	},
	isUndefined: function (v) {
	    var undef;
	    return v===undef;
	},
	popupWin:function (url, target, features) {
	    if (util.isUndefined(features)) features = _POPUP_DEF + ',width='+_POPUP_W+',height='+_POPUP_H;
	    if (util.isUndefined(target  )) target   = '_blank';
	    var theWindow = window.open(url, target, features);
	    theWindow.focus();
	    return theWindow;
	},
	popupLink:function (obj,width,height,opt) {
if (util.isUndefined(opt)){
  opt= ''
}else{
  opt = ',' + opt
}
		if (util.isUndefined(width)) width = _POPUP_W
		 if (util.isUndefined(height)) height = _POPUP_H
		 util.popupWin($(obj).attr('href'), $(obj).attr('target'),_POPUP_DEF + ',width='+width+',height='+height + opt);
	    return false
	}
}



