﻿
// Set jQuery to "noConflict" so that it doesn't conflict with other libraries that use the 
// dollar sign symbol as a shortcut (such as prototype.js)   
$.noConflict();

// Set up a shortcut variable for jQuery, "j$"    
var j$ = jQuery;

/*===============================================================*/
/*= MEGAMENU SUBSUBNAV POSITIONING                              =*/
/*===============================================================*/
/***************************************************
***		Added by Ian (Third Mind, Inc.) 1/15/2011
***		Adds support for sub sub navigation box
****************************************************/
function positionSubSubNav(row, width)
{
	j$(row).find(".subNav").each(function() {

		var id = j$(this).attr("id");
		id = id.replace("sub_", "");
		var subsubNavBoxID = "subsub_" + id;
		
		j$("#" + subsubNavBoxID).css("left", width-5);
	});
}

function positionSubSubNavTop()
{
	j$("#pantoneTopNav .sub").show();
	j$("#pantoneTopNav .subsub").show();
	
	j$("#pantoneTopNav").find(".subNav").each(function() {
	
		var id = j$(this).attr("id");
		id = id.replace("sub_", "");
		var subsubNavBoxID = "subsub_" + id;
		
		var topOff = j$(this).position().top;
		if(typeof(j$.browser.msie) != "undefined" && j$.browser.msie && j$.browser.version == "7.0")
		{
			topOff = j$("#" + subsubNavBoxID).css("top");//(topOff + j$(this).parent().parent().parent().position().top);
			//topOff = topOff - ((.4)*topOff);
		}
		else
		{
			topOff = topOff + 20;
		}
		
		//j$("#debug").append(subsubNavBoxID + " : " + topOff + "<br>");
		j$("#" + subsubNavBoxID).css("top", topOff);
	
	});
	j$("#pantoneTopNav .subsub").hide();
	j$("#pantoneTopNav .sub").hide();
}
/*=====================================================*/
/*= INITIALIZE START-UP FUNCTIONS                     =*/
/*=====================================================*/
j$(document).ready(initMegaMenu);
j$(document).ready(initProdFinder_FancyBoxStyle);
j$(document).ready(function() { positionSubSubNavTop(); });
  
/*=====================================================*/
/*= BEGIN MEGAMENU ROUTINE                            =*/
/*=====================================================*/
function initMegaMenu(event)
{
    //On Hover Over
    function megaHoverOver(){
        j$(this).find(".sub").stop().show();//fadeTo('fast', 1).show(); //Find sub and fade it in
		j$(this).find(".tab-inactive").removeClass("tab-inactive").addClass("tab");
        (function(j$) {
            //Function to calculate total width of all ul's
            jQuery.fn.calcSubWidth = function() {

                rowWidth = 0;

                //Calculate row
                j$(this).find("ul").each(function() { //for each ul...
                    rowWidth += j$(this).width(); //Add each ul's width together
                });

				if (rowWidth > 600) 
				{
					// SLH: Add an extra 10 to the width, to allow for a padding of 
					// 10 pixels.
					rowWidth += 50;
				}

				/***************************************************
				***		Added by Ian 1/15/2011
				***		Adds support for sub sub navigation box
				****************************************************/
				positionSubSubNav(this, rowWidth);
            };
        })(jQuery); 

        if ( j$(this).find(".row").length > 0 ) { //If row exists...
            var biggestRow = 0;	
            j$(this).find(".row").each(function() {	//for each row...
                j$(this).calcSubWidth(); //Call function to calculate width of all ul's
                //Find biggest row
                if(rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });

            j$(this).find(".sub").css({'width' :biggestRow}); //Set width
            j$(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin
        } else { //If row does not exist...
            j$(this).calcSubWidth();  //Call function to calculate width of all ul's
            j$(this).find(".sub").css({'width' : rowWidth}); //Set Width
        }
    }
	
    //On Hover Out
    function megaHoverOut(){
      j$(this).find(".sub").stop().hide();//fadeTo('fast', 0, function() { //Fade to 0 opactiy
	  j$(this).find(".tab").removeClass("tab").addClass("tab-inactive");
          //j$(this).hide();  //after fading, hide it
      //});
    }

	/***************************************************
	***		Added by Ian 1/15/2011
	***		Adds support for sub sub navigation box
	****************************************************/
	function megaSubSubHoverOver() {
		var id = j$(this).attr("id");
		id = id.replace("sub_", "");
		var subsubNavBoxID = "subsub_" + id;
		j$("#" + subsubNavBoxID).stop().show();//fadeTo('fast', 1).show(); 
	}

	j$("#pantoneTopNav .subsub").hover(function() {
		j$(this).data("close", true);
		j$(this).stop().show();
	});

	j$("#pantoneTopNav .subsub").mouseleave(function() {
		setTimeout(function() { megaSubSubHoverOut(); }, 50);
	});

	function megaSubSubHoverOut() {
		j$("#pantoneTopNav .subsub").each(function() {
			if(j$(this).data("close") == true)
			{
				j$(this).data("close", false);
				var id = j$(this).attr("id");
				j$("#" + id).hide();//fadeTo('fast', 0, function() { //Fade to 0 opactiy
					//j$(this).hide();  //after fading, hide it
				//});
				//j$("#" + id).hide();
			}
		});
	}

	function megaSubSubHoverOut2()
	{
		var id = j$(this).attr("id");
		id = id.replace("sub_", "");
		var subsubNavBoxID = "subsub_" + id;
		if(typeof(j$("#" + subsubNavBoxID).data("close")) == "undefined" || j$("#" + subsubNavBoxID).data("close") == false)
		{
			j$("#" + subsubNavBoxID).hide();//fadeTo('fast', 0, function() { //Fade to 0 opactiy
				//j$(this).hide();  //after fading, hide it
			//});
			//j$("#" + subsubNavBoxID).hide();
		}
	}

    //Set custom configurations
    var config = {
    sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
    interval: 10, // number = milliseconds for onMouseOver polling interval
    over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
    timeout: 50, // number = milliseconds delay before onMouseOut
    out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    };

	/***************************************************
	***		Added by Ian 1/15/2011
	***		Adds support for sub sub navigation box
	****************************************************/
	var subSubConfig = {
		sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
		interval: 10, // number = milliseconds for onMouseOver polling interval
		over: megaSubSubHoverOver, // function = onMouseOver callback (REQUIRED)
		timeout: 50, // number = milliseconds delay before onMouseOut
		out: megaSubSubHoverOut2 // function = onMouseOut callback (REQUIRED)
	};

    //j$("ul#pantoneTopNav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
    j$("ul#pantoneTopNav li").hoverIntent(config); //Trigger Hover intent with custom configurations       

	/***************************************************
	***		Added by Ian 1/15/2011
	***		Adds support for sub sub navigation box
	****************************************************/
	j$("ul#pantoneTopNav .subNav").hoverIntent(subSubConfig);
} 

/*=====================================================*/
/*= BEGIN PRODFINDER_FANCYBOXSTYLE ROUTINE            =*/
/*=====================================================*/
function initProdFinder_FancyBoxStyle()
{
    j$("a.prodFinderLinks").fancybox ({
    'width'					: 759,
    'height'				: 365,
    'scrolling'				: 'no',
    'padding'				: 0,
    'type'					: 'iframe',
    'hideOnContentClick'	: false,
    'overlayColor'			: '#416377',
    'overlayOpacity'		: 0.8
    });       
    
    j$("a#lnkProdFinder").fancybox({
    width				: 720,
    height				: 600,
    type				: 'iframe',
    hideOnContentClick	: false,
    overlayColor		: '#416377',
    overlayOpacity		: 0.8
    });
	
	CheckIfValidate();
	//callFancyBox();
}

/*=====================================================*/
/*= BEGIN CHECKIFVALIDATE ROUTINE                     =*/
/*=====================================================*/
function CheckIfValidate(){
	var hVal = j$("#ctl00_ctlFooter_cntrlSMW_hdnSelected").val();
	//console.log("Hidden Value: " + hVal);
	if(hVal == "Task Completed"){
		callFancyBox();
	}
}


/*=====================================================*/
/*= BEGIN CALLFANCYBOX ROUTINE                        =*/
/*=====================================================*/
function callFancyBox(){
	j$("a#various1").fancybox ({
		'width'					: 405,
		'height'				: 310,		
		'autoScale'             :'false',
		'scrolling'				: 'no',
		'padding'				: 0,
		'margin'				: 0,
		'top'					: 0,	
		'bottom'				: 0,	
		'left'					: 0,	
		'right'					: 0,
		'frameborder'			: 0,
		'marginwidth'			: 0,
		'marginheight'			: 0,
		'vspace'				: 0,
		'hspace'				: 0,
		'noresize'				: 'noresize',
		'position'              : 'absolute',
		'type'					: 'iframe',
		'href'					: '/Resources/newsletter/index.aspx',
		'hideOnContentClick'	: false,
		'overlayColor'			: '#416377',
		'overlayOpacity'		: 0.8
	}).trigger("click");
}

function closeFancyBox(){
   $.fancybox.close()
}
