//version 1.0; created 2/2005

var ns = (navigator.appName.indexOf('Netscape')>-1);
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
				
	function open_action_menu(evnt, q_string)
	{	
	    var callingControlID;
	    var calling_control;
		var parent_control;
		var height_of_link;
		var parent_left_x;
		var parent_left_y;
		
		if ( ns )
		{		
			callingControlID = evnt.target.id;
			calling_control = document.getElementById(callingControlID);
			parent_control = document.getElementById(callingControlID).offsetParent;
			height_of_link = evnt.target.offsetHeight;
			
			parent_left_x = findPosX(calling_control) + 'px';
			parent_left_y = findPosY(parent_control) + height_of_link + 'px';
		}
		else
		{		
			callingControlID = evnt.srcElement.id;		
			calling_control = document.getElementById(callingControlID);
			parent_control = document.getElementById(callingControlID).offsetParent;
			height_of_link = evnt.srcElement.offsetHeight;
			
			parent_left_x = findPosX(calling_control) + 10 + 'px';
			parent_left_y = findPosY(parent_control) + height_of_link  +  'px';
		}


		create_links(callingControlID, q_string)
		
		if (document.getElementById("menuDiv").style.visibility == 'hidden')
		{
			document.getElementById("menuDiv").style.left = parent_left_x; 
			document.getElementById("menuDiv").style.top = parent_left_y;
		
			document.getElementById("menuDiv").style.visibility = 'visible';
		}
		
	}
	
	function close_action_menu(evnt)
	{
		var menu_cont = document.getElementById("menuDiv");
		
		if(menu_cont.style.visibility == 'visible')
		{
			menu_cont.style.visibility = 'hidden';
		}	
	}	
		
	function browse_action_menu()
	{
		var menu_cont = document.getElementById("menuDiv");
		menu_cont.style.visibility = 'visible';
	}
	
	function create_links(sectionID, q_string)
	{	
		var section = sectionID.substring(0,4); //4 char code representing parent menu
		var id = sectionID.substring(4,sectionID.length); //# representing current item
		var menu = document.getElementById("menu_table"); 
		var gs_path = "http://www.givesimple.com/"; //path for external site
		//var gs_path = "http://localhost/thesimplegift/givesimple/";
		var sub_items;
		var rows = menu.rows.length;
			
			//delete all rows in table, so we can start a new sub_menu
			if (rows > 1)
			{	
				for(var x = 1 ; x <= rows ; x ++)
				{	
					menu.deleteRow(rows - x);
				}
			}
			
			/*rules for sub_items ..  
			  The element at the even position must be the <a> inner text while the element at the odd position 
			  will be the actual link			
			*/
			
			var session = ""
			var session1 = ""
			
			if( q_string != "" )
			{
				session = "&" + q_string
				session1 = "?" + q_string
			}

			if (section == "shop") // sub_menu categories
			{
				sub_items = ["Lounge", "products.aspx?category=4" + session, "Spa" , "products.aspx?category=1" + session, "Scent", "products.aspx?category=2" + session, "Home", "products.aspx?category=20" + session, "Kitchen", "products.aspx?category=6" + session, "Eat + Drink", "products.aspx?category=3" + session, "Paper","products.aspx?category=5" + session, "Jewels","products.aspx?category=16" + session, "Read","products.aspx?category=18" + session, "Go","products.aspx?category=17" + session, "Gift Packages" , "products.aspx?category=12" + session,"Gift Certificates","products.aspx?category=10" + session, "New Items", "new_items.aspx" + session1, "SALE!", "sale_items.aspx" + session1];
			}
			else if (section == "live") //sub_menu categories
			{
				sub_items = ["Live Simple Tips", "livesimple_tips_cat.aspx" + session1, "Eat Simple Recipes", "livesimple_recipe_cat.aspx"  + session1,  "The Gift Exchange", "giftideas/index.html"  + session1, "Occasion Reminders", "event_reminders.aspx" + session1,  "Wallpaper Calendar", "desktop.aspx"  + session1, "eThanks", "ethanks/ethanks.aspx"  + session1, "Donates" ,"donates.aspx"  + session1]
			}

			
										
			for (var x = 0 ; x < sub_items.length ; x+=2)
			{
				var row = menu.insertRow(x/2);//insert row at next position avail
												
				var cell = row.insertCell(0);//insert cell at position 0
				cell.className = 'dropdown';
			
				// create <a> 				
		    	cell.innerHTML = "<a  style='margin-left:5px;text-decoration:none;color:#666666'  href=" + (gs_path+sub_items[x+1]+id) + ">"+ sub_items[x] +"</a>"; 
			
    		}
			
			//alert(menu.innerHTML)
	}	
	
	function rollover_effect(evnt)
	{
		var cell;
		var link; 
		var sourceIsTable = false;
			
		if ( ns ) //user is using Netscape
		{		
			if ( evnt.target.tagName == "TABLE" )//<table> is the element producing the event
			{
				sourceIsTable = true;
			}
			else if ( evnt.target.tagName == "TD" ) //<td> is the element producing the event
			{
				cell = evnt.target;
				link = evnt.target.firstChild;
				window.status = link.href;
			}	
			else //<a> is the elemnt producing the event
			{
				cell = evnt.target.parentNode;
				link = evnt.target;	
			}
			document.body.style.cursor = 'pointer';
		}
		else //user is using ie
		{			
			if ( evnt.srcElement.tagName == "TABLE" )//<table> is the element producing the event
			{
				sourceIsTable = true;	
			}
			else if ( evnt.srcElement.tagName == "TD" ) //<td> is the element producing the event
			{
				cell = evnt.srcElement;
				link = evnt.srcElement.firstChild;
				window.status = link.href;
			}	
			else //<a> is the elemnt producing the event
			{
				cell = evnt.srcElement.parentNode;
				link = evnt.srcElement;	
			}	
			//document.body.style.cursor = 'hand';
		}			

			if ( link != null )
			{
				if ( link.href != null ) 
				{	
					if( evnt.type == "mouseover" && !sourceIsTable  )
					{ 
						cell.style.backgroundColor = "#E6F8FF";
						link.style.color = "#0066cc";						
					}
					else if ( evnt.type == "mouseout" )
					{ 	
						cell.style.backgroundColor = "#FFFFFF";
						link.style.color = "#666666";
						window.status = "";	
						document.body.style.cursor = "";	
					}
				}			
			}
	}

function process_cell_click(evnt)
{
	var url;
	var calling_link;
	
	if ( ns )
	{	
		calling_link = evnt.target.firstChild;
	}
	else
	{
		calling_link = evnt.srcElement.firstChild;
	}
	
	if ( calling_link != null )
	{
		if (  calling_link.href != null ) 
		{
			if ( calling_link.href == "javascript:void(0)" ) //processing javascript function
			{	
				calling_link.click();
			}
			else //processing normal href
			{	
				location.href = calling_link;
			} 
		}
	}	
}

//found at http://www.quirksmode.org/js/ *********************
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			obj = obj.offsetParent;
			curtop += obj.offsetTop		
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
//**************************************************************

