/* Remove IE6 image flickering */
try
{
	document.execCommand ('BackgroundImageCache', false, true);
}
catch (error) {}

/* Sets the delay for starting setHeaderSearch */
function setPrimaryNavInit ()
{
	var delay = setTimeout (setPrimaryNav, 10);
}

/* Sets the header search toggling functionality */
function setPrimaryNav ()
{
	var topnav = document.getElementById ('topnav');
	if (topnav)
	{
		var navUl = topnav.getElementsByTagName ('ul').item (0);
		if (navUl)
		{
			function processNavEvents (event, state)
			{
				var delay;
				var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
				if (eventSource.nodeName != 'LI')
				{
					eventSource = eventSource.parentNode;
				}
				if (state == 1)
				{
					if (delay)
					{
						clearTimeout (delay);
					}
						eventSource.className += (eventSource.className == '' ? '' : ' ') + 'active';
				}
				else
				{
					delay = setTimeout (function ()
					{
							eventSource.className = eventSource.className.replace (/ ?active/g, '');
					}, 1);
				}
			}
			
			tii_dom_removeWhitespaceTextNodes (navUl);
			var navLis = navUl.childNodes;
			var navLisLength = navLis.length;
			for (var i = 0; i < navLisLength; i++)
			{
				var navLi = navLis.item (i);
				tii_addEventHandler (navLi, 'mouseover', function (event)
				{
					processNavEvents (event, 1);
				}, false);
				tii_addEventHandler (navLi, 'mouseout', function (event)
				{
					processNavEvents (event, 0);
				}, false);
			}
		}
	}
}

/* Sets the delay for starting setHeaderSearch */
function setHeaderSearchInit ()
{
	var delay = setTimeout (setHeaderSearch, 10);
}

/* Sets the header search toggling functionality */
function setHeaderSearch ()
{
	var searchRoot = document.getElementById ('search');
	var searchSiteBox;
	if (searchRoot)
	{
		searchContent = searchRoot.getElementsByTagName ('div').item (1);
	}
	var search_this_site_form = document.getElementById ('search_this_site_form');
	var search_this_site = document.getElementById ('search_this_site');
	var search_this_site_inactive = document.getElementById ('search_this_site_inactive');
	var search_recipes = document.getElementById ('search_recipes');
	var search_recipes_inactive = document.getElementById ('search_recipes_inactive');
	var search_this_site_image = document.getElementById ('search_this_site_image');
	var actionNumber = 1;
	if (search_this_site_form && searchContent && search_this_site && search_this_site_inactive && search_recipes && 
		search_recipes_inactive && search_this_site_form && search_this_site_image)
	{
		function processAnchorClick (event, state)
		{
			if (event.type == keyevent && event.keyCode != 13)
			{
				return false;
			}
			switch (state)
			{
				case 1:
					search_this_site.style.cursor = 'default';
					search_this_site.style.display = 'block';
					search_this_site_inactive.style.display = 'none';
					search_recipes.style.display = 'none';
					search_recipes_inactive.style.display = 'block';
					actionNumber = 1;
					break;
				case 3:
					search_recipes.style.cursor = 'default';
					search_recipes.style.display = 'block';
					search_recipes_inactive.style.display = 'none';
					search_this_site.style.display = 'none';
					search_this_site_inactive.style.display = 'block';
					actionNumber = 2;
					break;
			}
		}

		search_this_site.style.cursor = 'default';
		search_this_site.href = 'javascript: {}';
		search_this_site_inactive.href = 'javascript: {}';
		search_recipes.href = 'javascript: {}';
		search_recipes_inactive.href = 'javascript: {}';
		
		function processImageSubmit (event)
		{
			tii_stopDefaultAction (event);
			if (actionNumber == 1)
			{
				search_this_site_form.submit ();
			}
			else
			{
				var queryEl = document.getElementById ('search_this_site_box');
				var query = '';
				if (queryEl && queryEl.value)
				{
					query = queryEl.value;
				}
				else
				{
					return false;
				}
				var publicationsEl = document.getElementById ('search_publications');
				var publications = '';
				if (publicationsEl && publicationsEl.value)
				{
		/*	                      if (publicationsEl.value == 'Coastal Living')
{
	publications = '&N=' + '4294959826';
}
else if (publicationsEl.value == 'Cottage Living')
{
	publications = '&N=' + '4294959779';
}
else if (publicationsEl.value == 'Southern Living')
{
	publications = '&N=' + '4294959881';
}
else if (publicationsEl.value == 'Cooking Light')
{
	publications = '&N=' + '4294959874';
}
else if (publicationsEl.value == 'Sunset')
{
	publications = '&N=' + '4294959838';
}	*/

publications = '&type=et:' + publicationsEl.value + ';'	
                                }
window.open ('http://search.myrecipes.com/search.html?Ntt=' + escape (query)+publications, 'searchRecipesResults');
			}
		}
		
		tii_addEventHandler (search_this_site, 'click', function (event)
		{
			processAnchorClick (event, 0);
		}, false);
		tii_addEventHandler (search_this_site_inactive, 'click', function (event)
		{
			processAnchorClick (event, 1);
		}, false);
		tii_addEventHandler (search_recipes, 'click', function (event)
		{
			processAnchorClick (event, 2);
		}, false);
		tii_addEventHandler (search_recipes_inactive, 'click', function (event)
		{
			processAnchorClick (event, 3);
		}, false);
		var keyevent = tii_issafari || tii_isie ? 'keydown' : 'keypress';		
		tii_addEventHandler (search_this_site, keyevent, function (event)
		{
			processAnchorClick (event, 0);
		}, false);
		tii_addEventHandler (search_this_site_inactive, keyevent, function (event)
		{
			processAnchorClick (event, 1);
		}, false);
		tii_addEventHandler (search_recipes, keyevent, function (event)
		{
			processAnchorClick (event, 2);
		}, false);
		tii_addEventHandler (search_recipes_inactive, keyevent, function (event)
		{
			processAnchorClick (event, 3);
		}, false);
		tii_addEventHandler (search_this_site_image, 'click', function (event)
		{
			processImageSubmit (event);
		}, false);
	}
}

function tii_dom_createElement (nodeName, attributes)
{
	var isopera = typeof window.opera != 'undefined';
	var isie = typeof document.all != 'undefined'
   		&& !isopera && navigator.vendor != 'KDE';
		
	var newElement;
	try
	{
		newElement = document.createElement (nodeName);
	}
	catch (error)
	{
		return null;
	}
	
	var attributesLength = attributes.length;
	for (var i = 0; i < attributesLength; i++)
	{
		var attribute = attributes [i] [0];
		var value = attributes [i] [1];
		newElement.setAttribute (attribute, value);
		switch (attribute)
		{
			case 'id':
				newElement.id = value;
				break;
			case 'class':
				if (isie)
				{
					newElement.setAttribute ('className', value);
				}
				newElement.className = value;
				break;
			case 'style':
				newElement.style.cssText = newElement.style.cssText + ' ' + value;
				break;
			case 'for':
				if (isie)
				{
					newElement.setAttribute ('htmlFor', value);
				}
				newElement.htmlFor = value;
		}
	}
	
	return newElement;
}


function tii_dom_removeWhitespaceTextNodes (node)
{
  for (var x = 0; x < node.childNodes.length; x++)
  {
    var child = node.childNodes [x];
    if (child.nodeType == 3 && !/\S/.test (child.nodeValue))
    {
      node.removeChild (node.childNodes [x]);
      x--;
    }
    if (child.nodeType == 1)
    {
      tii_dom_removeWhitespaceTextNodes (child);
    }
  }
}

function tii_callFunctionOnWindowLoad (functionToCall)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener ('load', functionToCall, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener ('load', functionToCall, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent ('onload', functionToCall);
  }
  else
  {
    var oldFunctionToCall = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = functionToCall;
    }
    else
    {
      window.onload = function ()
      {
        oldFunctionToCall ();
        functionToCall ();
      };
    }
  }
}


function tii_callFunctionOnElementLoad (targetId, functionToCall)
{
	var myArguments = arguments;
	tii_callFunctionOnWindowLoad (function ()
		{
			window.loaded = true;
		});
	var targetElement = document.getElementById (targetId);
	if (targetElement == null && !window.loaded)
	{
		var pollingInterval = setInterval (function ()
			{
				if (window.loaded)
				{
					clearInterval (pollingInterval);
				}
				targetElement = document.getElementById (targetId);
				if (targetElement != null)
				{
					clearInterval (pollingInterval);
					var argumentsTemp = new Array ();
					var argumentsTempLength = myArguments.length - 2;
					for (var i = 0; i < argumentsTempLength; i++)
					{
						argumentsTemp [i] = myArguments [i + 2];
					}		
					functionToCall.apply (this, argumentsTemp);
				}
			}, 10);
	}
}


function tii_addEventHandlerOnElementLoad (targetId, eventType, functionToCall, bubbleEventUpDOMTree)
{
	tii_callFunctionOnWindowLoad (function ()
		{
			window.loaded = true;
		});
	var targetElement = document.getElementById (targetId);
	if (targetElement == null && !window.loaded)
	{
		var pollingInterval = setInterval (function ()
			{
				if (window.loaded)
				{
					clearInterval (pollingInterval);
				}
				targetElement = document.getElementById (targetId);
				if (targetElement != null)
				{
					clearInterval (pollingInterval);
					tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree);
				}
			}, 10);
	}
}


function tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree)
{
  if (!targetElement)
  {
	  window.status = 'Warning: Tried to attach event to null object';
	  return false;
  }
  if (typeof targetElement.addEventListener != 'undefined')
  {
    targetElement.addEventListener (eventType, functionToCall, bubbleEventUpDOMTree);
  }
  else if (typeof targetElement.attachEvent != 'undefined')
  {
    targetElement.attachEvent ('on' + eventType, functionToCall);
  }
  else
  {
    eventType = 'on' + eventType;
    if (typeof targetElement [eventType] == 'function')
    {
      var oldListener = targetElement [eventType];
      targetElement [eventType] = function ()
      {
        oldListener ();
        return functionToCall ();
      }
    }
    else
    {
      targetElement [eventType] = functionToCall;
    }
  }

  return true;
}



function tii_removeEventHandler (targetElement, eventType, functionToRemove, bubbleEventUpDOMTree)
{
  if (typeof targetElement.removeEventListener != "undefined")
  {
    targetElement.removeEventListener (eventType, functionToRemove, bubbleEventUpDOMTree);
  }
  else if (typeof targetElement.detachEvent != "undefined")
  {
    targetElement.detachEvent ("on" + eventType, functionToRemove);
  }
  else
  {
    targetElement ["on" + eventType] = null;
  }
  
  return true;
}

function tii_stopDefaultAction (event)
{
	event.returnValue = false;
	if (typeof event.preventDefault != 'undefined')
	{
		event.preventDefault ();
	}
}

/* ads functions from adwrapper.js */
function adSetTarget() {}
function htmlAdWH() {}

function adSetType() {} 


function PlayIt(what){
document.getElementById('music').innerHTML=
'<embed '
+'width="100" height="20" '
+'src="'+what+'" type="audio/x-mpeg"  name="myAudio" EnableJavascript="TRUE"  AUTOPLAY="TRUE" CONTROLLER="TRUE">'
+'</embed>';
}
function StopIt(anObj){
anObj.Stop();
document.getElementById('music').innerHTML='';
}

