﻿var currentDropdown = null;
var gNavId = null;
var gNavList = null;
var activePage = null;
var setActiveClass = null;
var setInactiveClass = null;
var containerHeight = null;
var isTabInitalLoad = true;

$(window).resize(function() {
    setFooterHeight();
});

$(window).load(function()
{
    
    // transparent png fix
    $('body').supersleight();
    $('body').supersleight({shim: '/Style%20Library/Rotozip/Images/transparent.gif'});
    
    // sets the height of the footer based on the size of the browser
    setFooterHeight();
    
    $('#global-nav > ul > li').hover(function(e) {
        gNavList = $(this);
        gNavId = $(this).attr('id');
        navMouseOver(e);
    }, function(e) {
        navMouseOut(e);
    });
    
    
    // sets hover on the Cutting Solution button
    if($('#cutting-solution-button').length)
    {
        $('#cutting-solution-button > a > img').hover(function(e){
            $(this).css('margin-top', '-28px');
        }, function(e){
            $(this).css('margin-top', '0px');
        });
    }
        
        
    // sets hover on products secondary landing page (product pages)
    // functionality is in jquery.product.popup.js
    if($('.product-container').length)
        setProductRollovers();
    
    // sets the side items to slide down  
    // functionality is in jquery.sidebar.slide.js
    if($('#side-items-container').length)
    {
        setSideItemDropdown();
        setWatermark();
    }   
    // sets cutting tools product detail tabs
    // functionality is in jquery.tabrollover.js 
    if($('#cutting-tools-tabs').length)
        setCuttingToolsTabsFunctionality();
        
    // sets cutting tools product detail tabs
    // functionality is in jquery.tab.rollover.js
  //  if($('#accessories-attachment-tabs').length)
    //    setAccessoriesTabsFunctionality();
    
     // sets the secondary navigation
    // functionality is in jquery.navigation.secondary.js
    if($('#secondary-navigation-container').length)
        setSeondaryNavigationRollover();

        
    // sets the right column video overlay  
    if($('#video-dropdown').length)
        $(".video-click").colorbox({iframe:true, innerWidth:499, innerHeight:309});
        
    if($('.section-callout-box').length)
    {
    	$('.section-callout-box').css('background-color', '#d4d4d4');
       // $('.section-callout-box').css('cursor', 'pointer');
       // $('.section-callout-box').hover(function(e){
       //     $(this).css('background-color', '#cccccc');
       // }, function(e){
       //     $(this).css('background-color', '#d4d4d4');
       // });
    }
    
    if($('.thumbnail-image').length)
    {
        $('.thumbnail-image').css('cursor', 'pointer');
    }
    
    
    // BATCH 2
    // sets the secondary navigation
    // functionality is in jquery.cutting.solution.js
    if($('#cutting-solutions-container').length || $('#cutting-solutions-results-container').length)
        setCuttingSolutions();
        
    // sets the secondary navigation under the support section
    // functionality is in jquery.support.navigation.secondary.js
    if($('#support-content-container').length) {
        setSupportSecondaryNavRollover();
        setSupportSecondaryNavActive();
    }
        
    // sets all of the functionality of the Identify your bits page
    // functionality is in jquery.identify.bit.js
   
	if($('#identify-your-bit-container').length)
	    setBitsFunctionality(); 
	                      
    // sets video thumbnail hover
    if($('.video-thumbails').length)
    {
        $('.video-thumbails').children('.thumbnail').hover(function(e){
            $(this).children('p').css('color', '#ffffff');
        }, function(e){
            $(this).children('p').css('color', '#333333');
        });
    }
    
    // set global nav top position dynamically
    setGlobalNavTopPosition();   
        
});

function navMouseOver(event)
{
    setActiveClass = "nav-" + $(gNavId).selector + "-active";
    setInactiveClass = "nav-" + $(gNavId).selector;
    
    // Sets the navigation background glow
   // if($(gNavList).hasClass('nav-small'))
     //   $(gNavList).css('background', 'url(/Style%20Library/Rotozip/Images/header-nav-active-small-background.png) no-repeat 0px bottom');
    //else
      //  $(gNavList).css('background', 'url(/Style%20Library/Rotozip/Images/header-nav-active-large-background.png) no-repeat 10px bottom');
        
    // checks to see if you are on an active page to set a variable so
    // when the user rolls off the navigation...it will not remove the active state
    if($(gNavList).hasClass(setActiveClass))
        activePage = $(gNavId).selector;
        
    // sets active class
    $(gNavList).removeClass(setInactiveClass).addClass(setActiveClass);
   
    // checks to see if it is one of the two sections that have a dropdown and will display the dropdown menu
    switch(gNavId)
    {
        case "cutting-tools" :
            $('#cutting-tools-menu').center();
            $('#cutting-tools-menu').hoverFlow(event.type, {
              'height': 'show',
              'marginTop': 'show',
              'marginBottom': 'show',
              'paddingTop': 'show',
              'paddingBottom': 'show' 
            }, 'fast');
            
            currentDropdown = $('#cutting-tools-menu');
            setSecondaryNav();
        break;
        case "accessories-attachments" :
            $('#accessories-attachments-menu').center();
            $('#accessories-attachments-menu').hoverFlow(event.type, {
              'height': 'show',
              'marginTop': 'show',
              'marginBottom': 'show',
              'paddingTop': 'show',
              'paddingBottom': 'show' 
            }, 'fast');
            
            currentDropdown = $('#accessories-attachments-menu');
            setSecondaryNav();
        break;
        default : 
            currentDropdown = null;
        break;
    }
}

function navMouseOut(event)
{
 //if($(gNavList).hasClass('nav-small'))
   //     $(gNavList).css('background', 'url(/Style%20Library/Rotozip/Images/header-nav-active-small-background.png) no-repeat 0px -70px');
    //else
      //  $(gNavList).css('background', 'url(/Style%20Library/Rotozip/Images/header-nav-active-large-background.png) no-repeat 10px -70px');
    if(gNavId != activePage)
        $(gNavList).removeClass(setActiveClass).addClass(setInactiveClass);
    
    // Resets the navigation background glow to a hidden state
    if(currentDropdown != null)
    {
        $(currentDropdown).hoverFlow(event.type, {
          'height': 'hide',
          'marginTop': 'hide',
          'marginBottom': 'hide',
          'paddingTop': 'hide',
          'paddingBottom': 'hide' 
        }, 'fast');
        
        currentDropdown = null;
    }
}

function setSecondaryNav()
{   
    // Sets the dropdown functionality 
    $(currentDropdown).children('dl').css('cursor', 'pointer');
    
    $(currentDropdown).children('dl').hover(function(){
        $(this).css('background-position', '0px -213px');
    }, function() {
        $(this).css('background-position', '0px 0px');
    });
}

function setFooterHeight()
{
    var marginTop;
    var containerId;
    var contentContainerId = null;
    
    // getting/setting the page's current container id and content copy container
    if($('#secondary-landing-content').length)
    {
        containerId = $('#secondary-landing-content');
        contentContainerId = $('#content-background');
        $(contentContainerId).removeAttr('style');
    }
    else if ($('#detail-landing-content').length)
    {
        containerId = $('#detail-landing-content');
        contentContainerId = $('#product-description-container');
        $(contentContainerId).removeAttr('style');
    }
    else if ($('#search-results-content').length)
    {
    	containerId = $('#search-results-content');
    	contentContainerId = $('#content-background');
    	$(contentContainerId).removeAttr('style');
    }
    else
    {
        containerId = $('#content');
    }
    
    var footerHeight    = $('#footer').height();
    var headerHeight    = $('#header').height();
    var browserHeight   = $(window).height();
    var contentHeight   = containerId.height() + 3;
        
    var documentHeight =  headerHeight + contentHeight + footerHeight;
    
    if(browserHeight >= documentHeight && contentContainerId != null)
    {
        containerHeight = $(contentContainerId).height() + (browserHeight - documentHeight);
        contentContainerId.css('height', containerHeight+'px');
    }
    else if(browserHeight > documentHeight)
    {
        marginTop = browserHeight - documentHeight;
        $('#footer').css('margin-top', marginTop+'px');
    }
    else
    {
        // default
    }
}

function pageRedirect(pageURL)
{
    $(window.location).attr('href', pageURL);
}

// centers the dropdown navigation on the page
jQuery.fn.center = function () {
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

  function SetVideoOverlay()
        {
          $(".video-click").colorbox({inline: true,scrolling: false, href: '#video-overlay', innerWidth: 499, innerHeight: 309 });
          }
        

function colorBox(divId)
{
    var id = "#" + divId;
    $.colorbox({ width: "596", height: "349", inline: true,scrolling: false, href: id });
    
    $('.overlay-close').hover(function(){
        $(this).children('img').css('margin-top', '-14px');
    }, function() {
        $(this).children('img').css('margin-top', '0px');
    });
}

function setGlobalNavTopPosition() {
	var navTop = $('#header').offset().top + $('#header').height() - 7;
	$('div#cutting-tools-menu, div#accessories-attachments-menu').css('top', navTop);
}

function Emdswf(videourl,divId)
{
var id = "#div" + divId;


//swfobject.embedSWF(videourl,divId, "499", "284", "9.0.0", "/Style Library/Rotozip/flash/expressInstall.swf");
$.colorbox({inline: true,scrolling: false, href: id, innerWidth: 499, innerHeight: 309 });
}
	
function resizeCallouts(calloutDescriptors) {
   var callouts = $(calloutDescriptors);
   var maxHeight = 0;
   callouts.each(function () {
      if ($(this).height() > maxHeight) {
         maxHeight = $(this).height();
      }
   });
   callouts.each(function () {
      $(this).height(maxHeight);
   });	  
}

