// JavaScript Document
$(document).ready(function(){
	
	//----------------
	// MENU
	//----------------
	
	$('img').bind("contextmenu",function(e){
		alert('right click is not available');
        return false;
    });
	
	//header menu
	$('#header-navimages ul li ul').hide()
	var is_menu_active = false;
		
	$('#header-navimages ul li').hover(
	  function () {
		  var jQuerytarget_ul= $(this).children('ul')
		 if( jQuerytarget_ul.is(":visible") == false && jQuerytarget_ul.length > 0 && jQuerytarget_ul.queue().length==0){
				$(this).children('ul').slideDown();
				
				if($(this).find('a.btn_top_navigation_active').length > 0){
					is_menu_active = true;	
				}				
				$(this).find('a.btn_top_navigation').addClass('btn_top_navigation_active')
		 }			
	  }, 
	  function () {
		   if( $(this).children('ul').is(":visible") == true){
	   			$(this).children('ul').slideUp('fast');
				if(!is_menu_active) $(this).find('a.btn_top_navigation').removeClass('btn_top_navigation_active')				
		   }
	 });
	 
	 
	 //popup video
	 $('.btn_video_popup').fancybox({
                    'titleShow'     : false,
                    'transitionIn'  : 'elastic',
                    'transitionOut' : 'elastic',
            'type'      : 'swf',
            'swf'       : {'wmode':'transparent','allowfullscreen':'true'}
        });
		
	//------------------------	
	//effetti sul campi form
	//------------------------
	
	//reset testo input sul focus
	var temp_value = '';
	$('.input_val').focus(function(){
		temp_value = $(this).val();
		$(this).val('')
		$(this).css('color', 'black');		
	})
	
	$('.input_val').focusout(function(){
		if($(this).val() == "") {			
			$(this).val(temp_value)	
			$(this).css('color', '#999999');
		}
		temp_value = '';
	})
	
	$('.input_val_sc').focus(function(){
		temp_value = $(this).val();
		$(this).val('')
	})
	
	$('.input_val_sc').focusout(function(){
		if($(this).val() == "") {			
			$(this).val(temp_value)	
		}
		temp_value = '';
	})
	
	$('#btn_sel_all').click(function(){
		if($('input[name="cart_delete[]"]').is(':checked')){
			$('input[name="cart_delete[]"]').attr('checked', false);	
		}else{
			$('input[name="cart_delete[]"]').attr('checked', true);	
		}
	})
	
	//------------------------------
	// EFFETTI CAMPI FORM PULSANTI + E - 
	//------------------------------
	if($('.btn_quantity_plus').length > 0 && $('.btn_quantity_minus').length > 0){
		
		$('.btn_quantity_plus, .btn_quantity_minus').click(function(){
			var value
			var target = $(this).parents('.quantity_container').find('#cart_quantity')
			if($(this).attr('class') == 'btn_quantity_plus'){
				value = parseInt($(target).val()) +1
			}else{
				value = parseInt($(target).val()) -1
			}
			if(value < 1 || isNaN(value)) value = 1
			$(target).val(value)	
		})
		
	}
	
	//-----------------------------------
	// EFFETTI CAMPI FORM LOGIN E RICERCA
	//-----------------------------------
	var temp_value2 = ''
	$('input.input_password, input.input_login, input.input-style').css('color', '#999999');
	$('input.input_password, input.input_login, input.input-style').focus(function(){
		temp_value2 = $(this).val();	
		$(this).val('')
		$(this).css('color', 'black');			
	})
	
		$('input.input_password, input.input_login, input.input-style').focusout(function(){
		if($(this).val() == "") {			
			$(this).val(temp_value2)	
			$(this).css('color', '#999999');
		}
		temp_value2 = '';
	})
	
	//----------------------------
	// TABELLE
	//----------------------------
	
	//rigne colore alternato
	//per aaplicare l'effetto aggiungere alla tabella la classe row_aternate
	$(".row_aternate tr:even").addClass("even");
  	$(".row_aternate tr:odd").addClass("odd");
	
	//---------------------------
	// STAMPA ORDINE
	//---------------------------
	
	//pulsante stampa pagina 
	$('#stampa_ordine').click(function(event){
		event.preventDefault()
		window.print()	
	})
	
	//------------------------------
	//EFFETTI HOVER SU CATEGORIE HOME
	//------------------------------
	
	$('.cat_home_image').hover(function(){
			
			//effetto hover su titolo categoria
			var name_cat = '#'+$(this).attr('id') + '_name';
			$('.cat_home').removeClass('cat_hover');
			$(name_cat).addClass('cat_hover');
			
			//effetto hover su immagine
			var margin_top = parseInt($(this).find('img').attr('height')) / 2
			$('.cat_home_image img').css('margin-top', 0)
			$(this).find('img').css('margin-top', '-'+margin_top+'px')
		},
		
		function(){
			$('.cat_home_image img').css('margin-top', 0)
			$('.cat_home').removeClass('cat_hover');
			
	});
	
	$('.cat_home').hover(function(){
			
			//effetto hover su titolo categoria
			var name_cat = '#'+$(this).attr('id').replace('_name', '');
			//$('.cat_home').removeClass('cat_hover');
//			$(name_cat).addClass('cat_hover');
			
			//effetto hover su immagine
			var margin_top = parseInt($(name_cat).find('img').attr('height')) / 2
			$(name_cat +' img').css('margin-top', 0)
			$(name_cat).find('img').css('margin-top', '-'+margin_top+'px')
		},
		
		function(){
			$('.cat_home_image img').css('margin-top', 0)
			//$('.cat_home').removeClass('cat_hover');
			
	});
	
	
	
	
	//------------------------------
	// provvisorio under costruction
/*	$('a').not($('#btn_video_azienda')).click(function(){
		return false;	
	})*/
	
	$('#btn_video_azienda').fancybox({
	    'padding'           : 0,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'width'				: '720',
		'height'			: '603',
		'overlayOpacity'	:	0.8,
		'overlayColor'		: '#000'
	
	})
	
	//VIDEO AZIENDA PARTENZA AUTOMATICA
	/*var video_url = $('#btn_video_azienda').attr('href');
	
	$.fancybox({
		'href'				:video_url,
	    'padding'           : 0,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'width'				: '720',
		'height'			: '603',
		'overlayOpacity'	:	0.8,
		'overlayColor'		: '#000'
	
	})*/
	
	//------------------------------
	// provvisorio under costruction
	
})

/*  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-11903197-7']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
*/

