$(window).ready(function() {
	$('body:not(#location, #aziende) #slider').nivoSlider({
		pauseTime: 5000,
		slices: 1,
		boxCols: 1,
		boxRows: 1,
		effect: "fade",
		controlNav: false,
		pauseOnHover: true
	});
	
	var togglePlaying = false;
	 $('#location #slider').nivoSlider({
		slices: 1,
		boxCols: 1,
		boxRows: 1,
		pauseTime: 7500,
		effect: "fade",
		controlNav: false,
		pauseOnHover: true,
		directionNavHide: false,
		pauseNav: true,
		afterLoad: function() {
			togglePlaying = !$('#slider').data('nivo:vars').paused;
			updateTextLocation($('#location #slider').data('nivo:vars').currentSlide);
		},
		beforeChange: function() {
			var cs = $('#location #slider').data('nivo:vars').currentSlide + 1;
			if (cs < 0) cs = gallery.length-1;
			if (cs >= gallery.length) cs = 0;
			updateTextLocation(cs);
		},
		afterChange: function() {
			if (!togglePlaying) {
				$('#location #slider').data('nivoslider').start();
			}
			//updateTextLocation($('#location #slider').data('nivo:vars').currentSlide);
		}

	});
	 
	function updateTextLocation(imgId) {
		$('.wide_col').html(gallery[imgId].testo);
		$('.bottom .content').html(gallery[imgId].icone);
		$('.caption .fLeft').html(gallery[imgId].titolo);
		$('.caption .fRight').html(gallery[imgId].sottotitolo);
	}
	
	
	$('.nivo-pauseNav').click(function() {
		if (togglePlaying) { // stop
			$('#location #slider').data('nivoslider').stop();
		} else { // play
			$('#location #slider').data('nivoslider').start();
		}
		togglePlaying = !togglePlaying;
	});
	
	
	
	
	$('#aziende #slider').nivoSlider({
		pauseTime: 5000,
		slices: 1,
		boxCols: 1,
		boxRows: 1,
		effect: "fade",
		controlNav: false,
		pauseOnHover: true,
		afterLoad: function() {
			togglePlaying = !$('#slider').data('nivo:vars').paused;
			updateTextAziende($('#aziende #slider').data('nivo:vars').currentSlide);
		},
		beforeChange: function() {
			var cs = $('#aziende #slider').data('nivo:vars').currentSlide + 1;
			if (cs < 0) cs = gallery.length-1;
			if (cs >= gallery.length) cs = 0;
			updateTextAziende(cs);
			//updateTextAziende($('#aziende #slider').data('nivo:vars').currentSlide);
		}

	});
	 
	function updateTextAziende(imgId) {
		$('.caption').html(gallery[imgId].caption);
	}
    
    $("a[rel^='prettyPhoto']").prettyPhoto({
        deeplinking: false,
        social_tools: false
    });
});

function PrintMailLink(nome, dominio, label){
    var email = nome+'@'+dominio;
    if(!label) label = email;
    document.write('<a href="mailto:'+email+'">'+label+'</a>');
}

//$(document).ready(checkResize);
//$(window).resize(checkResize);

function checkResize() {
    if($('#homepage').length > 0) {
    	console.log("w: " + $('body').width() + " - " + $('.center_col').width() + " - " + $('#supersized').width());
    }
}

// nascondo la barra di navigazione per iPhone
$(window).live('load', function() {
	setTimeout(scrollTo, 0, 0, 1);
}, false);

// gestisco i cambi di orientamento per device
//$(window).live('load', setOrientation, false);
//$(window).live('orientationchange', setOrientation, false);

function setOrientation() {
	var orient = Math.abs(window.orientation) === 90 ? 'landscape' : 'portrait';
	var cl = document.body.className;
	document.body.className = orient;
}  

