/* Information -------------------------------------

Version: 0.1.22

Include on: All HermanMiller.com Templates

Contains:
	=DOM Ready Functions
		=>Initialize Tabs
		=>Initialize Custom Scroll Pane
		=>Initialize Rotators
		=>Initialize Carousels
		=>Product Detail Hero Nav Menu Click
		=>Initialize Slideshow
		=>Initialize Modal Windows
		=>Initialize Show/Hide Toggle
		=>Source Link Click with Page Scroll
		=>Initialize Product Hero Captions
		=>Initialize Equal Height Columns
		=>Initialize Hover Switcher
		=>Initialize Custom Select
		=>Initialize Position Results Found : IE7 Only
----------------------------------------------------*/



/* =DOM Ready Functions */
$(function(){
	// Open Links in New Window via rel="external"
	$('a[rel="external"]').click(function(){this.target = "_blank";});
	
	// Initialize Input Blur
	$('.customInput input').inputBlur();

	// Initialize Tabs	
	var isEditMode = typeof(isPreviewMode) != 'undefined' ? !isPreviewMode : false;
	if (($('.tabWrap').length || $('.navSide').length) && !isEditMode) {
		$('.tabWrap').initTabs();
		//Add Point to Tab Nav
		if ( $('.navTab.point').length ) {
			$('.navTab.point').addTabPoint();
		}
	} else if (isEditMode) {
		$('.navTab a').click(function(e) {
			e.preventDefault();
		});
		$('.tabContent .parsys').show();
	}

    /**
     * Initialize Custom Scroll Pane for visible, non-initialized .scrollPane containers
     * @author blackwell
     */ 
    $('.scrollPane:visible:not(:has(.jspContainer))').jScrollPane();
	
	// Initialize Rotators
	$('.rotatorWrap').each(function() {
		if ( $(this).hasClass('homeHero') ) {
			$(this).rotator({
				animation: 'horizontal-push',
				timer: true,
				randomizer: true,
				beforeChange: function(){

				},
				afterChange: function(){

				}
			});
		} else if ( $(this).hasClass('productHero') ) {
			$(this).rotator({
				animation: 'horizontal-push',
				beforeChange: function(){

				},
				afterChange: function(){

				}
			});
		} else {
			$(this).rotator({
				bulletNav: true,
				beforeChange: function() {

				},
				afterChange: function() {

				}
			});
		}
	});

	// Initialize Carousels
    $('.carouselWrap:visible').carousel();
	
	// Product Detail Hero Nav Menu Click
	if ( !$('.productHero #insetBlock').hasClass('init') ) {
		$('#insetBlock').addClass('init');
	
		// Toggle visibility of Product Nav
		$('#insetBlock').delegate('.toggle','click', function(){
			$(this).prev('#navProduct').slideToggle();
			$(this).toggleClass('hide').text($(this).text() == 'Hide Menu' ? 'Show Menu' : 'Hide Menu');
			return false;
	    });
	
		//If coming from the Home Segment, collapse the Product Nav
		if (document.referrer.indexOf("/Home") != -1) {	    
			$('#insetBlock a.toggle').click();
		}	
	}
	
	// Initialize Slideshow
	$('.slideshowWrap').slideShow();
	
	// Initialize Modal Windows
	$('.openModal,.openVideo').modalWin('.modalWin');
	
	// Initialize Inline Videos
	$('a.videoInline').videoInline();

    // initializes all visible videos
    $('video').initVideo();
    
    // Initialze Show/Hide Toggle
	$('.expandable, .expandableText').showHideToggle();
    
    // Source Link Click with Page Scroll
	$('a[href*="#source"]').click(function(){
		if ( $('.expandableText').length && $('.expandableText .second').is(':hidden') ) {
			$('.showHide').click();
		}
		$(this).scrollPage();
		return false;
	});
	
	// Initialize Product Hero Captions
	$('.productHero .slide').heroImgCaptions();
	
	// Initialize Equal Height Columns
	$('.cols3-980 > div').setAllToMaxHeight();
	$('.cols4-980 > div').setAllToMaxHeight();
	
	// Initialize Hover Switcher
	$('.hoverSwitcher').hoverSwitcher();
	
	// Initialize Custom Select
	$('.customSelect').customSelect();
	
	// Initialize Position Results Found : IE7 Only
	if ($.browser.msie && $.browser.version == 7) {
		$('.resultsBar.thick .resultsFound').posResultsFound();
	};
    
});
