﻿  $(function() {

    $('img.categoryImg').each(function() {
    
        $(this).hover(function(){
            var oldSrc =  $(this).attr('src');
            var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
            var newSrc = oldSrc.replace(re, "$1_hover.$2");
            $(this).attr('src', newSrc);
        }, function(){
            var oldSrc =  $(this).attr('src');
            var re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
            var newSrc = oldSrc.replace(re, "$1.$2");
            $(this).attr('src', newSrc);
        });
        
    });

    $('.productHeader').each(function() {
	
      $(this).hover(
        function() {
          var hoverId = this.id;
          var categoryId = hoverId.substr(6);
        
          if($("#products" + categoryId).is(':hidden')) {
            $(this).attr('title', 'Näytä tuotteet');
          } else {
            $(this).attr('title', 'Piilota tuotteet');
          }

          $(this).css('cursor','pointer');
          $(this).css('background-color', '#FFBFBF');
        
        }, 
        function() {
          $(this).css('cursor','auto');
          $(this).css('background-color', 'white');
        }
      );
      
      $(this).click(
        function() {
          var clickedId = this.id;
          var categoryId = clickedId.substr(6);
          $("#products" + categoryId).stop().slideToggle(); 
        }
      );
      
    });
	
	$('.menuHeader').each(function() {
	
      $(this).hover(
        function() {
          var hoverId = this.id;
          var categoryId = hoverId.substr(6);
        
          if($("#restaurant" + categoryId).is(':hidden')) {
            $(this).attr('title', 'Näytä ruokalista');
          } else {
            $(this).attr('title', 'Piilota ruokalista');
          }

          $(this).css('cursor','pointer');
          $(this).css('background-color', '#FFBFBF');
        
        }, 
        function() {
          $(this).css('cursor','auto');
          $(this).css('background-color', 'white');
        }
      );
      
      $(this).click(
        function() {
          var clickedId = this.id;
          var categoryId = clickedId.substr(6);
          $("#restaurant" + categoryId).stop().slideToggle(); 
        }
      );
      
    });
    
    $('.productImgLink').fancybox({
    
      'transitionIn'	:	'elastic',
      'transitionOut'	:	'elastic',
      'speedIn'		:	600, 
      'speedOut'		:	200, 
      'overlayShow'	:	true
      
    });
	
	$('#showAll').fancybox({
      'transitionIn'	:	'elastic',
      'transitionOut'	:	'elastic',
      'speedIn'		:	600, 
      'speedOut'		:	200, 
      'overlayShow'	:	false,
	  'hideOnContentClick': true,
	  'width'				: '75%',
	  'height'			: '75%',
	  'autoScale'     	: false,
	  'type'				: 'iframe',
	  'scrolling' : 'yes'
	});
	
	$("#feedbackForm").validate();
	
	$("#submitp").each(function() {
	
		$(this).hover(
		  function() {
		    $(this).css('cursor','pointer');
			$(this).css('background-color', '#C66668');
		  },
		  function() {
		    $(this).css('cursor','auto');
		    $(this).css('background-color', 'white');
		  }
	    );
	});
	
	$("#reset").each(function() {
	
		$(this).hover(
		  function() {
		    $(this).css('cursor','pointer');
			$(this).css('background-color', '#C66668');
		  },
		  function() {
		    $(this).css('cursor','auto');
		    $(this).css('background-color', 'white');
		  }
	    );
		
		$(this).click(
		  function() {
		    $("#teksti").val("");
			$("#name").val("");
			$("#email").val("");
		  }
		);
	});

    
  });
  
