$(document).ready(function() {
//$("#mellofoto_gallery").queryLoader2({ backgroundColor:'#191919',barColor:'#FC0', percentage: true,barHeight:'30'});
if ($.browser.msie){
	if ($.browser.version<=7){
		alert("Browser non perfettamente compatibile con melloblocco.it. Si consiglia l'utilizzo di uno dei seguenti browser: Google Chrome, Mozilla Firefox o Internet Explorer 9");
	}
}
//BISCOTTI 
if($.cookie('mellocookie')==null){
	if(millisecondsLoading< 800){
		$.cookie("mellocookie","1", { expires: 10 });//10 gg 
	}else{
		$.cookie("mellocookie","0", { expires: 10 });//10 gg 
	}
}

if($.cookie("mellocookie") =="1"){
	//se il video č abilitato
	if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
        	//se SAFARI metti lo slideshow
		setSlideshowBackground();
	}else{
		if ($.browser.msie){
			//se explorer 
			if ($.browser.version<9){
				//se Explorer versione inferiore a 9 metti lo slideshow
				if($.browser.version>7){
					setSlideshowBackground();
				}
			}else{
				
				//se EXplorer 9 metti il video
				setVideoBackground();
				$('.pannello').show();
			}
		}else{	
			//per tutti gli altri browser
			setVideoBackground();	$('.pannello').show();
		}
	}
}else{
	//se il video č disabilitato metti lo slideshow
	setSlideshowBackground();
	if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
        	
	}else{
		if ($.browser.msie){
			//se explorer 
			if($.browser.version>=9){
				$('.pannello').show();
			}
		}else{	
			//per tutti gli altri browser
				$('.pannello').show();
		}
	}
}

// SCRIPT VIDEO 
function setVideoBackground() {
	$('body').prepend('<div class="video-background"></div>');
	$('.video-background').videobackground({
		videoSource: ['http://www.melloblocco.it/wp-content/themes/jamais-vu-v2/video/sfondo.mp4',
			'http://www.melloblocco.it/wp-content/themes/jamais-vu-v2/video/sfondo.webm',
			'http://www.melloblocco.it/wp-content/themes/jamais-vu-v2/video/sfondo.ogv'], 
			controlPosition: '#pannello_video',
			loop: true,
			poster: 'http://www.melloblocco.it/wp-content/themes/jamais-vu-v2/images/1.jpg'
	});
	$('.video-background').videobackground('mute');
}
// FINE SCRIPT VIDEO

 //SCRIPT SLIDESHOW BACKGROUND


function setSlideshowBackground(){
	function randomFromTo(from, to){
		return Math.floor(Math.random() * (to - from + 1) + from);
	}
	var random = randomFromTo(0,4);
	$.vegas({ src:'http://www.melloblocco.it/wp-content/themes/jamais-vu-v2/images/' + random + '.jpg'});
}
//FINE SCRIPT SLIDESHOW BACKGROUND

// SUONI
function suonoClick(){
	if (!$.browser.msie){mySound2.play();}
}
function suonoFreccia(){
	if (!$.browser.msie){mySound3.play();}
}

var mySound2 = new buzz.sound("http://www.melloblocco.it/wp-content/themes/jamais-vu-v2/audio/click", {
    formats: [ "ogg", "mp3" ],preload: true });
var mySound3 = new buzz.sound("http://www.melloblocco.it/wp-content/themes/jamais-vu-v2/audio/sound_arrow", {
    formats: [ "ogg", "mp3" ],preload: true });

// SET STYLE
var larghezza = $(window).width();
var altezza = $(window).height();
var altezzaInfoBox = altezza - 100;
var altezza_info = altezza;
var infobox = (larghezza * 6) + 20 ; 
var infoboxLi = larghezza;
var testo = larghezza - 20;  
var leftmargin = - (infobox - larghezza - 20);
$('.melloinfo_box').css('width', infobox);
$('.melloinfo_box ul li').css('width', infoboxLi);
$('.melloinfo_text').css('width', testo);
$('.navbox_close').hide();
//inizializzazione prettyphoto

$("a[rel^='prettyPhoto']").prettyPhoto({
	modal: false,
	theme: 'dark_rounded',
	show_title: true,
	social_tools:''
	});
$("a[rel^='prettyNews']").prettyPhoto({
	modal: false,
	theme: 'dark_square',
	show_title: false,
	social_tools: ''	
	});
$("a[rel^='prettyRassegna']").prettyPhoto({
		modal: false,
		theme: 'dark_square',
		show_title: false,
		social_tools: ''	
		});
//inizializzazione lightbox
$('.ngg-gallery-thumbnail a ').lightBox();
//nav menu
$('a.navRight, a.navLeft').hide();
$('a.navLeft').click(function(){
var position = $('.melloinfo_box').position();
if (!(position.left == leftmargin)) {
	suonoFreccia()
$('.melloinfo_box').animate({
    left: '-=' + larghezza
  }, 500);
} 
});

$('a.navRight').click(function(){ 
var position = $('.melloinfo_box').position();
if (!(position.left == 0)) {
suonoFreccia()
$('.melloinfo_box').animate({
    left: '+=' + larghezza
  }, 500);
} 
});

var melloinfo_box_enter=function () {//handler mouseenter
//le freccie scuriamole per favore
$('a.navRight, a.navLeft').stop(true).animate({ opacity: '0.9' });
//apro il box al passaggio del mouse
$(this).stop(true).animate({ bottom: '0' }, 500); 
$(this).animate({ opacity : '0.9' });
};
var melloinfo_box_leave=function () { //handler mouseleave
// poi perņ facciamole tornare normali ste freccie
$('a.navRight, a.navLeft').animate({ opacity: '0.5' });
//e lo chiudo quando il mouse se ne va
$(this).stop(true, true).animate({ bottom: '-227'
}, 500);
$(this).animate({ opacity : '1'});


 };

$('.melloinfo_box').bind('mouseenter', melloinfo_box_enter);
$('.melloinfo_box').bind('mouseleave', melloinfo_box_leave);


$('a.openInfo').click(function(){ 
$('.melloinfo_box').unbind( 'mouseleave' , melloinfo_box_leave);
$('.melloinfo_box').unbind( 'mouseenter', melloinfo_box_enter);

$('#logo_melloblocco, .mainSponsor').hide();

suonoClick()
$('.melloinfo_box').animate({
        height: altezza_info
  }, 500);
  $('a.navRight, a.navLeft, .funClick').hide();
  $('.melloinfo_text').css('height' , altezzaInfoBox);
});
$('a.closeInfo').click(function(){ 
$('#logo_melloblocco, .mainSponsor, ').show();
//e riporto tutto normale
$('.melloinfo_box').animate({
    height: '300'
  }, 500);
    $('.melloinfo_box').animate({
	bottom: '-227'
});
	$('a.navRight, a.navLeft,.funClick').show();
	$('.melloinfo_text').css('height' , '210');
	$('.melloinfo_box').bind('mouseenter', melloinfo_box_enter);
	$('.melloinfo_box').bind('mouseleave',melloinfo_box_leave);

});  

//stile dei pulsanti destra/sinistra al passaggio del mouse
$('a.navRight, a.navLeft').hover(
	 function () {
$(this).animate({
	opacity: '0.9'
});
	 }, 
  function () {
	  $(this).animate({
	opacity: '0.5'
});
  	}
	  );	  
	  
// GESTIONE FUNCLICK (area cliccabile sopra il video - SEZIONE MELLOBLOCCO)
$('.funClick').hover(
  function () {
	//  scurisco un po lo sfondo al passaggio del mouse 
	$('.navbox_close').animate({ 
		opacity: '0.8'
	});
    $(this).animate({
		opacity: '0.4'
		});
  }, 
  function () {
	 // al mouseover nascondo tutto 
	 $('.navbox_close').animate({ 
		opacity: '0'
	});
   $('.funClick').animate({
		opacity: '0'
		});;
  }
);
$('.funClick').click(function(){ 
suonoClick();
if($("#pannello_video").css('display')=="none"){$("#pannello_share").show();}
$('.navbox_close').hide();
//nascondo freccie destra/sinistra
$('a.navRight, a.navLeft').hide();
//chiudo box 
 $('.melloinfo_box').stop(true).animate({
    bottom: '-500'
  }, 500);
//apro menu
$('#menuFooter').stop(true).animate({
    bottom: '0'
  }, 500);
$(this).css('display' , 'none');
});

// MELLOBLOCCO INFO
//pulsante home


$('li.mello').mouseenter(function(){
	$('#SubmenuFooter').show();	
});
$('li.mello').mouseleave(function(){
	$('#SubmenuFooter').hide();	
});

$('li.mello').click(function(){
	$('#SubmenuFooter').hide();	
});
$('li.home').click(function(){ 						
suonoClick();
$("#contentArea").hide().fadeTo("slow", 0);
$('#logoimg').show().fadeTo(400, 1);
$('#subMenuFooter, #subMenuFooter2, #subMenuFooter3').removeClass('visible').hide('fast');
$('li.madre2 a, li.madre3 a, li.madre a, li.madre0 a, li.madre4 a').removeClass('active');
$('li.home a').addClass('active')
	});
$('li.foto').click(function(){
suonoClick();
$("#pannello_share").hide();
$('.navbox_close').show();
$('.funClick, .funkClick_news').css('display' , 'none');
$('.funkClick').css('display' , 'block');
//nascondo menu
$('#carouse2').animate({
    bottom: '0px'
  }, 500);
$('#menuFooter').animate({
    bottom: '-50px'
  }, 500);
$('#mellofoto').show();
// e apro le foto
$('#mellofoto_gallery').show().animate({
    bottom: '99px'
  }, 500);
});

// GESTIONE FUNKCLICK (area cliccabile sopra il video - SEZIONE FOTO)
//setto la larghezza del contader scorrevole delle foto
var fotoBoxContainerCount=$('.fotoBoxContainer img').length;
var fotoBoxContainerWidth=(fotoBoxContainerCount*107)+$('.fotoBoxContainer li').length * 74;//numero di foto x laghezza foto + numero di edizione + margine aggiunto

$('.fotoBoxContainer').css('width',fotoBoxContainerWidth+'px');
$('.funkClick, .navbox_close').hover(
  function () {	
	//  scurisco un po lo sfondo al passaggio del mouse 
	$('.navbox_close').animate({ 
		opacity: '0.8'
	});
    $(this).animate({
		opacity: '0.4'
		});
  }, 
  function () {
	 // al mouseover nascondo tutto 
	 $('.navbox_close').animate({ 
		opacity: '0'
	});
   $('.funClick').animate({
		opacity: '0'
		});;
  }
);
$('.funkClick').click(function(){ 
suonoClick();
if($("#pannello_video").css('display')=="none"){$("#pannello_share").show();}
$('.navbox_close').hide();
//chiudo slide 
 $('#carouse2').animate({
    bottom: '-100px'
  }, 500);
//chiudo box slide
 $('#mellofoto_gallery').animate({
    bottom: '-115px'
  }, 500);
//apro menu
$('#menuFooter').animate({
    bottom: '0'
  }, 500);
// una volta terminati gli slide nascondo tutto
$('#mellofoto').delay(500).hide();
//nascondo FunClick cosi lo puoi riaprire solo cliccando sulla voce del menu   
$('.funkClick').css('display' , 'none');
});

//SEZIONE VIDEO

$('li.video').click(function(){
suonoClick();
$("#pannello_share").hide();
$('.navbox_close').show();
$('.funkClick_news').css('display' , 'none');
$('.funkClick').css('display' , 'none');
$('.funkClick_video').css('display' , 'block');
//nascondo menu
$('#carouse2_v').animate({
    bottom: '0px'
  }, 500);  
$('#menuFooter').animate({
    bottom: '-50px'
  }, 500);
$('#melloVideo').show();
// e apro le foto
$('#mellofoto_gallery_v').show().animate({
    bottom: '99px'
  }, 500);
});

// GESTIONE FUNKCLICK (area cliccabile sopra il video - SEZIONE VIDEO)

$('.funkClick_video, .navbox_close').hover(
  function () {
	//  scurisco un po lo sfondo al passaggio del mouse 
	$('.navbox_close').animate({ 
		opacity: '0.8'
	});
	//  scurisco un po lo sfondo al passaggio del mouse 
    $(this).animate({
		opacity: '0.4'
		});
  }, 
  function () {
	 // al mouseover nascondo tutto 

	$('.navbox_close').animate({ 
		opacity: '0'
	});
   $(this).animate({
		opacity: '0'
		});
  }
);
$('.funkClick_video, .navbox_close').click(function(){ 
suonoClick();
if($("#pannello_video").css('display')=="none"){$("#pannello_share").show();}
$('.navbox_close').hide();
//chiudo box slide
 $('#carouse2_v').animate({
    bottom: '-110px'
  }, 700);
//apro menu
$('#menuFooter').animate({
    bottom: '0'
  }, 500);
// una volta terminati gli slide nascondo tutto
//nascondo FunClick cosi lo puoi riaprire solo cliccando sulla voce del menu   
$('.funkClick_video').css('display' , 'none');
});
// SEZIONE NEWS
$('li.news_mini').click(function(){ 	
suonoClick()
$("#pannello_share").hide();
$('.navbox_close').show();
$('.funkClick_news').css('display' , 'block');
$('.funClick, .funkClick_video').css('display' , 'none');
//nascondo menu
$('#menuFooter').animate({
    bottom: '-50px'
  }, 500);
$('#carouse2_n').animate({
    bottom: '0px'
  }, 500);
}); 

// GESTIONE FUNKCLIC SEZIONE NEW
$('.funkClick_news, .navbox_close').hover(
  function () {
	//  scurisco un po lo sfondo al passaggio del mouse 
	$('.navbox_close').animate({ 
		opacity: '0.8'
	});
    $(this).stop(true).animate({
		opacity: '0.4'
		});
  }, 
  function () {
	 // al mouseover nascondo tutto 
   	$('.navbox_close').animate({ 
		opacity: '0'
     });
   $(this).stop(true).animate({
		opacity: '0'
		});
  }
);
$('.funkClick_news').click(function(){ 
suonoClick()
if($("#pannello_video").css('display')=="none"){$("#pannello_share").show();}
$('.navbox_close').hide();
//chiudo slide 
 $('#carouse2_n').animate({
    bottom: '-120px'
  }, 500);
//apro menu
$('#menuFooter').animate({
    bottom: '0'
  }, 500);
//nascondo FunClick cosi lo puoi riaprire solo cliccando sulla voce del menu   
$('.funkClick_news').css('display' , 'none');
});

//SEZIONE MELLOBLOCCO

$('li.mello').click(function(){ 	
suonoClick()
$("#pannello_share").hide();
$('.navbox_close').show();
$('.funClick').css('display' , 'block');
$('.funkClick, .funkClick_news').css('display' , 'none');
$('#contentArea, #subMenuFooter, #subMenuFooter2').hide();
//visualizzo freccie avanti e indietro
$('a.navRight, a.navLeft').show();
//apro box 
 $('.melloinfo_box').animate({
    bottom: '0px'
  }, 500);
//nascondo menu
$('#menuFooter').animate({
    bottom: '-50px'
  }, 500);
}); 

//SEZIONE CONTATTI

$('li.contatti, li.contatti a, li.iscritti, li.iscritti a').click(function(){
suonoClick()
});

//SEZIONE PANNELLO

$('a.pannello').click(function(){
suonoClick()
$("#pannello_share").hide();
$('#pannello_video').show(); });
$('#enableVideo').click(function(){
                        $.cookie("mellocookie","1", { expires: 10 });//10 giorni 
                        location.reload();
        });
$('#disableVideo').click(function(){
                        $.cookie("mellocookie","0", { expires: 10 });//10 giorni 
                        location.reload();
        });
$('a.closePannello').click(function(){		
suonoClick()
$('#pannello_video').hide();if($("#pannello_video").css('display')=="none"){$("#pannello_share").show();}
});

//*********************     LOAD CONTENT      ***********************************//
  
$('a.items').click(function(){   
								 var id = $(this).attr("href");
								 var total = $('#mellofoto_gallery').find('li').length;
							      $('#mellofoto_gallery').scrollTo( $('ul li.lista' + id) , 800 );
								   });

//*********************     SCROLL      ***********************************//
$(".scrollable").scrollable({ circular: true });
//*********************     CAROUSEL    ***********************************//
$('#carouse2_n').elastislide({
	imageW 	: 340,
	speed : 200,
	minItems	: 1
});
$('#carouse2, #carouse2_v').elastislide({
	imageW 	: 100,
	speed : 200,
	minItems	: 1
});
$('#carouse3').elastislide({
	imageW 	: 100,
	speed : 200,
	minItems	: 1
});
//chisura script
})

