$(document).ready(function() {
	// image overlay
	$('.thumbHover').hide();
	$('.detail-image').mouseenter(function(){
		$('.thumbHover').show();
		var margin = (185-$('.detail-image img').width()) / 2;
		$('.overlay').css('margin-left', margin);
		$('.overlay').css('width', $('.detail-image img').width());
		$('.overlay').css('height', $('.detail-image img').height());
                $('.overlay').css('background-color', '#000000');
		$('.detail-image img').css('opacity', '0.5');	        

	});

	$('.detail-image').mouseleave(function(){
		$('.thumbHover').hide();
		$('.overlay').css('background-color', '#ffffff');
		$('.detail-image img').css('opacity', '1');
	});
	
	// image overlay
	$('.viewdetails').hide();
	$('.image-container').mouseenter(function(){
		$(this).find('.viewdetails').show();
	});
	
	$('.image-container').mouseleave(function(){
		$('.viewdetails').hide();
	});

	
/*
	// image resizing so that they look more uniform
	$('.productimage').each(function() {
		var maxWidth = 185; // Max width for the image
		var maxHeight = 185;    // Max height for the image
		var ratio = 0;  // Used for aspect ratio
		var width = $(this).width();    // Current image width
		var height = $(this).height();  // Current image height

		// Check if the current width is larger than the max
		if(width > maxWidth){
			ratio = maxWidth / width;   // get ratio for scaling image
			$(this).css("width", maxWidth); // Set new width
			$(this).css("height", height * ratio);  // Scale height based on ratio
			height = height * ratio;    // Reset height to match scaled image
		}

		// Check if current height is larger than max
		if(height > maxHeight){
			ratio = maxHeight / height; // get ratio for scaling image
			$(this).css("height", maxHeight);   // Set new height
			$(this).css("width", width * ratio);    // Scale width based on ratio
			width = width * ratio;    // Reset width to match scaled image
		}
	});
*/	
// image resizing so that they look more uniform
	$('.product_image').each(function() {
		var maxWidth = 185; // Max width for the image
		var maxHeight = 185;    // Max height for the image
		var ratio = 0;  // Used for aspect ratio
		var width = $(this).width();    // Current image width
		var height = $(this).height();  // Current image height

		// Check if the current width is larger than the max
		if(width > maxWidth){
			ratio = maxWidth / width;   // get ratio for scaling image
			$(this).css("width", maxWidth); // Set new width
			$(this).css("height", height * ratio);  // Scale height based on ratio
			height = height * ratio;    // Reset height to match scaled image
		}

		// Check if current height is larger than max
		if(height > maxHeight){
			ratio = maxHeight / height; // get ratio for scaling image
			$(this).css("height", maxHeight);   // Set new height
			$(this).css("width", width * ratio);    // Scale width based on ratio
			width = width * ratio;    // Reset width to match scaled image
		}
	});
	

	// front page banner
    $('.flexslider').flexslider({
		controlNav: false,
		directionNav: false,
		slideshowSpeed: 7000,
		animationDuration: 600,
		animation: 'show'
	});

	// initialize scrollable for front page scrolling products
	$(".scrollable").scrollable({
			speed: 800,
			size: 4,
			easing: 'linear'
		});
	
	// lightbox for product images
	$(".lightbox").lightbox({
		fitToScreen:'true'
	});

  //Form text effects
  $('#inputName').defaultvalues({focusaction:"clear"});
  $('#inputEmail').defaultvalues({focusaction:"clear"});
  $('.contactFormInput').defaultvalues({focusaction:"clear"});
  $('.contact2').defaultvalues({focusaction:"clear"});
  $('.cms_textfield').defaultvalues({focusaction:"clear"});
  $('.promo').defaultvalues({focusaction:"clear"});
  $('.password').defaultvalues({focusaction:"clear"});
  
  //hack to get textarea/captcha form color to change properly. 
  $('.text').css('color', '#838383');
  $('.cms_textfield').css('color', '#838383');
  $('.cms_dropdown').css('color', '#838383');
  
   
   $("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");


	/*$("li.myCart").click(function(){
		$(this).addClass("hover");
		$('#cartSummary').css('right', '0');
		$('#cartSummary').css('visibility', 'visible');
	});*/


	$("#tab-1, #tab-2, #tab-3, #tab-4, #tab-5, #tab-6, #tab-7").hide();
	$("#tab-1").show();

	$("#continue-2").click(function(){
		$('#tab-1').hide();
		$('#tab-2').show();
	});

 	$("#continue-3").click(function(){
                $('#tab-2').hide();
                $('#tab-3').show();
        });

	 $("#continue-4").click(function(){
                $('#tab-3').hide();
                $('#tab-4').show();
        });


	 $("#continue-5").click(function(){
                $('#tab-4').hide();
                $('#tab-5').show();
        });


	 $("#continue-6").click(function(){
                $('#tab-5').hide();
                $('#tab-6').show();
        });


	 $("#continue-7").click(function(){
                $('#tab-6').hide();
                $('#tab-7').show();
        });

	$("#back-1").click(function(){
		$('#tab-1').show();
		$('#tab-2').hide();
	});

	 $("#back-2").click(function(){
                $('#tab-2').show();
                $('#tab-3').hide();
        });

	 $("#back-3").click(function(){
                $('#tab-3').show();
                $('#tab-4').hide();
        });


	 $("#back-4").click(function(){
                $('#tab-4').show();
                $('#tab-5').hide();
        });


	 $("#back-5").click(function(){
                $('#tab-5').show();
                $('#tab-6').hide();
        });


	 $("#back-6").click(function(){
                $('#tab-6').show();
                $('#tab-7').hide();
        });


	




    
});



$(window).load(
	function() {
        $('.productimage').each(function(){
                var maxWidth = 185;
                var width = $(this).width();
                if (width < maxWidth){
                      	leftMargin = ( (maxWidth - width) / 2 );
       	      		$(this).css('left', leftMargin);
      		}
        });
}
);

  





