$(window).load(
	function () { 
	$("#loading-img").remove();	
		$('#mask').fadeOut(600); 
	}); 
/* Author: Matteo Galli - Playcode Studio (http://www.playcodestudio.com) */
	function fadeAll(elems) {

		   elems.filter(':hidden:first').fadeIn(300, function() { fadeAll(elems); });
	}
// Funzione click thumb/title-list	
		$(".list a,.list-bookshop, ul#menu-years, .exhibition-artist-name a,.bookshop-prev-next a,.nextpostslink,.previouspostslink,#logo").click(function() {
			$("#mask").fadeIn(650);	
			$("#backstretch").hide();
			

		});	
		
// Funzione zoom	
var collection	=	{

	selectedItem	:	null,
	init					:	function(){
		jQuery('#slideshow-images img').bind({
			'click':	function(event){
				
				event.preventDefault();
				createZoom(jQuery(this).attr('data-bigimage'));
			}
		});

		function createZoom(elem){
			
			if(elem){
		//		var ipadstyle = (all.isOtherDevice()) ? 'height: auto;' : '';

				var ipadstyle = 'height: auto';
				var fullscreen_wrapper = '<div class="zoomed-image-wrapper" style="display: none;'+ipadstyle+'"><img class="zoomed-image" src="'+ elem +'"/><a class="close-zoom" href="javascript:void(0)">X</a></div>';
				jQuery('body').append(fullscreen_wrapper);
		

				jQuery('.zoomed-image-wrapper').fadeIn(300, function(){
					jQuery('.zoomed-image').draggable({
						axis: 'y',
						caller: this,
						scroll: true,
						stop: function(event,ui) {
							if(ui.position.top>0) 
								$(this).animate({top:0},200,'easeOutCubic');
//							else if(Math.abs(ui.position.top)>$(this).height()-$(this).parent().height())
//								$(this).animate({top:-($(this).height()-$(this).parent().height())},200,'easeOutCubic');
							else if(Math.abs(ui.position.top)>($(this).height()-400)-$(this).parent().parent().height())
								//alert($(this).parent().parent().height()+" <> "+$(this).height())
								$(this).animate({top:-($(this).height()-$(this).parent().parent().height()-320)},200,'easeOutCubic');
/*								
							if(ui.position.left>0) 
								$(this).animate({left:0},200,'easeOutCubic');
//							else if(Math.abs(ui.position.top)>$(this).height()-$(this).parent().height())
//								$(this).animate({top:-($(this).height()-$(this).parent().height())},200,'easeOutCubic');
							else if(Math.abs(ui.position.left)>$(this).width()-$(this).parent().parent().width())
								//alert($(this).parent().parent().height()+" <> "+$(this).height())
								$(this).animate({left:-($(this).width()-$(this).parent().parent().width())},200,'easeOutCubic');
	*/							
							}
							
					});
				});
				jQuery('.close-zoom').bind('click',function(event){
					event.preventDefault();
					jQuery('.zoomed-image-wrapper').fadeOut(300, function(){
						jQuery('.close-zoom').unbind('click');
						jQuery(this).remove();
					});
				});
			}
		}
	}
};


$(document).ready(function() {


// mask white
$("ul.menu li a").each(function() { 
		$(this).bind('click',function(event){
			$("#mask").fadeIn(450, function(){
				 loadimage = "http://www.rizzieroarte.com/wp-content/themes/rizzieroarte/img/ajax-loader.gif";
				 $("body").append("<img src='"+loadimage+"' id='loading-img' style='position:absolute;z-index:999999;top:0;left:50%;margin-left:-200px'/>")																			
			});	
		});
		
	});

		$("#logo").bind('click',function(event){
			$("#mask").fadeIn(450, function(){
				 loadimage = "http://www.rizzieroarte.com/wp-content/themes/rizzieroarte/img/ajax-loader.gif";
				 $("body").append("<img src='"+loadimage+"' id='loading-img' style='position:absolute;z-index:999999;top:0;left:50%;margin-left:-200px'/>")																			
			});	
		});


// Elementi definiti al caricamento 
	// $("#white,#main,#main-2").hide();
	$("#container-page-artista h1").css("color","#ffffff")
	$("#bg-top-menu").css("height","50px");
	$("ul.sub-menu").hide();
	$("ul.children").hide();
	$(".facebook").hide();
	$(".twitter").hide();
	$("#lang_sel_list ul li:last-child").hide();


// Apertura/chiusura top menu
	$(document).mousemove(function(e){
		if(e.pageY<=50){
			$("#bg-top-menu").stop().animate({height:120},200);
			$("ul.sub-menu").fadeIn(200);
			$("ul.children").fadeIn(200);
			$(".facebook").fadeIn(200);
			$(".twitter").fadeIn(200);
			$("#lang_sel_list ul li:last-child").fadeIn(200);
		}
		if(e.pageY>145){
			$("#bg-top-menu").stop().animate({height:50},800);
			$("ul.sub-menu").fadeOut(200);
			$("ul.children").fadeIn(200);
			$(".facebook").fadeOut(200);
			$(".twitter").fadeOut(200);
			$("#lang_sel_list ul li:last-child").fadeOut(200);
		}   
	});

// Ottimizza leggibilità del @font-face tramite jQuery								 
	$("body").css("text-rendering","optimizeLegibility");


// Apre i link esterni al sito in blank in automatico
	$("a").filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).attr("target", "_blank");



/////////// PAGINA LOOP-PAGE-ARTISTS.PHP ///////////////

		$(".pp-list").css("display","block").fadeIn(450) 
		//$('#box_title_list li.list-bookshop').hide()
		/*
			setTimeout(function() {
			 fadeAll($('#box_thumb_list div.list, #box_thumb_list a.list-bookshop'));
			 }, 300);
			*/

		// Switch Function
		$('.btn-switch-list').click(function() {
			/*Hide title & Show thumb voice*/
			$(".pp-list").fadeOut(300,function(){
				$(".pp-thumb").css("display","block").fadeIn(300)
			})
			/* Hide thumblist div & Show titlelist div*/
		  $("#box_thumb_list").fadeOut(300,function(){
 		  //$('.track').remove();
			$("#box_title_list").fadeIn(300);
			$('#box_title_list div.list, #box_title_list li.list-bookshop').fadeIn(300,function(){$('.scroll-pane-titlelist').jScrollPane();});			
			
			/*
				setTimeout(function() {
			 	fadeAll($('#box_title_list div.list, #box_title_list li.list-bookshop'));
			}, 300); 
				*/
		 })
		});
		$('.btn-switch-thumb').click(function() {
			/*Hide thumb & Show title voice*/															 
			$(".pp-thumb").fadeOut(300,function(){
				$(".pp-list").css("display","block").fadeIn(300)
			})
			/* Hide titlelis div & Show thumblist div*/			
		 $("#box_title_list").fadeOut(300,function(){
		 //$('.track').remove();
		 $("#box_thumb_list").fadeIn(300)
		 
	  	
		 /*
			setTimeout(function() {
			 fadeAll($('#box_thumb_list div.list,#box_thumb_list a.list-bookshop'));
			}, 300);
			*/
		 }) 
		});
////////////////////////////////////////////////////////


/////////// PAGINA SENGLE-ARTIST.PHP ///////////////

		$("#container-page-artista h1, #menu-artista").fadeIn(650);

		this_box = "box_back";
		////////////////////////////////////
		// Funzione Menu Artista
		////////////////////////////////////
		$("#menu-artista a").click(function() {
																				
																				
			var ua = window.navigator.userAgent
      var msie = ua.indexOf("MSIE")
			if ( msie > 0 )  {
					$f("*").each(function() {
						this.stop();
					});
			}else{
			 if ($('.work-video').is(':visible')){
				 $(".work-video video").each(function() { 
																							
					  this.video = $(this);
					  var myPlayer1 = VideoJS.setup(this);	
					  myPlayer1.pause();
				});
				 
				 }				 
			 }


			
			id_option = $(this).attr('href').substring(1,$(this).attr('href').lenght);			
			click_box = "box_"+id_option;
			
			//alert(click_box + " this:" + this_box)
			
			if(click_box!="box-works"){
					$("#box_works_dett").hide();
			}
			if(click_box!="box-video"){
					$("#box_video_dett").hide();
			}

			if ($(this).attr('href').substring(0,1)!="#"){
				$("#mask").fadeIn(650);			
			}else{
				
				if(this_box!=click_box){
					$("#triquibackimg").fadeOut(450);
					$("#"+this_box).stop().fadeOut(250,function(){
						// fade in del box
						$("#container-page-artista h1").css("color","#cccccc")
						$("#"+click_box).stop().fadeIn(250,function(){
																																				
							switch (id_option) {
								case "works":
										collection.init();

									break;
								case "video":
										//collection.init();
									break;
								case "bio":
										$('.scroll-pane-testobio').jScrollPane();
									break;
								case "exhibitions":
										$('.scroll-pane-exhibitions').jScrollPane();	
									break;
								case "other_exhibitions":
									break;
								case "catalogues":
										$('.scroll-pane-catalogues').jScrollPane();	
									break;
								case "press":
										$('.scroll-pane-press').jScrollPane();	
									break;
								case "back":
										//call apertura back							
										open_back();
										break;
								}
							
								this_box = click_box;
						});																		 
					})
				}else{
					
						if ((click_box == "box_works")&&(this_box == "box_works")){
							$("#box_works_dett").stop().fadeOut(250,function(){
								$("#"+click_box).stop().fadeIn(250);
																															 
							});
																													
						}
						if ((click_box == "box_video")&&(this_box == "box_video")){
							$("#box_works_dett").stop().fadeOut(250,function(){
								$("#"+click_box).stop().fadeIn(250);
																															 
							});
																													
						}

					}
					
				}
		});	
		// apre la bio		
		function open_bio(){
			$('#box-bio img').fadeIn(350,function(){
						$('#box-bio div').fadeIn(350);																			
			});

		}
		// apre back
		function open_back(){
			$("#container-page-artista h1").css("color","#ffffff")
			$("#triquibackimg").fadeIn(450);
			$("#box_works_dett, #box_video_dett").fadeOut(300);
		}
		
		
		/////////////////////////////////////
		// Funzione apertura Dettaglio Opere
		/////////////////////////////////////
		$("#box_works .multimedia-portfolio-images li div").click(function(){
			id = $(this).attr('id');
			get_work_dett_images(id)
		})

		/////////////////////////////////////
		// Funzione apertura Dettaglio Video
		/////////////////////////////////////
		$("#box_video .multimedia-portfolio-video li div").click(function(){
			id = $(this).attr('id');
			get_work_dett_video(id)
		})
		/////////////////////////////////////
		// Funzione apertura Dettaglio Altre mostre
		/////////////////////////////////////
		$("#box_other_exhibitions .multimedia-portfolio-other li div").click(function(){
			id = $(this).attr('id');
			get_work_dett_other(id)
		})


		function get_work_dett_images(id){
			$("#box_works").fadeOut(250,function(){
				$("#box_works_dett").fadeIn(450);
				
				$('#slideshow-images').cycle({
						fx:      'fade',
						speed:   300, 
						timeout:  0,
						prev:    '#prev',
						next:    '#next',
						backwards: true,
						startingSlide: id,
		
				});	
				
			});
		}		
		function get_work_dett_video(id){
			$("#box_video").fadeOut(250,function(){
				$("#box_video_dett").fadeIn(450);
				
				$('#slideshow-video').cycle({
						fx:      'fade',
						speed:   300, 
						timeout:  0,
						prev:    '#prev-video',
						next:    '#next-video',
						backwards: true,
						startingSlide: id,
		
				});	
				
			});
		}	
		
		
		
		$("#prev-video, #next-video").click(function() {
	  	// passare l'ID dell'elemento video o un array di elementi
			var ua = window.navigator.userAgent
      var msie = ua.indexOf("MSIE")
			if ( msie > 0 )  {
				
				//flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.6.swf");
				$f("*").each(function() {
					this.pause();
				});
			}else{
				if ($('.work-video').is(':visible')){	
					$(".work-video video").each(function() { 
						this.video = $(this);
						var myPlayer1 = VideoJS.setup(this);	
						myPlayer1.pause();
					});
				}				 
			}
		});	

/////////// PAGINA PAGE-EXHIBITIONS-PAST.PHP ///////////////


		this_box_ex = "box_works_exhibition";
		///////////////////////////
		// Funzione Menu Exhibition
		///////////////////////////
		$("#menu-exhibitions a").click(function() {
			
			id_option_ex = $(this).attr('href').substring(1,$(this).attr('href').lenght);			
			click_box_ex = "box_"+id_option_ex + "_exhibition";
			if(click_box_ex!="box_works_exhibition"){
					$("#box_works_dett_exhibition").hide();
			}
			//Se clicco btn-back o moreabout non parte la funzione
			if($(this).attr('class')=='btn-back' || $(this).attr('class')=='more')	{
				// no fa niente
			}else{
				// Funzione che nasconde e fa apparire i diversi box
				if(this_box_ex!=click_box_ex){
					// Nasconde il box aperto
					$("#"+this_box_ex).fadeOut(300,function(){
						// Visualizza il box						
						$("#"+click_box_ex).fadeIn(500,function(){
																																				
							switch (id_option_ex) {
								case "back":
										//call apertura back							
											open_back_ex();
										break;
								}
							
							this_box_ex = click_box_ex;
						});																		 
					})
				}else{
							if ((click_box_ex == "box_works_exhibition")&&(this_box_ex == "box_works_exhibition")){
							$("#box_works_dett_exhibition").stop().fadeOut(250,function(){
								$("#"+click_box_ex).stop().fadeIn(250);
																															 
							});
																													
						}				
				
				}
			}
		});	
		// apre back
		function open_back_ex(){
			
			$("#box_works_dett_exhibition").fadeOut(300);
		}
		
		
		/////////////////////////////////////
		// Funzione apertura Dettaglio Opere
		/////////////////////////////////////
		$("#box_works_exhibition .multimedia-portfolio-images li div").click(function(){
			id = $(this).attr('id');
			get_work_dett_exhibition_images(id)
		})


		function get_work_dett_exhibition_images(id){
			$("#box_works_exhibition").fadeOut(250,function(){
				$("#box_works_dett_exhibition").fadeIn(450);
				
				$('#slideshow-images').cycle({
						fx:      'fade',
						speed:   300, 
						timeout:  0,
						prev:    '#prev',
						next:    '#next',
						backwards: true,
						startingSlide: id,
		
				});	
				
			});
		}		

/////////// PAGINA PAGE-GALLERY-HISTORY.PHP ///////////////


		this_box_gh = "box_about_history";
		/////////////////////////
		// Funzione Menu History
		/////////////////////////
		$("#menu-history a").click(function() {
			
			id_option_gh = $(this).attr('href').substring(1,$(this).attr('href').lenght);			
			click_box_gh = "box_" + id_option_gh + "_history";
			if(click_box_gh != "box_image_history"){
					$("#box_image_history_dett").hide();
			}
				// Funzione che nasconde e fa apparire i diversi box
				if(this_box_gh != click_box_gh){
					// Nasconde il box aperto
					$("#"+this_box_gh).fadeOut(300,function(){
						// Visualizza il box						
						$("#"+click_box_gh).fadeIn(500,function(){
							this_box_gh = click_box_gh;
						});																		 
					})
				}
		});	

		
		
		////////////////////////////////////////
		// Funzione apertura Dettaglio Immagini
		////////////////////////////////////////
		$("#box_image_history .multimedia-portfolio-images li div").click(function(){
			id = $(this).attr('id');
			get_image_dett_history_images(id)
		})


		function get_image_dett_history_images(id){
			$("#box_image_history").fadeOut(250,function(){
				$("#box_image_history_dett").fadeIn(450);
				
				$('#slideshow-images').cycle({
						fx:           'fade',
						speed:         300, 
						timeout:       0,
						prev:         '#prev',
						next:         '#next',
						backwards:     true,
						startingSlide: id,
		
				});	
				
			});
		}		

/////////// PAGINA CONTACT ///////////////

		this_box_ct = "box_info_contacts";
		//////////////////////////
		// Funzione Menu Contatti
		//////////////////////////
		$("#menu-contacts a").click(function() {
																						 			
			$("#googlemap").remove();	
			
			id_option_ct = $(this).attr('href').substring(1,$(this).attr('href').lenght);			
			click_box_ct = "box_" + id_option_ct + "_contacts";
			
			
				// Funzione che nasconde e fa apparire i diversi box
				if(this_box_ct != click_box_ct){
					// Nasconde il box aperto
					$("#"+this_box_ct).fadeOut(300,function(){
						// Visualizza il box						
						$("#"+click_box_ct).fadeIn(500,function(){

							switch (id_option_ct) {
								case "map":
										
										$("<iframe width='960' height='380' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?q=rizziero+arte+pescara&amp;hl=en&amp;sll=37.0625,-95.677068&amp;sspn=56.331468,81.914062&amp;vpsrc=6&amp;hq=rizziero+arte&amp;hnear=Pescara+Province+of+Pescara,+Abruzzi,+Italy&amp;t=m&amp;ie=UTF8&amp;cid=7679898160662579652&amp;ll=42.483808,14.21133&amp;spn=0.024053,0.082312&amp;z=14&amp;iwloc=A&amp;output=embed'></iframe>").fadeIn(250).appendTo('#box_map_contacts');
										

									break;
								}



							this_box_ct = click_box_ct;
						});																		 
					})
				}
		});	



////////////////////////////////////////////////////

});
