﻿

/* keeps parent list item selected when hovering over a drop down menu */
Event.observe( window, "load", function( evt )
{
	// setNav is for IE6 bug
	setNav();
	
	$$( "div.nav ul ul" ).each( function( item )
	{
		Event.observe( item, 'mouseover', function( evt )
		{
			item.up('li').down('a').className='on';
		} );

		Event.observe( item, 'mouseout', function( evt )
		{
			item.up('li').down('a').className='';
		} );
	} );
} );

var setNav = function()
{
	$$( 'div.nav ul li' ).each( function( item )
		{
			item.onmouseover = function()
			{
				item.className += " over";	
			}
			item.onmouseout = function()
			{
				item.removeClassName( "over" );	
			}
		} );		
}


function pleaseWait(btn, on){
	if (on) {
		if ($(btn)) {
				$(btn).disabled = true;
				$(btn).value = "Please Wait...";
		}
	}
	else {
		if ($(btn)) {
			$(btn).disabled = false;
		}
	}
}



/**************************************************************
	for left nav content
***************************************************************/	
var activeSubMenu = "";
var activeMenu = "";
var isProduct = false;

function hideall() {
	$$('.content').each(function(item){
		item.hide();
	});
}

function toggleDiv(divid, productId) {
	
	hideall();
	
	switch( divid )
	{
	    case "products":
            
	        $j(".product").show();
	        $(divid).show();
	        $(divid).down("div").show();
	        $j(".col-one").show();
	        activeMenu = "menu_products";
	        activeSubMenu = "subMenu_products";
	        break;
			
		case "readyToHang":
		case "cardsStationery":
		case "homeOffice":
		case "jewelry":
		case "holiday":
		case "games":
		case "apparel":
		case "travel":
		case "photobooks":
		case "pressPrints":
		case "prints":

		    $("products").show();
		    $j(".product").show();
		    $(divid).show();
		    activeMenu = "menu_products";
		    if (productId) {
		        $j(".product").hide();
		        $j("#" + divid + " #" + productId).show();
		    }
		    activeSubMenu = "subMenu_products";
		    break;
		
		case "contentLibrary":
		case "mothersDay":
		case "holiday":
		case "valentinesDay":
		case "thankYouNotes":
		case "invitations":
		case "announcements":
		
			$(divid).show();
			activeMenu = "menu_contentLibrary";
			activeSubMenu = "subMenu_contentLibrary";
			
			break;
			
		default:
		
			$(divid).show();
			activeMenu = "";
			activeSubMenu = "";
	        $j(".col-one").hide();
	}
	
	if( $( activeMenu ) )
	{
		$( activeMenu ).className = "subList";	
	}
	
	if( $( activeSubMenu ) )
	{
		$( activeSubMenu ).show();
	}

}

function goToAnchor(defaultContentDiv) {

	var anchor = window.location.hash;

	var anchorTag = anchor.sub('#','');
	var contentDiv = anchorTag.sub(/-.+$/,'');
	var nav = contentDiv + '-Nav';

	// open the nav section
	if ($(nav)) {
		g_leftNav.activate($(nav));
	}

	// show the "page"
	contentDiv = $(contentDiv) ? contentDiv : defaultContentDiv;
	toggleDiv(contentDiv);

	// scroll to the anchor point
	//window.location.href = anchor;
}
