var CAL = window.CAL || {};

/**
 * @namespace Holds global functionality
 */

CAL.global = CAL.global || {};


window.CAL = window.CAL = {};

(function() { 
var Calphalon = {


  /**
  * Suckerfish method for nav dropdowns
  */
  
sfHover: function() {
	$('#nav li').each( function() 
								  
								  {
		 $(this).hoverIntent(
		    function() {
		    	$(this).addClass('sfhover');
		    },
		    function() {
		    	$(this).removeClass('sfhover');
		    }
		  );
	});
  }, // sfHover


  /**
  * Removes label from text fields    
  */
  
removeLabels: function() {
    $('.labelField').each(function() {
        var node = $(this);
        var defaultText = node.val();
        
        node.focus(function() {
  	      if($(this).val()== defaultText) {
	        $(this).val('');
	      }
          $(this).blur(function() {
            var userInput = $(this).val();
            if(userInput=='') {
              $(this).val(defaultText);
            }
          }); // blur
        }); // focus
    });
  }, // removeLabels

  
  /**
  * Opens links in New Window
  */
   
newWin : function() {
       $("a.newWin").bind("click",function(e) {
            window.open(this.href);
            e.preventDefault();
        });
   },


  /**
  * Switches between Featured Recipes
  */
     
recipeSwitch : function() {
		$('#featRecipeLinks a').click(function() {
			$('.featRecipeInfo').hide().filter(this.hash).fadeIn(400);
			
			$('#featRecipeLinks a').removeClass('selected');
			$(this).addClass('selected');
				
			return false;	
		}).filter(':first').click();
	},

 /**
	* Switches between Store Registry
 */

 regStoreSwitch : function() {
		 $('.storeGiftListLinks a').click(function() {
			 $('.storeGiftList').hide().filter(this.hash).fadeIn(400);
			
			 $('.storeGiftListLinks a').removeClass('on');
			 $(this).addClass('on');
		
			 return false;
		 }).filter(':first').click();
	 }, 

/**
  * Accordian for Pre Registry 
  */

/* Warrenty Information */
/*preRegAccordian1 : function() {
		var divID,
			preHeight,
			postHeight;
		
		$('.WarrentyInfo h3 a').click(function() {
			divID = this.hash;
			preHeight = $(divID+' .content').height();
			if ($(this).hasClass('open') != true) { 
				collapseAll();
				openHidden(divID);				
				$(this).addClass('open');			}
			else {
				$(this).removeClass('open');
				collapseAll();
			}		
			return false;
		});
		
		$('.learnMoreLnk a').click(function() {
			divID = this.hash;
			preHeight = $(divID+' .content').height();
			collapseAll();
			openHidden(divID);
			$(divID).prev('h3').children('a').addClass('open');
			return false;
		});
		
		$('.closeLnk a').click(function() {
			divID = this.hash;
			collapseAll();
			$(divID).prev('h3').children('a').removeClass('open');		
			return false;
		});
		
		function openHidden(d) {			
			$(d+' .learnMoreLnk').hide();
			$(d+' .hiddenCopy').fadeIn(300);
			$(d+' .slideCopy').slideDown(400);
			$(d+' .sectionSubList').slideDown(400).end();
		}
		
		function collapseAll() {
			$('.WarrentyInfo h3 a').removeClass('open');			
			$('.hiddenCopy').hide();
			$('.slideCopy').hide();
			$('.sectionSubList').hide();
			$('.learnMoreLnk').show();
		}
	},
*/
preRegAccordian1 : function() {
		var divID;
		
		$('.WarrentyInfo span.hiddenCopy').before('<em class="moreCopy">&hellip;</em>');
		$('.WarrentyInfo h3 a').click(function() {
			divID = this.hash;
			
			if ($(this).hasClass('open') != true) { 
				collapseAll();
				openHidden(divID);				
				$(this).addClass('open');			}
			else {
				$(this).removeClass('open');
				collapseAll();
				$('em.moreCopy').show();
			}		
			return false;
		});
		
		$('.WarrentyInfo .learnMoreLnk a').click(function() {
			divID = this.hash;
			openHidden(divID);
			$(divID).prev('h3').children('a').addClass('open');
			return false;
		});
		
		$('.WarrentyInfo .closeLnk a').click(function() {
			divID = this.hash;
			collapseHidden(divID);
			//$('#'+divID).prev('h3').children('a').removeClass('open');
			$('em.moreCopy').show();		
			return false;
		});
		
		function openHidden(d) {			
			$(d+' .learnMoreLnk').hide();
			$(d+' .hiddenCopy').not('span').fadeIn(300);
			$(d+' span.hiddenCopy').show().css('display','inline');
			$(d+' .content').animate({'height' : '730px'}, 300);
			$(d+' em.moreCopy').hide();
		}
		
		function collapseHidden(d) {
			$('.WarrentyInfo h3 a').removeClass('open');			
			$(d+' .hiddenCopy').hide();
			$(d+' .learnMoreLnk').show();
			$(d+' .content').animate({'height' : '115px'}, 300);
		}
		
		function collapseAll() {
			$('.WarrentyInfo h3 a').removeClass('open');			
			$('.hiddenCopy').hide();
			$('.learnMoreLnk').show();
			$('.WarrentyInfoContent .content').animate({'height' : '115px'}, 300);
			
		}
	},

    

preRegAccordian : function() {
		var divID,
			preHeight,
			postHeight;
		
		$('.preregistryContainer span.hiddenCopy').before('<span class="moreCopy">&hellip;</span>');
		$('.preregistryContainer h3 a').click(function() {
			divID = this.hash;
			preHeight = $(divID+' .content').height();
			if ($(this).hasClass('open') != true) { 
				collapseAll();
				openHidden(divID);				
				$(this).addClass('open');			}
			else {
				$(this).removeClass('open');
				collapseAll();
				$('span.moreCopy').show();
			}		
			return false;
		});
		
		$('.preregistryContainer .learnMoreLnk a').click(function() {
			divID = this.hash;
			preHeight = $(divID+' .content').height();
			collapseAll();
			openHidden(divID);
			$(divID).prev('h3').children('a').addClass('open');
			return false;
		});
		
		$('.preregistryContainer .closeLnk a').click(function() {
			divID = this.hash;
			collapseAll();
			$(divID).prev('h3').children('a').removeClass('open');
			$('span.moreCopy').show();		
			return false;
		});
		
		function openHidden(d) {			
			$(d+' .learnMoreLnk').hide();
			$(d+' .hiddenCopy').not('span').fadeIn(300);
			$(d+' span.hiddenCopy').show().css('display','inline');
			$(d+' .slideCopy').slideDown(400);
			$(d+' .sectionSubList').slideDown(400).end();
			$(d+' .moreCopy').hide();
		}
		
		function collapseAll() {
			$('.preregistryContainer h3 a').removeClass('open');			
			$('.hiddenCopy').hide();
			$('.slideCopy').hide();
			$('.sectionSubList').hide();
			$('.learnMoreLnk').show();
		}
	},


   
  /**
  * Initializes all global page interactions
  */
 
 _init: function() {
  	this.sfHover();
  	this.removeLabels();
  	this.recipeSwitch();
  	this.preRegAccordian();
  	this.preRegAccordian1();
  	this.regStoreSwitch();
  } // _init
  
}; // Calphalon Namespace

$(document).ready(function() {
  Calphalon._init();
  $('.sifr').sifr({
		font: '../js/lib/futuralt.swf',
		version: 3,
		build: 'beta2'
	});
});

window.CAL = Calphalon;

})();

  /**
  * Opens/Closes the Left Nav
  */

$(function() {
	$('.home').next('div').addClass('homeContainer');
	$('#leftNav > li.on').children('ul').show(); // any first-level 'li' tag in the #leftNav will be open on page load
	
	$('.topLevel').click(function() {
		var parID = $(this).parent().parent().attr('id');
		
		if(parID == 'leftNav') {
			//$('#leftNav ul').slideUp(300);
			//$(this).parent().children('ul').slideDown(750);
		
			$('#leftNav > li').removeClass('on');
			$(this).parent('li').addClass('on');
		}
		else {
			$('#leftNav2 > li').removeClass('on');
			$(this).parent('li').addClass('on');
		}
		//return false;
	});
});

/* Archive */
$(function() {
	$('#archive > li.on').children('ul').show(); // any first-level 'li' tag in the #leftNav will be open on page load
	
	$('.topLevel').click(function() {	
		var parID = $(this).parent().parent().attr('id');
		
		if(parID == 'archive') {
			$('#archive ul').slideUp(100);
			$(this).parent().children('ul').slideDown(450);
		
			$('#archive > li').removeClass('on');
			$(this).parent('li').addClass('on');
		}
		
		//return false;
	});
});

	
	
	