

$(document).ready(function() {

	//area suoni
	var myPlaylist = new jPlayerPlaylist({
		jPlayer: "#jquery_jplayer_1",
		cssSelectorAncestor: "#jp_container_1"
	}, [
		{
			title:"Ruscello",
			//free: true,
			mp3:"audio/mp3/Ruscello_e_Uccelli.mp3",
			oga:"audio/ogg/Ruscello_e_Uccelli.ogg"

		},
		{
			title:"Oceano",
			//free: true,
			mp3:"audio/mp3/Oceano.mp3",
			oga:"audio/ogg/Oceano.ogg"
		},
		{
			title:"Onde",
			//free: true,
			mp3:"audio/mp3/Onde_del_Mare.mp3",
			oga:"audio/ogg/Onde_del_Mare.ogg"
		}
	], {
		playlistOptions: {
			autoPlay: true,
			enableRemoveControls: false
		},
		swfPath: "js",
		supplied: "oga, mp3",
		wmode: "window"

	});
	

//fine area suoni






var HalfScreen = $(window).width()/2;
var OffsetScroll = HalfScreen - 424; 
						   
function all_mini_gallery_start(){
				$('.scroll_box .content').cycle({
					fx:    'fade', 
					timeout: 1500,
					speed:  1000, 
					cleartype: true, 
					cleartypeNoBg: true
				});
}
function all_mini_gallery_pause(){
		$('.scroll_box .content').cycle('pause');
}


function mini_gallery_pause(){
			$('.opened .content').cycle(0)
			$('.opened .content').cycle('pause');
}

function mini_gallery_resume(){
			$('.opened .content').cycle('resume');
}

function on_start(){
			var PHtarget;
			$('#2').addClass('openedIcon');
			$('#sez2').addClass('opened');
			$(".openedIcon").css("font-weight","bold");	
			mini_gallery_resume();
			$('body .description').css({display: 'none'});
						
			PHtarget = ($('.opened').position().left);				
			$('.opened').animate({width : '848px'}, 600, 'easeInOutQuart', function() {
				
				$("#scroller").animate({scrollLeft: PHtarget-OffsetScroll}, {duration: 600, specialEasing: {width: 'easeInOutQuart'}});
				$('.opened .description').fadeIn('medium', function() {
				})
			});

}
						   
all_mini_gallery_start();
all_mini_gallery_pause();
on_start();

$(".bgThumb a[rel^='prettyPhoto']").prettyPhoto({theme: 'facebook',hideflash: true, social_tools: false/*,slideshow:5000, autoplay_slideshow:true*/});
//$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'standard'});


//CHINAN ACCORDION SCROLLER


$('.scroll_box').click(function() {
								
		var PHtarget;
	
		if($(this).hasClass('opened') == false) {
			//console.log(this.id);

			$("#"+this.id.substring(3)).addClass('CheckedBoxIcon');
			//console.log(this.id.substring(3));
			//console.log($('.CheckedBoxIcon').attr('id'));
			$(".openedIcon").css("font-weight","normal");
			$('.openedIcon').removeClass('openedIcon');
			$('.CheckedBoxIcon').addClass('openedIcon');
			srcIcon = $('.openedIcon img').attr("src");
			//console.log('.openedIcon'.id);
			$(".openedIcon").css("font-weight","bold");


			$(this).addClass('CheckedBox');
			PHtarget = ($('.CheckedBox').position().left);				

			$('.opened').animate({width : '460px'}, 600, 'easeInOutQuart', function() {
				PHtarget = ($('.CheckedBox').position().left);				
				//console.log(PHtarget);
			});
			mini_gallery_pause();
				
			
			//$(".opened #nav1").text("");
			
			$('.opened').removeClass('opened');
			$('.CheckedBox').addClass('opened');
			mini_gallery_resume();

			//$('body .control_inside').css({display: 'none'});
			$('body .description').css({display: 'none'});
						
			$('.opened').animate({width : '848px'}, 600, 'easeInOutQuart', function() {
				
				$("#scroller").animate({scrollLeft: PHtarget-OffsetScroll}, {duration: 600, specialEasing: {width: 'easeInOutQuart'}});
				$('.opened .description').fadeIn('medium', function() {
				//$('.opened .control_inside').fadeIn('medium');
				
				$('.CheckedBox').removeClass('CheckedBox');
				$('.CheckedBoxIcon').removeClass('CheckedBoxIcon');
			})
		});
		
		

	
		//console.log($('.opened').children('.sottoSezioni'));
		//$('.opened ').children('.sottoSezioni').cycle({ 
/*														
		$('.opened .sottoSezioni').cycle({ 
			fx:     'scrollVert', 
			speed:  1000,
			timeout:     0,
			pauseOnPagerHover: true,
			pause: true,
			pager:  '#nav1',
			
			//callback fn that creates a thumbnail to use as pager anchor 
			pagerAnchorBuilder: function(idx, slide) {
			  //var img = document.getElementById("img"+idx).value;
			  var tit = $('#img_' + idx).attr('title');
			  //return '<img src="' + img + '" width="15" height="15" border="0" title="' + tit + '"  style="display:block; margin:3px 0" /> ';
			  //return '<div title="' + tit + '" style="display:block; margin:3px 0"></div>';
			  return '<div></div>'; 
			}
			
			
		});
*/		
		//$('.opened .description').cycle();
		
//				$('.opened .descriptions .description').cycle({
//					fx:     'scrollVert',
//					speed:  'slow',
//					timeout: 0,
//					prev:   $('.opened .prev_inside', this.parentNode),
//					next:   $('.opened .next_inside', this.parentNode),
//					//after: onAfter,
//					nowrap:  0,
//					pager:  $('.opened .nav', this.parentNode),
//					pagerAnchorBuilder: function(idx, slide) {
//					  //var img = $(slide).eq(0).attr("src");
//					  return '<div>uee</div>';
//					  //var img = document.getElementById("img"+idx).value;
//					 // return '<img src="' + img + '" width="58" height="55" border="0" />';
//					}
//		});

	//console.log(this.id);
    $('.opened #mycarousel_' + this.id).jcarousel({
        vertical: true,
        scroll: 1
    });
			
	// Caption Immagini Numero
				
//	function onAfter(curr,next,opts) {
//				var msg = (opts.currSlide + 1) + ' / ' + opts.slideCount;
//				$('.opened .control_inside .caption').html(msg);
//				return false;
//	};

// END CHINAN ACCORDION SCROLLABLE
	

//$('.opened').children('.control_inside').children('.magnify_inside').cycle({
//					timeout: 0,
//					prev:   '.prev_inside',
//					next:   '.next_inside',
//					nowrap:  1
//				});
};


		
	// FancyBox - Images
	
//$('.opened').children('.control_inside').children('.magnify_inside').children('a').fancybox({
//		'transitionIn'	:	'fade',
//		'transitionOut'	:	'fade',
//		'speedIn'		:	400, 
//		'speedOut'		:	300, 
//		'overlayShow'	:	true,
//		'padding' : 0,
//		'overlayOpacity':	0.9,
//		'overlayColor' : '#000',
//		'hideOnContentClick' : false
//	});

	});




$('#navIcone a').click(function() {
								
		var PHtarget;
		//console.log(this.id);
		if($("#sez"+this.id).hasClass('opened') == false) {
			
			
			//$("#sez"+this.id).hasClass('opened')
			//console.log(this.id);
			
			$(this).addClass('CheckedBoxIcon');
			$(".openedIcon").css("font-weight","normal");
			$(".openedIcon").removeClass("openedIcon");
			$('.CheckedBoxIcon').addClass('openedIcon');
//			srcIcon = ($('.openedIcon img').attr("src"));
//			srcIcon = srcIcon.substring(0,srcIcon.lastIndexOf("_"));
//			srcIcon = srcIcon+"_on.png";
//			$(".openedIcon img").attr({ 
//			  src: srcIcon
//			});
			
			$("#sez"+this.id).addClass('CheckedBox');
			PHtarget = ($('.CheckedBox').position().left);				


			$('.opened').animate({width : '460px'}, 600, 'easeInOutQuart', function() {
				PHtarget = ($('.CheckedBox').position().left);				
				//console.log(PHtarget);
			});
			mini_gallery_pause();

			
			//$(".opened #nav1").text("");
			
			$('.opened').removeClass('opened');
			$('.CheckedBox').addClass('opened');
			mini_gallery_resume();

			//$('body .control_inside').css({display: 'none'});
			$('body .description').css({display: 'none'});
						
			$('.opened').animate({width : '848px'}, 600, 'easeInOutQuart', function() {
				
				
				$("#scroller").animate({scrollLeft: PHtarget-OffsetScroll}, {duration: 600, specialEasing: {width: 'easeInOutQuart'}});
				$('.opened .description').fadeIn('medium', function() {
				//$('.opened .control_inside').fadeIn('medium');
				
				$('.CheckedBox').removeClass('CheckedBox');
				$('.CheckedBoxIcon').removeClass('CheckedBoxIcon');
			})
		});
			
		//console.log($('.opened').children('.sottoSezioni'));
		//$('.opened ').children('.sottoSezioni').cycle({ 
/*														
		$('.opened .sottoSezioni').cycle({ 
			fx:     'scrollVert', 
			speed:  1000,
			timeout:     0,
			pauseOnPagerHover: true,
			pause: true,
			pager:  '#nav1',
			
			//callback fn that creates a thumbnail to use as pager anchor 
			pagerAnchorBuilder: function(idx, slide) {
			  //var img = document.getElementById("img"+idx).value;
			  var tit = $('#img_' + idx).attr('title');
			  //return '<img src="' + img + '" width="15" height="15" border="0" title="' + tit + '"  style="display:block; margin:3px 0" /> ';
			  //return '<div title="' + tit + '" style="display:block; margin:3px 0"></div>';
			  return '<div></div>'; 
			}
			
			
		});
*/		
/*
				$('.opened').children('.descriptions').cycle({
					fx:     'scrollHorz',
					speed:  'slow',
					timeout: 0,
//					prev:   $('.opened .prev_inside', this.parentNode),
//					next:   $('.opened .next_inside', this.parentNode),
					//after: onAfter,
					nowrap:  1,
					pager:  $('.opened .nav', this.parentNode),
					pagerAnchorBuilder: function(idx, slide) {
					  //var img = $(slide).eq(0).attr("src");
					  return '<div>uee</div>';
					  //var img = document.getElementById("img"+idx).value;
					 // return '<img src="' + img + '" width="58" height="55" border="0" />';
					}
		});
*/				
	//console.log(this.id);
    $('.opened #mycarousel_sez' + this.id).jcarousel({
        vertical: true,
        scroll: 1
    });
				
				
	};//fine if


});



	$('#navIcone a').mouseover(function() {
										

			$(this).addClass('CheckedBoxIconOver');
			
			
				
				
		if($("#sez"+this.id).hasClass('opened') == false) {
				//console.log(".CheckedBoxIcon img");
				$(".CheckedBoxIconOver").css("font-weight","bold");


				//console.log(PHtarget);
				
			
		};

	});

$('#navIcone a').mouseout(function() {
		var srcIcon;
			
		
		if($("#sez"+this.id).hasClass('opened') == false) {
				$("#"+this.id).css("font-weight","normal");
		};
		$('.CheckedBoxIconOver').removeClass('CheckedBoxIconOver');

	});







});

/**
 * jQuery.fullBg
 * Version 1.0
 * Copyright (c) 2010 c.bavota - http://bavotasan.com
 * Dual licensed under MIT and GPL.
 * Date: 02/23/2010
**/
(function($) {
  $.fn.fullBg = function(){
    var bgImg = $(this);		
 
    function resizeImg() {
      var imgwidth = bgImg.width();
      var imgheight = bgImg.height();
 
      var winwidth = $(window).width();
      var winheight = $(window).height();
 
      var widthratio = winwidth / imgwidth;
      var heightratio = winheight / imgheight;
 
      var widthdiff = heightratio * imgwidth;
      var heightdiff = widthratio * imgheight;
 
      if(heightdiff>winheight) {
        bgImg.css({
          width: winwidth+'px',
          height: heightdiff+'px'
        });
      } else {
        bgImg.css({
          width: widthdiff+'px',
          height: winheight+'px'
        });		
      }
    } 
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})(jQuery)


$(window).load(function() {
	$("#background").fullBg();
});
