﻿    jQuery.fn.fadeToggle = function(speed, easing, callback) {
       return this.animate({opacity: 'toggle'}, speed, easing, callback);

    }; 
	
	$j(document).ready(function() {

        $j(".products").click(function () {
            $j(".products").removeClass("pselected");
            $j(".all-products").removeClass("all-products-pselected");
            $j(".products .jRadioWrapper .jNiceRadio ").removeClass("jNiceChecked");
            $j(".all-products .jRadioWrapper .jNiceRadio ").removeClass("jNiceChecked");
            $j(this).toggleClass("pselected");
            $j(this).find('input').attr("checked", true);
            $j(this).find('.jNiceRadio').addClass("jNiceChecked");
            $j('.sub-products').hide();
            $j('.find').hide();
            $j(this).parent().find('.sub-products').slideDown('300');
            $j(this).parent().find('.find').fadeToggle('300');
            
        });

        $j(".all-products").click(function () {
            $j(".products").removeClass("pselected");
            $j(".products .jRadioWrapper .jNiceRadio ").removeClass("jNiceChecked");
            $j(this).addClass("all-products-pselected");
            $j(".all-products .jRadioWrapper .jNiceRadio ").addClass("jNiceChecked");
            $j(this).find('input').attr("checked", true);
            $j('.sub-products').hide();
            $j('.find').hide();
            $j(this).parent().find('.sub-products').slideDown('300');
            $j(this).parent().find('.find').fadeToggle('300');
        });
        
        $j(".products .jNiceRadio").click(function () {
            $j(this).parent().parent().click();
        });   

        $j(".all-products .jNiceRadio").click(function () {
            $j(this).parent().parent().click();
        });  
     

        $j(".all-products").click(
          function () {
            $j(".search-tip").hide();
          }
        );
        $j("#bath").click(
          function () {
            $j(".search-tip").hide();
            $j(".search-tip.bath").fadeIn();
          }
        );
        $j("#papertowel").click(
          function () {
            $j(".search-tip").hide();
            $j(".search-tip.papertowel").fadeIn();
          }
        );
        $j("#napkin").click(
          function () {
            $j(".search-tip").hide();
            $j(".search-tip.napkin").fadeIn();
          }
        );        
        $j("#facial").click(
          function () {
            $j(".search-tip").hide();
            $j(".search-tip.facial").fadeIn();
          }
        );  

        
        $j("#r-allproducts").click(
          function () {
            $j(".indent").slideUp();
          }
        );  

        $j("#r-allbath").click(
          function () {
            $j(".indent").slideUp();
            $j("#bath-sub").slideDown('300');
          }
        );          
        
        $j("#r-allpapertowel").click(
          function () {
            $j(".indent").slideUp();
            $j("#papertowel-sub").slideToggle('300');
          }
        );  

        $j("#r-allnapkin").click(
          function () {
            $j(".indent").slideUp();
            $j("#napkin-sub").slideToggle('300');
          }
        );  

        $j("#r-allfacial").click(
          function () {
            $j(".indent").slideUp();
            $j("#facial-sub").slideToggle('300');
          }
        ); 
        
        $j(".jNiceRadio").click(
          function () {
            //alert("hello");
            $j(this).parent().find('input').click();
          }
        ); 

        var initialized = "no";

        $j("#calcform").submit(function() {
            $j('.calc-button').click();
            return false;
        });

        $j('#people').focus(function() {
          $j(this).val('');
        });

        $j('.calc-button').click(function() {
            
            
            //alert($j('#people').val());
            
            /*            
            $j('.oneyear').fadeOut().html(parseInt(($j('#people').val()*50*1)/117.65)+1).fadeIn();
            $j('.fiveyear').html(parseInt(($j('#people').val()*50*5)/117.65)+1);
            $j('.tenyear').html(parseInt(($j('#people').val()*50*10)/117.65)+1);
            $j('.twentyyear').html(parseInt(($j('#people').val()*50*20)/117.65)+1);
            */
            if (initialized=="yes") {
                $j('.oneyear').fadeOut('fast', function() {
                    $j(this).html(parseInt(($j('#people').val()*50*1)/117.65)+1+"<span>AFTER 1 YEAR</span>").fadeIn();
                });
                $j('.fiveyear').fadeOut('fast', function() {
                    $j(this).html(parseInt(($j('#people').val()*50*5)/117.65)+1+"<span>AFTER 5 YEARS</span>").fadeIn();
                });
                $j('.tenyear').fadeOut('fast', function() {
                    $j(this).html(parseInt(($j('#people').val()*50*10)/117.65)+1+"<span>AFTER 10 YEARS</span>").fadeIn();
                });
                $j('.twentyyear').fadeOut('fast', function() {
                    $j(this).html(parseInt(($j('#people').val()*50*20)/117.65)+1+"<span>AFTER 20 YEARS</span>").fadeIn();
                });
            }
            else {
                $j('.calcwrapper').animate({
                    height: '370px'
                }, 500, function() {
                    // Animation complete.
                });
                $j('.oneyear').delay(500).animate({
                    top: '-=10px',
                    opacity: 'show'
                }, 1000);
                $j('.fiveyear').delay(1000).animate({
                    top: '-=10px',
                    opacity: 'show'
                }, 1000);
                $j('.tenyear').delay(1500).animate({
                    top: '-=11px',
                    opacity: 'show'
                }, 1000);
                $j('.twentyyear').delay(2000).animate({
                    top: '-=11px',
                    opacity: 'show'
                }, 1000);

                $j('.recalculate_cta').delay(3000).slideDown('slow');    
                
                $j('.oneyear').html(parseInt(($j('#people').val()*50*1)/117.65)+1+"<span>AFTER 1 YEAR</span>");
                $j('.fiveyear').html(parseInt(($j('#people').val()*50*5)/117.65)+1+"<span>AFTER 5 YEARS</span>");
                $j('.tenyear').html(parseInt(($j('#people').val()*50*10)/117.65)+1+"<span>AFTER 10 YEARS</span>");
                $j('.twentyyear').html(parseInt(($j('#people').val()*50*20)/117.65)+1+"<span>AFTER 20 YEARS</span>");      
            }
            initialized="yes";
            resize();  
        });

	    $j(".find").click(function ()
		{ 
		    //alert($j("#zip").val().length);	
	
		    if( $j("#zip").val() == "")
		    {
			    //alert("null");
			    $j('.sf-error').fadeIn();
			    return false;
            }
		    else if( isNaN($j("#zip").val()))
		    {
			    //alert("null");
			    $j('.sf-error').html("ZIP code must be a number.");
			    $j('.sf-error').fadeIn();
			    return false;
            }
		    else if( $j("#zip").val().length < 5)
		    {
			    //alert("null");
			    $j('.sf-error').html("ZIP code must be 5 digits.");
			    $j('.sf-error').fadeIn();
			    return false;
            }
            else
            {
                form.submit();
            }
		});

	    $j("#zip").focus( function () 
	    {
	        //alert("focus");
	        $j('.sf-error').fadeOut();
	    });

	    $j("ul li div.norm").click( function ()
	    {
	        window.location = $j(this).find('a').attr("href");
	    });
	    
	    $j("ul li div.sel").click( function ()
	    {
	        window.location = $j(this).find('a').attr("href");
	    });
    });
    
    function divresize() {

      var white = $j('#response').height(); 
      if (white + 400 > 800)
          $j('#BodyConentWrap').height(white + 400);
      else
          $j('#BodyConentWrap').height(800);

    }