// JavaScript Document




jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle', height: 'toggle'}, 500, 'jswing', callback);  
};

var imgVisualizzata=0;
var videoVisualizzato=0;
var prodottoVisualizzato=0;

var xmouse = 0;
var ymouse = 0;

var inChiusura=false;
var inApertura=false;





//MENU LATERALE
function menuLaterale(){
	
	if(navigator.appName == "Microsoft Internet Explorer"){ 
		$('#contMenuDx').show();
	}else{
		$('#contMenuDx').slideFadeToggle('slow');
	
	}
	
	
	$('#menuDx li a').click(function(){					 
		
		
		
		
		var arrowTop = $(this).attr('top');
		var titleSub = $(this).text();
		var url = $(this).attr('url');
		var ultoopen = $(this).attr('toopen');
		
		
		$('#contSubmenuDx a h1').text(titleSub);
		$('#contSubmenuDx a:first').attr("href",url);
		
		
		
		if(navigator.appName == "Microsoft Internet Explorer"){ 
			
		}else{
			Cufon.refresh();
		}
		
		
		
		
		$('ul#submenuDx div').hide();
		
		$('.'+ultoopen ,'ul#submenuDx').show();
		
		
		
		$('#contSubmenuDx .arrow').stop().animate({ top:arrowTop});
		
		if($('#contSubmenuDx').hasClass('close') && inChiusura==false){
			
			
			
			$('#contSubmenuDx').removeClass('close');
			$('#contSubmenuDx').addClass('open');
			
			
			inApertura=true;
			
			
			if(navigator.appName == "Microsoft Internet Explorer"){ 
				$('#contSubmenuDx').css({'width':'288px', 'right':'340'}).show();
				inApertura=false;
			}else{
				$('#contSubmenuDx').stop().animate({
					opacity: 100, 
					width:288, 
					width: 'toggle', 
					right: 340
					}, 500, 'jswing', function(){
					inApertura=false;
																														   
				});
			}
			
		}
	});
	
	$('#content .center').mousemove(function(e){
		
		
		
		var xmouse = e.pageX - this.offsetLeft;
		var ymouse = e.pageY - this.offsetTop;
	
		if($('#contSubmenuDx').hasClass('open') &&  inApertura==false){
		
			if((xmouse>=1190) || (xmouse<=600) || (ymouse>=670)){
				
				//Chiudo
				
				$('#contSubmenuDx').removeClass('open')
					$('#contSubmenuDx').addClass('close');
					
				inChiusura=true;
				
				if(navigator.appName == "Microsoft Internet Explorer"){ 
					$('#contSubmenuDx').css({'right':'325'}).hide();
					inChiusura=false;
				}else{
					$('#contSubmenuDx').stop().animate({ 
						opacity:0, 
						width:288, 
						width: 'toggle', 
						right: 325
						}, 500, 'jswing', function(){
							
						inChiusura=false;
							
						$('.arrow', this).stop().animate({ top:0});
						
					});
				}
				
			}
		}
	});

}


//ALTEZZE
function changeH(){
	$('.load-content').height($('#contSlider').height()+$('.contSlider').height()+$('.container').height());
	
	$('#wrapper').height($('#content').height());
	$('#contMenuDx').height($('#wrapper').height());
	$('#contSubmenuDx').height($('#wrapper').height());
	
	$('#footer').height($(window).height() - $('#wrapper').height());
	$('#footer').css("background-color","black");
	
	
}



//GALLERY
function nivoGallery(){
	
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:30,
		autoStart:true,
		animSpeed:500, //Slide transition speed
		pauseTime:4000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8 //Universal caption opacity
	});
}


//RESIZE IMG
function resizeImg() {
	var iWidth = 0;
	var iHeight = 0;
	iWidth = $('#fsImage').width();
	iHeight = $('#fsImage').height();
	
	if(parseInt(iWidth) > parseInt(iHeight)) {
		$('#fsImage').css("width", $(window).width());
		$('#fsImage').css("height", 'auto');
	}
	else {
		$('#fsImage').height($(window).height()-100);
		$('#fsImage').css("width", 'auto');
	}
	
	var newWidth = $('#fsImage').width();
	var newHeight = $('#fsImage').height();
	
	$('#fsImage').css("margin-left",-(newWidth/2)+"px");
	$('#fsImage').css("margin-top",-(newHeight/2)+"px");
	
}

function mostraPhoto(){
	
	var imageZoom = $("#imgzoom"+imgVisualizzata).attr("zoom");
	$('img#fsImage').hide();
	
	$('#gallery #preloader').show();
	$('img#fsImage').attr('src', imageZoom);
				
    var download = $(this).attr('download');
		
		if(download=='' || download==$('body').attr('download')){
		    download=imageZoom;
	    }
	    
	    
		$('.footer a.download').attr('href',download);
		$('.footer a.download').attr('target',"_blank");
		
		
		
		
		
		$("img#fsImage").each(function() {
			
			if (this.complete) {
				resizeImg();
				if(navigator.appName == "Microsoft Internet Explorer"){ 
					$('#gallery #preloader').hide();
					setTimeout("$('img#fsImage').fadeIn('slow')", 1000)
					
				}else{
					$('#gallery #preloader').fadeOut('slow', function(){
						$('img#fsImage').fadeIn('slow');
					});		
				}
				
				if($(".zoom").size() <= 1){
					$("#arrow_gallery_sx").hide();
					$("#arrow_gallery_dx").hide();
				}else{
					$("#arrow_gallery_sx").show();
					$("#arrow_gallery_dx").show();	
				}
						
			} else {
				$(this).load(function() {
					
					resizeImg();
					if(navigator.appName == "Microsoft Internet Explorer"){ 
						$('#gallery #preloader').hide();
						setTimeout("$('img#fsImage').fadeIn('slow')", 1000)
					}else{
						$('#gallery #preloader').fadeOut('slow', function(){
							$('img#fsImage').fadeIn('slow');
							
						});		
					}
					
					if($(".zoom").size() <= 1){
						$("#arrow_gallery_sx").hide();
						$("#arrow_gallery_dx").hide();
					}else{
						$("#arrow_gallery_sx").show();
						$("#arrow_gallery_dx").show();	
					}
					
					
				});
			}
		});
	
}


//AVANTI
function avantiPhoto(){
	if(imgVisualizzata + 1 > $(".zoom").size()){
		imgVisualizzata = 1;
	}else{
		imgVisualizzata = imgVisualizzata +1;
		
	}
	mostraPhoto();
}

//INDIETRO
function indietroPhoto(){
	if(imgVisualizzata -1 > 0){
		imgVisualizzata = imgVisualizzata -1;
		
	} else{
		
		imgVisualizzata = $(".zoom").size();
		
	}
	mostraPhoto();
}

function centerDiv(div){
  	var DIVwidth = $(div).width();	
	var DIVheight = $(div).height();
	var SCREENwidth = $(document).width();
	var SCREENheight = $(window).height();	
	var SCREENscrolltop = $(window).scrollTop();
    $(div).hide();
	$(div).css({"position":"absolute","left":(SCREENwidth-DIVwidth)/2+"px","top":(SCREENheight-DIVheight)/2+SCREENscrolltop+"px"});
	$(div).show();
}

/* ZOOM */
function zoomPhoto(){
	
	$('.zoom').click(function(){
		imgVisualizzata=parseInt($(this).attr("id").replace("imgzoom", ""));
		
		
		$("html").css("overflow", "hidden");
		
		var imageZoom = $(this).attr('zoom');
		
		
		var download = $(this).attr('download');
		
		if(download=='' || download==$('body').attr('download')){
		    download=imageZoom;
	    }
	    
	    
		
		
		
		
		var titleZoom = $('h1.titleZoom').text() + ' ' + $('h2.titleZoom').text();
		
		
		$('<div id="gallery"><div id="arrow_gallery_sx"></div><div id="arrow_gallery_dx"></div><div id="preloader"><img src="img/loader.gif" width="16" height="16" /></div><img src="" id="fsImage" /><div id="header"><a href="javascript:void(0)" id="closeGallery">chiudi</a></div><div class="footer"><a class="download">download</a><p>PINOT GRIGIO TRENTINO DOC</p></div></div>').appendTo('body');
		var div = "#gallery";
		
		
		//Imposto il download
		$('.footer a.download').attr('href',download);
		$('.footer a.download').attr('target',"_blank");
				
		centerDiv(div)
		
		
		$('#closeGallery').click(function(){
			$('#gallery').fadeOut('slow').remove();		
			$("html").css("overflow", "auto");
		});
		
		
		$('#gallery .footer p').text(titleZoom);
		
		
		$('img#fsImage').attr('src', imageZoom);
				
		$('img#fsImage').hide();
		
		$("img#fsImage").each(function() {
			
			if (this.complete) {
				resizeImg();
				if(navigator.appName == "Microsoft Internet Explorer"){ 
					$('#gallery #preloader').hide();
					$('img#fsImage').fadeIn('slow');
					
				}else{
					$('#gallery #preloader').fadeOut('slow', function(){
						$('img#fsImage').fadeIn('slow');
					});		
				}
				
				
				if($(".zoom").size() <= 1){
					$("#arrow_gallery_sx").hide();
					$("#arrow_gallery_dx").hide();
				}else{
					$("#arrow_gallery_sx").show();
					$("#arrow_gallery_dx").show();	
				}
						
			} else {
				$(this).load(function() {
					
					resizeImg();
					if(navigator.appName == "Microsoft Internet Explorer"){ 
						$('#gallery #preloader').hide();
						$('img#fsImage').fadeIn('slow');
					}else{
						$('#gallery #preloader').fadeOut('slow', function(){
							$('img#fsImage').fadeIn('slow');
							
						});		
					}
					
					if($(".zoom").size() <= 1){
						$("#arrow_gallery_sx").hide();
						$("#arrow_gallery_dx").hide();
					}else{
						$("#arrow_gallery_sx").show();
						$("#arrow_gallery_dx").show();	
					}
					
					
				});
			}
		});
		
		
		
		$("#arrow_gallery_sx").click(function(){indietroPhoto()});
		$("#arrow_gallery_dx").click(function(){avantiPhoto()});
		
	});
	
	
}


//Zoom Video
function zoomVideo(){
	
	var fsvideoW = 0;
	var fsvideoH = 0;
	
	var icovideoW = $('ul.menuSchedaProdotto .icovideo').outerWidth();
	var icovideoMarginLeft = (174 - icovideoW)/2 + 'px'
	$('ul.menuSchedaProdotto .icovideo').css('margin-left', icovideoMarginLeft)
	
	  $('.zoomvideo').click(function(){
		
			$("html").css("overflow", "hidden");
			
			var videoFlv = $(this).attr('linkflv');
			var videoMp4 = $(this).attr('linkmp4');
			var videoOgv = $(this).attr('linkogv');
			
			var titleZoom = $('h1.titleZoom').text() + ' ' + $('h2.titleZoom').text();
			
			if ( $.browser.msie) {

				$('<div id="videogallery"><div id="fsVideo"><div width="605" height="340" ><div id="flashcontent"></div></div></div><div id="header"><a href="javascript:void(0)" id="closeVideo">chiudi</a></div><div class="footer"><a class="download">download</a><p>PINOT GRIGIO TRENTINO DOC</p></div></div>').appendTo('body');


			}else {

				$('<div id="videogallery"><div id="fsVideo"><video width="605" height="340" controls autoplay><source src="" type="video/mp4" /><!-- Safari / iOS video    --><source src="" type="video/ogg" /><!-- Firefox / Opera / Chrome10 --><!-- fallback to Flash: --><div id="flashcontent"></div></video></div><div id="header"><a href="javascript:void(0)" id="closeVideo">chiudi</a></div><div class="footer"><a class="download">download</a><p>PINOT GRIGIO TRENTINO DOC</p></div></div>').appendTo('body');
				$('#fsVideo').find('source:nth-child(1)').attr('src', videoMp4)
				$('#fsVideo').find('source:nth-child(2)').attr('src', videoOgv)


			}
			

			
			
			var div = "#videogallery";
			centerDiv(div)
			
			
			var download = $(this).attr('linkmp4');
		
			if(download=='' || download==$('body').attr('download')){
			    download=imageZoom;
			}
	
			
			
			//Imposto il download
			$('.footer a.download').attr('href',download);
			$('.footer a.download').attr('target',"_blank");
			
			$('#gallery .footer p').text(titleZoom);
			
			 var so = new SWFObject("http://dev5.thehouseofmouse.it/testnew/poliform/video/videoPlayer.swf", "mymovie", "605", "340", "8", "#000");
			 so.useExpressInstall('expressinstall.swf');
		   so.addParam("movie", "http://dev5.thehouseofmouse.it/testnew/poliform/video/videoPlayer.swf");
		   so.addParam("flashvars", "controlbar=over&amp;flvname="+videoFlv);
		   so.write("flashcontent");
			
			$('#closeVideo').click(function(){
				$('#videogallery').fadeOut('slow').remove();
				$("html").css("overflow", "auto");
			});
			
			
			$('#videogallery .footer p').text(titleZoom);
		
		
		});
	  
	  
}



//gallery list
function hoverVideoListLi(){
	$('#videoList li').hover(function(){
		$('#videoList li').not(this).stop().fadeTo('slow', 0.3);
		
	}, function(){
		$('#videoList li').not(this).stop().fadeTo('slow', 1);
		
	});
}
function hoverFotoListLi(){
	$('#fotoList li').hover(function(){
		$('#fotoList li').not(this).stop().fadeTo('slow', 0.3);
		
	}, function(){
		$('#fotoList li').not(this).stop().fadeTo('slow', 1);
		
	});
}

//CHANGE foto/video
function changeFV() {
	
	
	
	if($('#fotoList').is(':hidden') == false){
		hoverFotoListLi();
		zoomPhoto();	
	}else{
		hoverVideoListLi();
		zoomVideo();	
	}
	
	
	$('.submenu li a').click(function() {	
		$('.submenu li a').removeClass('off');
		$(this).addClass('off');
		if($('#fotoList').is(':hidden') == true){
			$('#videoList').fadeOut('slow', function(){
				$('#fotoList').fadeIn('slow', function(){
					hoverFotoListLi();
					zoomPhoto();									   
				});
				
			});
		}else{
			$('#fotoList').fadeOut('slow', function(){
				$('#videoList').fadeIn('slow', function(){
					hoverVideoListLi();
					zoomVideo();									   
				});
			});	
		}
	});
}



//Carousel prodotti
function carouselProdotti(){
	$('#slider-code .overview li:last-child').css({'background':'none'})
	var loadBoxW = $('#slider-code li').width();
	var loadBoxH = $('#slider-code li').height();
	
	
	$('<div style="position:absolute; top:0; left:0;" id="loaderBox"><img src="img/loader.gif" width="16" height="16" style="position:absolute; top:50%; left:50%; margin-top:-8px; margin-left:-8px" /></div>').appendTo('#slider-code li');
	
	$('#slider-code li #loaderBox').width(loadBoxW);
	$('#slider-code li #loaderBox').height(loadBoxH);
	
	
	$('#slider-code li .contCarousel').css({'display':'none'});									
	
	
	$("#slider-code li .contCarousel img.toload").each(function(i) { 
        if (this.complete) {
        		
				var loadingtofadeout = $(this).parent().parent().parent()
				
				if(navigator.appName == "Microsoft Internet Explorer"){ 
					$('#loaderBox', loadingtofadeout).hide();
					$(this).parent().parent().show();
				}else{
					$('#loaderBox', loadingtofadeout).fadeOut('slow');
					$(this).parent().parent().fadeIn('slow');
				}
				
				$('#slider-code').tinycarousel({display:1, controls: true});
				
				$('#slider-code li').hover(function(){
					
					if(navigator.appName == "Microsoft Internet Explorer"){ 
						$('h1', this).css({'color':'#000'});
						
					}else{
						$('#slider-code li').not(this).stop().animate({opacity: 0.3});
					}							
									   
				}, function(){
						if(navigator.appName == "Microsoft Internet Explorer"){ 
							$('h1', this).css({'color':'#BD6683'});
							
						}else{
							$('#slider-code li').not(this).stop().animate({opacity: 1});
						}	
				});
				
				
		} else {
            $(this).load(function() {
               	
				var loadingtofadeout = $(this).parent().parent().parent()
				
				if(navigator.appName == "Microsoft Internet Explorer"){ 
					$('#loaderBox', loadingtofadeout).hide();
					$(this).parent().parent().show();
				}else{
					$('#loaderBox', loadingtofadeout).fadeOut('slow');
					$(this).parent().parent().fadeIn('slow');
				}
				
				
				
				
				
				$('#slider-code').tinycarousel({display:1, controls: true});
				
				$('#slider-code li').hover(function(){
					if(navigator.appName == "Microsoft Internet Explorer"){ 
						$('h1', this).css({'color':'#000'});
						
					}else{
						$('#slider-code li').not(this).stop().animate({opacity: 0.3});
					}
									   
				}, function(){
						if(navigator.appName == "Microsoft Internet Explorer"){ 
							$('h1', this).css({'color':'#BD6683'});
							
						}else{
							$('#slider-code li').not(this).stop().animate({opacity: 1});
						}	
				});
				
            });
        }
		
    });
}

//Product dett accordion
function accordionProductDett(){
	$('.accordion_toggle').click(function() {
										  setTimeout("changeH()", 500)
		$('.accordion_toggle').removeClass('active');
		$('.accordion_content').slideUp('fast');
	
		if($(this).next().is(':hidden') == true) {
			$(this).addClass('active');
			changeH();
			$(this).next().slideDown('fast');
		 }
	});
	$('.accordion_content').hide();
}


//SUBMENU SX
function submenuSx(){
	$('#submenuSx li a').click(function() {
	    
	
		$('#submenuSx li ul').slideUp('fast');
		if($(this).next().is(':hidden') == true) {
			//OPEN THE SLIDE
			
			if($(this).next().children().length>0){
			
			    $(this).next().slideDown('fast');
			    
			}
			
			
		 }
		 
	 });
	$('#submenuSx li ul').hide();
	
}

//FOOTER LINK
function footerLink(){
	$('.footerMenu a.terms').click(function(){
											
	
		var contenutoLink = $(this).attr('link');	
		var titleWin = $(this).text()
			
		$('<div id="terms"><div id="header"><a href="javascript:void(0)" id="closeTerms">chiudi</a></div><div class="footer"><p>&nbsp;</p></div></div>').appendTo('body')
			
			var div = "#terms";
			centerDiv(div)
			
			$('<div class="contenutoLink"></div>').appendTo('#terms');
			
			$("html").css("overflow", "hidden");
				
			
			$('#terms .contenutoLink').height($(window).height()-150 +'px' );
			
			var newTermsHeight = $('#terms .contenutoLink').height();	
			
			$('#terms .contenutoLink').css("margin-top",-(newTermsHeight/2)+"px").fadeIn('slow', function(){
				$(this).load(contenutoLink).fadeIn('slow')
				$('#terms .footer p').text(titleWin);
			});
		
		
		
		
		
		$('a#closeTerms').click(function(){
			$('#terms').fadeOut('slow', function(){
				$('#terms').remove();			
				$("html").css("overflow", "auto");
			});								  
		});
			
	});
	
	
	
	$(window).resize(function(){
		$('#terms').width($(window).width())
		$('#terms').height($(window).height())
		
		$('#terms .contenutoLink').css('height', $(window).height()-150);
		var newTermsHeight = $('#terms .contenutoLink').height();	
		$('#terms .contenutoLink').css("margin-top",-(newTermsHeight/2)+"px");
		
	});
	
}

/* view wine locator */
function viewWineLocator(){

	
	
	
	
	$('.openwinelocator').click(function(){
		
	    
	    mostraStati();
	
	    $('.dropStato select').unbind('change');
	
	    $('.dropStato select').change(function(){
	    
	        $('.dropZipCode').hide();
	        $('.dropProdotto').hide();
	    
	        if($('.dropStato select').val()!="STATE"){
	            
	            $('.dropStato input').show();
	            mostraZipCode();
	        }
	    
	    });
	    
	    $('.dropZipCode select').unbind('change');
	    
	    $('.dropZipCode select').change(function(){
	    
	    
	        $('.dropProdotto').hide();
	    
	    
	        if( $('.dropZipCode select').val()!="ZIP CODE"){
	     
	            $('.dropZipCode input').show();
	            mostraProdotti();
	     
	        }
	    
	    });
	    
	    
	    $('.dropProdotto select').unbind('change');
	    
	    $('.dropProdotto select').change(function(){
	    
	        if( $('.dropProdotto select').val()!="PRODUCT"){
	     
	            $('.dropProdotto input').show();
	     
	        }else{
	     
	            $('.dropProdotto input').hide();
	     
	       }
	    
	    });
	
		
		$('.winelocator').fadeIn('slow', function(){
												  
			
			//Chiamo il webservice
			
												  
			$(".inputSearch select").msDropDown({ mainCSS: 'cc' });
												  
			$('.winelocator .search input[type="text"]').focus(function() {
       			//$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('.winelocator .search input[type="text"]').blur(function() {
    			//$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});									  
												  
			$('.winelocator a.close').click(function(){
				$('.winelocator').fadeOut('slow', function(){
					$('.winelocator .result').hide();	
					$('.winelocator .search').show()
				});										 
			});
		});	
	});
}

function viewResult(){

    numeroRisultati=0;

    $.ajax({
    type: "GET",
    url: urlWebservice+'getStore'+'?'+'brand='+brand+'&zipCode='+$('.dropZipCode select').val()+"&vino="+$('.dropProdotto select').val(),
    dataType: "xml",
    success: function(xml) {

    var risultatoRicerca='';

    
    $(xml).find('Store').each(function() {

        //Da terminare
        
        
        var nome = $(this).attr('nome');
        var trade = $(this).attr('trade');
		var indirizzo = $(this).attr('indirizzo');
        var telefono = $(this).attr('telefono');
        
        
        /*alert(nome);
        alert(trade);
        alert(indirizzo);
        alert(telefono);
        
        <li>
                    <div class="colSx">
                        <h1>Wine Shop</h1>
                        <h2>highway</h2>
                        <h3>179 Columbus Ave, New York</h3>
                        <h4>(212) 374-8361</h4>
                    </div>
                    <div class="colDx">
                        <h5><span>I Classici:</span>Pinot Grigio,  Lagrein, Traminer</h5>
                        <h5><span>Castel Firmian:</span>Muller Thurgau, Cabernet Sauvignon, Lagrein, Schiava</h5>
                        <h5><span>Le riserve:</span>Pinot Grigio Riserva</h5>
                        <h5><span>Nos:</span>Nos</h5>
                    </div>
                </li>*/
                
                risultatoRicerca+="<li><div class=\"colSx\"><h1>"+trade+"</h1><h2>"+nome+"</h2><h3>"+indirizzo+"</h3><h4>"+telefono+"</h4></div>";
                
                risultatoRicerca+="<div class=\"colDx\">";
                
                
                $(this).find('CategoriaVini').each(function() {
                
                    if( $(this).attr('categoria')!=""){
                        risultatoRicerca+="<h5><span>"+ $(this).attr('categoria')+":</span>"+$(this).attr('vini')+"</h5>";
                    }else{
                        risultatoRicerca+="<h5><span>&nbsp;</span>"+$(this).attr('vini')+"</h5>";
                    }
                    
                });
                
                risultatoRicerca+="</div></li>";
                
                numeroRisultati++;     
        
    });
    
    $('.contenitore .result h3').html("<a href=\"javascript:void(0)\" class=\"back\">back</a> | result ("+numeroRisultati+")");
    
    
    
    $('.contenitore .result .contList').html(risultatoRicerca);



    $('.contenitore .search').fadeOut('slow', function(){
		$('.contenitore .result').fadeIn('slow')
		$('.contenitore .result .contentList').jScrollPane()	
		$('.contenitore .result .contentList .jspVerticalBar').css('width', 8)
		$('.contenitore .result .contentList .jspVerticalBar .jspTrack').css('background', '#CCCCCC')
		$('.contenitore .result .contentList .jspVerticalBar .jspDrag').css('background', '#980033');
		
		$('.contenitore .result .back').click(function(){
			$('.contenitore .result').fadeOut('slow', function(){
				$('.contenitore .search').fadeIn('slow')
			});
		});
	})
	
    }});


		
}

/*-------------------------------------------------------------
------------------ADDRESS--------------------------------------
-------------------------------------------------------------*/
function addressChange(){
	
	$('#menu a').click(function(){
		$('#menu a').removeClass('off');
		$(this).addClass('off');
		$('#submenuDx li a').removeClass('off');
		$('#menuDx a').removeClass('off');
	});
	
	$('#logo a').click(function(){
		$('#menu a').removeClass('off');
		$('#menuDx li a').removeClass('off');
		$('#submenuDx li a').removeClass('off');
			
		
	});
	
	/*$('#menuDx a').click(function(){
		
		$('#menuDx a').removeClass('off');								
		$(this).addClass('off');
		
		inChiusura=true;
		$('#contSubmenuDx').removeClass('open')
		$('#contSubmenuDx').addClass('close');	
		
		if(navigator.appName == "Microsoft Internet Explorer"){ 
			$('#contSubmenuDx').css({'right':'325'}).hide();
			$('.arrow', this).animate({ top:0});	
				
			inChiusura=false;
			inApertura=false;
		}else{
			
			$('#contSubmenuDx').animate({ 
				opacity:0, 
				width:288, 
				width: 'toggle', 
				right: 325
				}, 500, 'jswing', function(){
					
				$('.arrow', this).animate({ top:0});	
				
				inChiusura=false;
				inApertura=false;
			});	
		}
		
		
		$('#menu li a').removeClass('off');
		$('#submenuDx li a').removeClass('off');
		
		
	});*/
	
	$('#submenuDx a').click(function(){
		$('#submenuDx a').removeClass('off');								
		$(this).addClass('off');
		
		$('#menu li a').removeClass('off');
		$('#menuDx li a').removeClass('off');
		
	});
	
	
	$.address.init(function(event) {

		// Initializes the plugin
		$('#menu a').address();
		$('#logo a').address();
		//$('#menuDx a').address();
		$('#submenuDx a').address();
		$('#submenuSx a').address();
		$('#slider-code li a').address();
		$('.nav a').address();
		
		$("#menu li").last().addClass("last");
		
		$('#contSubmenuDx a').address();
		
		$('.btnwine a.acquistavini').address();
	
	
		
	}).change(function(event) {
	
		var value = $.address.state() + event.value;
		
		
	
		
		// Loads and populates the page data	
		$.ajax({
			url: value,
		  	success: function(data) {
	
	
				
				
				
				if(navigator.appName == "Microsoft Internet Explorer"){ 
				
					$(".page").hide();
										
					$(".load-content").html($(data).find('.load-content'));
					
					$(".page").show();
					$(".loadTot").hide();
					
				
				}else{
					
					$(".page").fadeOut('slow');
										
					$(".load-content").html($(data).find('.load-content'));
					
					$(".page").fadeIn('slow');
					$(".loadTot").hide();
					
					Cufon.refresh();
					
					
				}
				
				
				
				
				$("#lang").html($(data).find('#lang li'));
				
				
				changeH();
			
				var matches = data.match(/<title>(.*?)<\/title>/);
				var spUrlTitle = matches[1];
				
				$.address.title(spUrlTitle);
				
				$('li.sottofamiglia	a').each(function() {
	    
	                    
	    
	    
	                
	                    if($(this).attr("href")=="javascript:void") {
	                        $(this).removeAttr("href");
	                        
	                    }
	
	            });	
	            
	            
	            $('#submenuSx li a').each(function() {
	    				if($(this).attr("href")=="javascript:void" || $(this).attr("href")=="javascript:void\"") {
	                        $(this).removeAttr("href");
	                        
	                    }
	
	            });	
				
				
				$('#content').attr('class', '');
				
					//INDEX
				if($('.container').hasClass('index')){
					$('#content').addClass('general');
					
					/* avvio slider */
					$('#titleimg').hide();
					
					var $slider = $('#slider img');
					$slider.css('opacity',0);
							
					$('#slider img').each(function() { 
						if (this.complete) {
							
							if(navigator.appName == "Microsoft Internet Explorer"){ 
				
								$('.loadNivo').hide();
								$slider.animate({'opacity':1}, 500);
								nivoGallery();
								$('#titleimg img').load(function(){
									$('#titleimg').show();	
								});
				
							}else{
								
								$('#preloader.loadNivo').fadeOut(500, function(){
									$slider.animate({'opacity':1}, 500);
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').fadeIn('slow');	
									});
									
								});
								
								
								
							}
							
						} else {
							$(this).load(function() {
							
								if(navigator.appName == "Microsoft Internet Explorer"){ 
					
									$('.loadNivo').hide();
									$slider.animate({'opacity':1}, 500);
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').show();	
									});
					
								}else{
									
									$('#preloader.loadNivo').fadeOut(500, function(){
										$slider.animate({'opacity':1}, 500)
									});
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').fadeIn('slow');	
									});
									
									
								}
							
							});
							
						}
						
					});
					/* fine slider */
					
					changeH();
					
					
					//CHI SIAMO
				}else if($('.container').hasClass('chisiamo')){
					$('#content').addClass('chisiamo');
					
					/* avvio slider */
					$('#titleimg').hide();
					
					var $slider = $('#slider img');
					$slider.css('opacity',0);
					
					
					//Controllo se ci sono i video
					
					if($("ul#videoList").length==0){
				        $("ul#fotoList").show();
				    }
							
					$('#slider img').each(function() { 
						if (this.complete) {
							
							if(navigator.appName == "Microsoft Internet Explorer"){ 
				
								$('.loadNivo').hide();
								$slider.animate({'opacity':1}, 500);
								nivoGallery();
								$('#titleimg img').load(function(){
									$('#titleimg').show();	
								});
				
							}else{
								
								$('#preloader.loadNivo').fadeOut(500, function(){
									$slider.animate({'opacity':1}, 500);
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').fadeIn('slow');	
									});
									
								});
								
								
								
							}
							
						} else {
							$(this).load(function() {
							
								if(navigator.appName == "Microsoft Internet Explorer"){ 
					
									$('.loadNivo').hide();
									$slider.animate({'opacity':1}, 500);
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').show();	
									});
					
								}else{
									
									$('#preloader.loadNivo').fadeOut(500, function(){
										$slider.animate({'opacity':1}, 500)
									});
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').fadeIn('slow');	
									});
									
									
								}
							
							});
							
						}
						
					});
					/* fine slider */
					
					changeH();
					changeFV();
					
					
					//PRODOTTI
				}else if($('.container').hasClass('prodotti')){
					$('#content').addClass('prodotti');
					carouselProdotti();	
					
					
					//PRODOTTI DETTAGLIO
				}else if($('.container').hasClass('prodottidett')){
					
					$('img#imgProdotto').hide();
					
					$('<div style=" width:340px; height:467px; position:absolute; top:0; left:0;" id="loaderBox"><img src="img/loader.gif" width="16" height="16" style="position:absolute; top:50%; left:50%; margin-top:-8px; margin-left:-8px" /></div>').appendTo('#schedaProdotto .contImg');
					
					if(navigator.appName == "Microsoft Internet Explorer"){ 
					
						$('img#imgProdotto').load(function(){
							$('#loaderBox').hide()
							$('img#imgProdotto').show();
						});
		
					}else{
						
						$('img#imgProdotto').load(function(){
							$('#loaderBox').fadeOut('fast', function(){
								$('img#imgProdotto').fadeIn('slow');									 
							});
						});
						
						
					}
					
					
					
					
					accordionProductDett();
					changeH();
					zoomPhoto();
					zoomVideo();
					
					//COMUNICAZIONE
				}else if($('.container').hasClass('comunicazione')){
					
					carouselProdotti();	
					//changeH();
					
					//COMUNICAZIONE DETT
				}else if($('.container').hasClass('comunicazionedett')){
					
					$('#imgProdotto').hide();
					
					$('<div style=" width:340px; height:423px; position:absolute; top:0; left:0;" id="loaderBox"><img src="img/loader.gif" width="16" height="16" style="position:absolute; top:50%; left:50%; margin-top:-8px; margin-left:-8px" /></div>').appendTo('#schedaProdotto .contImg');
					
					if(navigator.appName == "Microsoft Internet Explorer"){ 
					
						$('#imgProdotto img').load(function(){
							$('#loaderBox').hide();
								$('#imgProdotto').show();
						});
		
					}else{
						
						$('#imgProdotto img').load(function(){
							$('#loaderBox').fadeOut('fast', function(){
								$('#imgProdotto').fadeIn('slow');									 
							});
						});
						
						
					}
					
					
					
					
					
					changeH();
					zoomPhoto();
					
					//RICONOSCIMENTI
				}else if($('.container').hasClass('riconoscimento')){
					$('#content').addClass('riconoscimento');
					
					/* avvio slider */
					$('#titleimg').hide();
					
					var $slider = $('#slider img');
					$slider.css('opacity',0);
					
							
					//rimuovo il link dai 
					
					$('#submenuSx li ul#apriti').each(function() {
	    
	                    if($(this).children().size() == 0) {
	                        $(this).prev().addClass('configli');
	                    }else{
							$('a',this).addClass('configli');
						}
	
	                });
					
					$('#submenuSx li a').each(function() {
	    
	                    if($(this).attr("href")=="javascript:void") {
	                        $(this).removeAttr("href");
	                    }
	
	                });
	
							
					$('#slider img').each(function() { 
						if (this.complete) {
							
							if(navigator.appName == "Microsoft Internet Explorer"){ 
				
								$('.loadNivo').hide();
								$slider.animate({'opacity':1}, 500);
								nivoGallery();
								$('#titleimg img').load(function(){
									$('#titleimg').show();	
								});
				
							}else{
								
								$('#preloader.loadNivo').fadeOut(500, function(){
									$slider.animate({'opacity':1}, 500);
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').fadeIn('slow');	
									});
									
								});
								
								
								
							}
							
						} else {
							$(this).load(function() {
							
								if(navigator.appName == "Microsoft Internet Explorer"){ 
					
									$('.loadNivo').hide();
									$slider.animate({'opacity':1}, 500);
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').show();	
									});
					
								}else{
									
									$('#preloader.loadNivo').fadeOut(500, function(){
										$slider.animate({'opacity':1}, 500)
									});
									nivoGallery();
									
									$('#titleimg img').load(function(){
										$('#titleimg').fadeIn('slow');	
									});
									
									
								}
							
							});
							
						}
						
					});
					/* fine slider */
					
					submenuSx();
					changeH();
					
					//CONTATTI
				}else if($('.container').hasClass('contatti')){
					$('#content').addClass('contatti');
					
					
					
					submenuSx();
					
					changeH();
					
					   setTimeout("creaMappa()",2000);
				}
				
				
				
				
			}
		});
		// fine load
	});	
}


var map="";
var markerInseriti = 0;
var markers = []; 


function creaMappa() {


// Rimuovo i marker
for (var i = 0; i<markerInseriti; i++) { 
		  map.removeOverlay(markers[i]);
		 // alert(i);
}


markerInseriti=0;

//Creo la mappa

    map = new GMap2(document.getElementById('master_contentPage_contSlider')); 
	map.addControl(new GLargeMapControl());
	var italy = new GLatLng(46.34361,10.678711); 
 	map.setCenter(italy, 8); 


var latitidine=$("#submenuSx li a.off").attr('latitudine');
var longitudine=$("#submenuSx li a.off").attr('longitudine');
var nome=$("#submenuSx li a.off").attr('nome');



var point = new GLatLng(parseFloat(latitidine)+0, parseFloat(longitudine)+0); 
						marker = new GMarker(point); 
						map.addOverlay(marker);  
					  	
						markers[markerInseriti] = marker; 
						markerInseriti = markerInseriti+1;

if(markerInseriti==1){
							map.panTo(new GLatLng(parseFloat(latitidine), parseFloat(longitudine))); 
						}

}

$(function() {
	//replaceFont();	   
	
	//Sistemo le lingue
	
	//$('ul#lang li a').removeAttr('href');
	
	//$('ul#lang li a:first').attr('href','http://www.mezzacorona.it/');
	
	
	addressChange();
	
	
	
	$.preloadCssImages();
	
	footerLink();
	
	$(".page").fadeIn('slow');
	$(".loadTot").hide();
	
	changeH();
	
	if($('.winelocator') != 0){
		viewWineLocator()
	}
	if($('.winelocator .search').is(':visible')){
		viewResult();
	}
	
});

$(window).load(function(){
	menuLaterale();

});


//RESIZE
$(window).resize(function(){
	try
  	{
		
		$('#footer').height($(window).height() - $('#wrapper').height());	
	
	
	
	resizeImg();
	//changeH();
	
	}catch(err){
	}
});



/*wine locator*/

//Recupera valore dropdown

var urlWebservice="http://www.mezzacorona.it/WebServiceWineLocator.asmx/";
var brand="mezzacorona";

function recuperaDropDown($elemento,$chiamata,$parametri){
    
    

    
     $.ajax({
    type: "GET",
    url: urlWebservice+$chiamata+'?'+$parametri,
    dataType: "xml",
    success: function(xml) {

    var options='';
	
    
    $(xml).find('string').each(function() {

		

        options += '<option value="' + $(this).text() + '">' +  $(this).text() + '</option>';

    });

    $($elemento).html(options);

    $($elemento).parent().show();
	$(".inputSearch select").msDropDown({ mainCSS: 'cc' });
	
    }
});

}




function mostraStati(){
    


    
    $('.dropZipCode').hide();
    $('.dropProdotto').hide();
    
    $('.dropStato input').hide();
    
    recuperaDropDown($('.dropStato select'),'getStati','brand='+brand);
	$(".dropStato").show()
}

function mostraZipCode(){

    
    $('.dropProdotto').hide();
    $('.dropZipCode input').hide();
    
     recuperaDropDown($('.dropZipCode select'),'getZipCode','brand='+brand+"&stato="+$('.dropStato select').val());
	
	 $(".dropZipCode").show()
}

function mostraProdotti(){
    $('.dropProdotto input').hide();
    
    recuperaDropDown($('.dropProdotto select'),'getProdotti','brand='+brand+"&zipCode="+$('.dropZipCode select').val());
	 $(".dropProdotto").show()
}


