/**
 * @author batdam
 */
$(document).ready(
	function() {
		
		
		// geocoding

		
		// apro e chiudo la stripe delle mostre
		$('.mostre_arrow').click(
			function() {
				//$('#stripe').toggle("slide", { direction: "down" }, 1000, function() {
				$('#stripe').slideToggle(500, function() {
					if($('#stripe:visible').length>0) {
						$('.mostre_arrow').addClass(
							function() {
								if($('#stripe .wrapper').length==0) {
									var which_mostra = $('.which_mostra').val();
									var which_lang = $('.which_lang').val();
									var predir = (which_mostra=="" ? "" : "../")
									var prepredir = (which_mostra=="" ? "" : (which_lang == "en" ? "../" : ""));
									$.ajax({
									  url: prepredir + predir + "s_inc/stripe.php",
									  dataType: "html",
									  data: {
										  'which_mostra': which_mostra,
										  'which_lang': which_lang
									  },
									  success: function(data) {
									    $('#stripe').html(data);
									  }
									});
								}
								return 'mostre_arrow_off';
							}
						);
					}
					else {
						$('.mostre_arrow').removeClass(
							function() {
								return 'mostre_arrow_off';
							}
						);
					}
				});
				return false;
			}
		);
		
		// apro e chiudo la stripe della artmap
		$('.artmap_arrow').click(
			function() {
				$('.stripe_artmap').slideToggle(500, function() {
				//$('.stripe_artmap').toggle(500, function() {
					if($('.stripe_artmap:visible').length>0) {
						$('.artmap_arrow').addClass(
							function() {
								if($('.stripe_artmap .wrapper').length==0) {
									$.ajax({
									  url: "../s_inc/stripe_artmap.php",
									  dataType: "html",
									  data: {
									  },
									  success: function(data) {
									    $('.stripe_artmap').html(data);
									  }
									});
								}
								return 'mostre_arrow_off';
							}
						);
					}
					else {
						$('.artmap_arrow').removeClass(
							function() {
								return 'mostre_arrow_off';
							}
						);
					}
				});
				return false;
			}
		);
		$('.artmap_arrow').trigger('click');
		

		// apro e chiudo la login stripe
		$('.login_login_slide a').click(
				function() {
					$('.login_stripe').slideToggle();
					return false;
				}
		);


		// apro il layer sulcopyright
		$('.footer_copy').click(
			function(){
				if($('#copy_box').is(':visible')) {
					$('#copy_box').fadeOut();
				}
				else {
					$('#copy_box').fadeIn();	
				}
				return false;
			}
		);

		$('#copy_box').mouseleave(
			function(){
				$(this).fadeOut();
			}
		);







		
		// home specific
				
		$('#sblog').rssfeed(
			'http://www.lineadombra.it/blog/feed',
			{
				limit: 1,
				header: true,
				snippet: false
			}
		);
		
		$('.nav:gt(0)').hover(
			
			function() {
				var $index = $(this).index();

				$('.nav:eq(0) .nav_off').show();
				$('.nav:eq(0) .nav_on').hide();

				$(this).find('.nav_off').hide();
				$(this).find('.nav_on').show();
				
				$('#main').addClass($(this).attr("rel"));

				$('#banner_swapper img.thisopen').stop(true, true).fadeOut(1000).removeClass("thisopen");
				$('#banner_swapper img:eq('+$index+')').stop(true, true).fadeIn(1000).addClass("thisopen");

			},
			function() {
				var $index = $(this).index();

				$('.nav:eq(0) .nav_off').hide();
				$('.nav:eq(0) .nav_on').show();

				$(this).find('.nav_off').show();
				$(this).find('.nav_on').hide();
				
				$('#main').removeClass();

				$('#banner_swapper img.thisopen').stop(true, true).fadeOut(1000).removeClass("thisopen");
				$('#banner_swapper img:eq(0)').stop(true, true).fadeIn(1000).addClass("thisopen");

			}
			
		);
		
		
		$('#top_menu_mostre').click(
			function() {
				
				return false;
			}
		);




		// inner

		
		if($('#opera_inner').length>0) {
			$('#opera_inner').cycle({
				fx: 'scrollHorz',
				prev: '#opera_prev',
				next: '#opera_next',
				timeout: 0
			});
		}
		
		
		if($('#sede_wrapper').length>0) {
  		$('#sede_wrapper').cycle({
  			fx: 'scrollHorz',
  			pager: '#sede_nav',
  			activePagerClass: 'circle_active',
  			slideExpr: '.sede_pic',			
  			prev: '#sede_prev',
  			next: '#sede_next',
  			// callback fn that creates a thumbnail to use as pager anchor 
  	    pagerAnchorBuilder: function(idx, slide) { 
  	       return '<a href="#" class="circle"><img src="../img/circle-base.png"></a>'; 
  	    }
  		});
		}
		
		
		
		// mostro la didascalia cliccando sulla i
		$('.tools_info').mouseenter(
			function() {
				$(this).closest('.opera_box').find('.opera_info').show("slide", {direction: 'down'});	
				return false;
			}
		);		
		$('.tools_info').mouseout(
			function() {
				$(this).closest('.opera_box').find('.opera_info:visible').hide("slide", {direction: 'down'});	
				return false;
			}
		);		
		$('.tools_info').click(
				function() {
					return false;
				}
			);		

		
		
		
		
		
		
		
		
		
		
		
		
		
		// mostro la didascalia sull'hover
		/*
		$('.opera_pic img').hover(
			function() {
				$(this).next('.opera_info').show("slide", {direction: 'down'});	
			},
			function() {
				$(this).next('.opera_info').hide("slide", {direction: 'down'});
			}
		);
		*/		
		

		
		
		
		
		
		
		
		
		// passo alla modalità zoom cliccando sulla lente
		$('.tools_lente').click(
			function() {
				var href = $(this).attr("href");
				var mypath = '../';
				if($('#hiddenlang').length>0) {
					var mypath = '../../';
				}
				$.ajax(
					{
						url: mypath + 'ajax_lente.php',
						data: { 'href': href },
						method: 'get',
						success: function(html) {
							$('#opera_inner').append('<div class="coprotutto">'+html+'</div>');
							$('#interno_contenuto .wrapper:first').append('<a href="" id="chiudi_zoom">chiudi lo zoom</a>');
							
							$('.opera_big').jqzoom({
								alwaysOn: true,
								title: false,
								preloadText: 'Caricamento in corso',
								zoomWidth: 980,
								zoomHeight: 572
							});
							
							$('#chiudi_zoom').click(
								function() {
									$('.coprotutto').remove();
									$(this).remove();
									return false;
								}
							);
							
						}
					}
				);
				return false;
			}
		);
		
		
		// leggo l'interno contenuto in pagina principale
		$('.leggidipiu').click(
			function() {
				$(this).closest('.p').find('.hidden').slideToggle();
				$(this).hide();
				return false;
			}			
		);
		
		
		$('.info_opener a').click(
			function() {
				var corpo = $(this).closest('.info_opener').next('.info_corpo');
				if (corpo.is(':visible')) {
					$(this).removeClass('down');
				}
				else {
					$(this).addClass('down');
				}
				corpo.slideToggle();
				return false;
			}
		);
		
		
		// audioguide rollover
		$('.audioguida a').hover(
			function() {
				$(this).find('.mask').show();
			},
			function() {
				$(this).find('.mask').hide();
			}
		);		
		
		
		// margine sul primo elemento degli sponsor
		$('.sponsor_block').each(
			function() {
				$(this).find('.sponsor:first').css("margin-left", "30px");		
			}
		);
		
		
		// tab turismo
		$('.turismo_tabs a').click(
				function() {
					$('.turismo_tabs a').removeClass('tab_sel');
					$(this).addClass('tab_sel');
					$('.turismo_box').hide();
					$('#box_' + $(this).attr("id")).show();
					return false;
				}
		);


		// tab turismo
		$('.turismo_riga').hover(
				function() {
					$(this).addClass('turismo_riga_sel');
					$(this).prev().addClass('turismo_chiuso_up');
				},
				function() {
					$('.turismo_riga').removeClass('turismo_riga_sel');
					$(this).prev().removeClass('turismo_chiuso_up');
				}
		);
		
		
		// apri tab turismo
		$('.block_leggitutto').click(
				function () {
					//$('.riga_hidden').hide();
					$(this).prev('.turismo_riga_collapse').find('.riga_hidden').slideToggle(500);
					$(this).find('.span_leggi').toggle();
					$(this).find('.span_chiudi').toggle();
					$(this).prev('.turismo_riga_collapse').find('.puntini').toggle();
					$(this).prev('.turismo_riga_collapse').find('.puntini_post').toggle();
					return false;
				}
		);



		// tab approfondimento genova
		$('.approfondimenti_tabs a').click(
				function() {
					if(!$(this).hasClass('tab_sel')) {
						$('#turismo_tabs a').removeClass('tab_sel');
						$(this).addClass('tab_sel');
						$('.turismo_box').hide();
						$('#box_' + $(this).attr("id")).show();
						$('#sala_virtuale img:visible').fadeOut();
						$('#img_' + $(this).attr("id")).fadeIn();
					}
					return false;
				}
		);
		
		
		// turismo fancybox
		if($('.block_foto').length>0) $('.block_foto').fancybox();
		
		
		// carousel nella stripe
		
		
		// audioguide fancybox
		if($('.audioguida a').length>0 || $('.audioguida_intro a').length>0) {
			$('.audioguida a, .audioguida_intro a').fancybox();
		}
		
		
		// virtualtour opne in new window
		$('#virtualtour a, .lanci_box .popup').click(
				function() {
					window.open($(this).attr("href"), "virtualtour", "width=850, height=500");
					return false;
				}
		);



	}
);


Cufon.replace('.cufon, #poster');
