
    function hoverOver(){
        $this = $(this).find('.menuWrapper');
        if($this.attr('rel') != ''){
            $('#'+$this.attr('rel')).parent().css('position', 'absolute');
            var position = $(this).position();
            var pos2 = $('#header').position();
            $('#'+$this.attr('rel')).parent().css('top', '48px');
            $('#'+$this.attr('rel')).css('margin-top', '22px');
            $('#'+$this.attr('rel')).parent().css('z-index', '1001');
            $width = $('#'+$this.attr('rel')).find('.col5').size()+1;
            $('#'+$this.attr('rel')).css('width', (975)+ 'px');//$width*244
            $('#'+$this.attr('rel')).parent().css('left', (-120) +'px');
            $el = $('<div></div>').insertAfter($this);
            $el.addClass('arrowTop');
            $el.css('position', 'absolute');
            $el.css('z-index', '1002');
            $el.css('top', '50px');
            $el.css('left', (position.left+30)+'px');
            $this.data('el', $el);
            $('#'+$this.attr('rel')).show();
            //if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))){
                $('.closeW').css('display','block');
                $('.closeW').css('cursor','pointer');
                $('.closeW').css('position','absolute');
                $('.closeW').css('top','10px');
                $('.closeW').css('left',(975-45)+ 'px');//($width*244-40)
                //$('.closeW').css('left','100%');
                $('.closeW').click(function(){
                     $this = $(this).parent();
                     $this.hide();
                     if(typeof $this.data('el') != 'undefined'){
                        $this.data('el').remove();
                        $this.removeData('el');
                    }
                });
            //}else{
              //  $('.closeW').css('display','none');
            //}
        }
    }
    function formatTitle(title, currentArray, currentIndex, currentOpts) {
        return '<div id="tip7-title">'+title+'</div>';
    }

    function hoverOut(){
           $this = $(this).find('.menuWrapper');
          if($this.attr('rel') != ''){
            $('#'+$this.attr('rel')).hide();
            if(typeof $this.data('el') != 'undefined'){
                $this.data('el').remove();
                $this.removeData('el');
            }
          }
    }

    function careloOver(){
        $(this).css('cursor','pointer');
        var position = $(this).position();
        $('#divShoppingCard').css('top','50px');
        $('#divShoppingCard').css('left',(position.left+1)+'px');
        $('#divShoppingCard').stop(true, true).slideDown();
    }

    function careloOut(){
        $('#divShoppingCard').stop(true, true).slideUp();
        $('#divShoppingCard').hide();
    }

    function pochiOver(){
        $(this).find('.tooltipPochi').show();
        //$(this).find('.tooltipPochi2').show();
    }

    function pochiOut(){
        $(this).find('.tooltipPochi').hide();
        //$(this).find('.tooltipPochi2').hide();
    }

    function shareOver(){
       $(this).find('.addthis_toolbox.addthis_pill_combo').first().show();
    }

    function shareOut(){
       $('.addthis_toolbox.addthis_pill_combo').hide();
    }
    
    function refreshCart(){ 
		formElement = $('form[name="cart_quantity"]');
		$('.waitingDiv').show();
		$.ajax({
			cache:false,
			url: 'vali_ajax_shopping_cart.php?action=update_product&subAcc=getCartTotal',
			type: 'post',
			data: formElement.serialize(),
			dataType: 'html',
			success: function (data) {
				if(data.length > 3){
					$('#shopping_chart_total').html(data);
				}
				$('.waitingDiv').hide();
			}
		}); 
	}
    
    function checkoutChangeEmailType(){
   		 newVal = $('.emailType:checked').val();
   		 if(newVal == '0'){
   			 $('#checkoutFirmPart').hide();
   		 }else{
   			 $('#checkoutFirmPart').show();
   		 }
    }
    
    function printDivInNewWindow(divId){
    	w=window.open();
    	w.document.write($('#'+divId).html());
    	w.print();
    	w.close();
    }

$(document).ready(function (){
	
//	document.getElementById('shoppingCartMenuText').innerHTML = document.getElementById('shoppingText').innerHTML;
	
	
	
    $('#menuLine').css('display','block');
	$('#menuLine').parent().parent().css('margin-top','-4px');
	$('#menuLine').parent().parent().css('margin-left','1px');
	$('#menuLine').parent().parent().css('height','50px');
	$('.searchInput2').val('Cerca nel sito...');
	$('.searchInput2').click(function(){
		if($('.searchInput2').val() == 'Cerca nel sito...'){
			$('.searchInput2').val('');
		}

	});
    var config = {
         sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
         interval: 10, // number = milliseconds for onMouseOver polling interval
         over: hoverOver, // function = onMouseOver callback (REQUIRED)
         timeout: 0, // number = milliseconds delay before onMouseOut
         out: hoverOut // function = onMouseOut callback (REQUIRED)
    };

    $("#menuLine li").hoverIntent(config);
    $('.notLink').click(function(){
        //return false;
    });
    $('#fancybox-overlay').click(function(){
    	$('#fancybox-overlay').hide();
    });
    $('.dropDownWrapper').hide();

    var config2 = {
             sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
             interval: 10, // number = milliseconds for onMouseOver polling interval
             over: careloOver, // function = onMouseOver callback (REQUIRED)
             timeout: 0, // number = milliseconds delay before onMouseOut
             out: careloOut // function = onMouseOut callback (REQUIRED)
    };
    
//    $('#carelo').hoverIntent(config2);
    //$('#divShoppingCard').slideUp();

    $('#login-hover-link').click(function(){
       $('#top-login-wrapper').addClass('down');
       $('#lform').css('display','block');
       return false;
    });
    var mouse_is_inside = false;
    $('#top-login-wrapper').hover(function(){
        mouse_is_inside=true;
    }, function(){
        mouse_is_inside=false;
    });

    /*$('.addthis_toolbox.addthis_pill_combo').hover(function(){
        mouse_is_inside=true;
    }, function(){
        mouse_is_inside=false;
    });*/

    $('body').mouseup(function(){
        if(!mouse_is_inside) {
            $('#top-login-wrapper').removeClass('down');
            $('#lform').css('display','none');
        }
    });
    $('.searchIcon2').click(function(){
        $(this).parent().parent().submit();
    });
    $('.addthis_toolbox.addthis_pill_combo').hide();
    $('.sharebut').click(function(){
        return false;
    });

    var config4 = {
             sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
             interval: 10, // number = milliseconds for onMouseOver polling interval
             over: shareOver, // function = onMouseOver callback (REQUIRED)
             timeout: 0, // number = milliseconds delay before onMouseOut
             out: shareOut // function = onMouseOut callback (REQUIRED)
    };

    $('.stock_link').hoverIntent(config4);



    var config3 = {
             sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
             interval: 10, // number = milliseconds for onMouseOver polling interval
             over: pochiOver, // function = onMouseOver callback (REQUIRED)
             timeout: 0, // number = milliseconds delay before onMouseOut
             out: pochiOut // function = onMouseOut callback (REQUIRED)
    };

//    $('.stock_linka').hoverIntent(config3);
//    $('.buy_link').hoverIntent(config3);


    $('.subbtn').click(function(){
        if(parseInt($('.qty_field').val()) >1){
            $('.qty_field').val(parseInt($('.qty_field').val())-1);
        }
    });
    $('.addbtn').click(function(){
        if(parseInt($('.qty_field').val())+1 <= parseInt($('.qty_field').attr('maxval'))){
            $('.qty_field').val(parseInt($('.qty_field').val())+1);
        }
    });
    $('.qty_field').change(function(){
        if(isNaN($(this).val())){
            $(this).val('1');
        }else{ 
            if(parseInt($('.qty_field').val()) <= parseInt($('.qty_field').attr('maxval'))){
                $('.qty_field').val(parseInt($('.qty_field').val()));
            }else{
                $('.qty_field').val($('.qty_field').attr('maxval'));
            }
        } 
    });
    $('.addbtnChart').click(function(){
    	productId = $(this).attr('id').replace('addbtn_','');
    	if ( $(this).css('background-image').search('add_quantity.png') != '-1'){
	    	if(parseInt($('#qty_field_'+productId).val())+1 <= parseInt($('#qty_field_'+productId).attr('maxval'))){
	        	$('#qty_field_'+productId).val(parseInt($('#qty_field_'+productId).val())+1);
	    	}
	    	refreshCart();
    	}
    });

    $('.subbtnChart').click(function(){
    	productId = $(this).attr('id').replace('subbtn_','');
    	if( parseInt($('#qty_field_'+productId).val()) == 1){
    		allowRemove = confirm('Sei sicuro di voler rimuovere questo prodotto?');
    		if(!allowRemove) { 
    			return true;
    		}
    	}
    	if( parseInt($('#qty_field_'+productId).val()) > 0){
    		$('#qty_field_'+productId).val(parseInt($('#qty_field_'+productId).val())-1);
    	}else{
    	//	$('#subbtn_'+productId).css('background-image', 'url("images/template/cart_sub_block.png")');
    	}
    	refreshCart();
    	if( parseInt($('#qty_field_'+productId).val()) == 0){
    		$('#cartProd'+productId).remove();
    	}
    });
    
	$('.cartRefresh').change(function(){
		formElement = $('form[name="cart_quantity"]');
		refreshCart();
	});
	refreshCart();
   
    
    $('#contactAjax,#contactAjax1').click(function(){
        $.fancybox({
                    'padding'		: 0,
                    'autoScale'		: false,
                    'transitionIn'	: 'none',
                    'transitionOut'	: 'none',
//                    'title'			: 'Qual è il motivo del tuo contatto?',
                    'titleShow'		: true,
                    'titlePosition' : 'outside',
                    'width'		    : 890,
                    'overlayColor'  : '#111111',
                    'titleFormat'	: formatTitle,
                    'height'		: 457,
                    'type'			: 'ajax',
                    'href'			: this.href
                });

        return false;
    });
    $('#reserveAjax').click(function(){
    	$.fancybox({
    		'padding'		: 0,
    		'autoScale'		: false,
    		'transitionIn'	: 'none',
    		'transitionOut'	: 'none',
 //   		'title'			: 'Qual è il motivo del tuo contatto?',
    		'titleShow'		: false,
    		'titlePosition' : 'outside',
    		'width'		    : 890,
    		'overlayColor'  : '#111111',
    		'titleFormat'	: formatTitle,
    		'height'		: 457,
    		'href'			: this.href,
    		'type'			: 'ajax'
    			
    	});
    	
    	return false;
    });
    
    $('.reserveAjax').click(function(){
    	$.fancybox({
    		'padding'		: 0,
    		'autoScale'		: false,
    		'transitionIn'	: 'none',
    		'transitionOut'	: 'none',
//    		'title'			: 'Qual è il motivo del tuo contatto?',
    		'titleShow'		: false,
    		'titlePosition' : 'outside',
    		'width'		    : 890,
    		'overlayColor'  : '#111111',
    		'titleFormat'	: formatTitle,
    		'height'		: 457,
    		'href'			: this.href,
    		'type'			: 'ajax'
    			
    	});
    	
    	return false;
    });
    
    if($(window).width()<= 1024){
        //$('#container').css('padding-left', '10px');
    }
    $('.inviabtn').click(function(){
        if(isValid()){
           $.ajax({
                    cache:false,
                    url: $(this).parent().attr('action'),
                    type: 'post',
                    data: $(this).parent().serialize(),
                    dataType: 'html',
                    success: function (data) {
                        $('.cinfoemail #email').val('');
                        $('.cinfoname #name').val('');
                        $('.cinfomsg #msg').val('');
                        //  alert('Message was sent');//translate
                        $('#tab5').html('<div><div style="float:left;"><img border="0" align="left" title=" Contattaci " alt="Contattaci" src="images/contactsuccess.jpg"></div><div style="float:left; padding:80px 10px 10px 50px; width:450px; font-family:Arial; font-size:13px; text-align:center;">'+"La sua domanda è stata inviata all'Assistenza. Tutte le domande vengono spesso processate in pochissimo tempo dal Lunedi al Venerdi, e al massimo comunque in 72 ore. "+'</div><div class="clearDiv"></div></div>');  
                    }
                });
        }
       return false;
    });
    /*var position = $('.Header_Logo_Back').position();
    $('.Header_Logo_Back').css('left',(position.left)+'px');
    $('.Header_Logo_Back').css('top',(position.top)+'px');*/
    //$('.dropDownWrapper').corner('10px');
    /*$(window).resize(function() {
        widthp = $(this).width()/2;
        $('#container').css('margin-left','-'+widthp + 'px');
    });*/
});


