var persistmenu="yes" // "yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" // enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj)
{
	if(document.getElementById)
	{
		var el = document.getElementById(obj);
		var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
		if(el.style.display != "block")
		{ 
			for (var i=0; i<ar.length; i++)
			{
				if (ar[i].className=="submenu") 
					ar[i].style.display = "none";
			}
			el.style.display = "block";
		}
		else
		{
			el.style.display = "none";
		}
	}
}

function resetmenu()
{
	if(document.getElementById)
	{
		var n = 1;
		while (document.getElementById('sub' + n) != null)
		{
			var el = document.getElementById('sub' + n);
			el.style.display = "none";
			n++;
		}
	}
}

function get_cookie(Name) 
{ 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search)
		if (offset != -1) 
		{ 
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
				returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function onloadfunction()
{
	if (persistmenu=="yes")
	{
		var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
		var cookievalue=get_cookie(cookiename)
		if (cookievalue!="")
			document.getElementById(cookievalue).style.display="block"
	}
}

function savemenustate()
{
	var inc=1, blockid=""
	while (document.getElementById("sub"+inc))
	{
		if (document.getElementById("sub"+inc).style.display=="block")
		{
			blockid="sub"+inc
			break
		}
		inc++
	}
	var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
	var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
	document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
	window.addEventListener("load", onloadfunction, false)
else 
	if (window.attachEvent)
		window.attachEvent("onload", onloadfunction)
	else 
		if (document.getElementById)
			window.onload=onloadfunction
if (persistmenu=="yes" && document.getElementById)
	window.onunload=savemenustate

function MM_swapImgRestore() 
{ //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{ //v3.0
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0)
		{ 
			d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// open window 
function openwin(strWindow)
{ 
	window.open(strWindow, '_self');
}

// swap image by click (finame.ext -> filename(2).ext -> filename.ext)
function chImage(imgname) 
{
	return 0;
	var imgsrc = document.images[imgname].src;
	var x = imgsrc.length;
	while((imgsrc.substring(x,x-1)) != ".") { x--; } var clipend = x;
	while((imgsrc.substring(x,x-1)) != "/") { x--; } var clipstart = x;
	var imgname_name = imgsrc.substring(clipend-1,clipstart);
	var imgname_ext = imgsrc.substring(imgsrc.length, clipend-1);
	if (imgname != imgname_name)
	{ document.images[imgname].src = "/img/" + imgname + imgname_ext; }
	else 
	{ document.images[imgname].src = "/img/" + imgname + "(2)" + imgname_ext; }
}

function preload()
{
	MM_preloadImages(			// preload main menu images
		'/img/center.jpg',
		'/img/center-o.jpg',
		'/img/center-about.jpg',
		'/img/center-about-o.jpg',
		'/img/center-address.jpg',
		'/img/center-address-o.jpg',
		'/img/center-photo.jpg',
		'/img/center-photo-o.jpg',
		'/img/integralyoga.jpg',
		'/img/integralyoga-o.jpg',
		'/img/library.jpg',
		'/img/library-o.jpg',
		'/img/library-audio.jpg',
		'/img/library-audio-o.jpg',
		'/img/library-photo-video.jpg',
		'/img/library-photo-video-o.jpg',
		'/img/library-text.jpg',
		'/img/library-text-o.jpg',	
		'/img/library-yoga-art.jpg',
		'/img/library-yoga-art-o.jpg',
		'/img/library-humor.jpg',
		'/img/library-humor-o.jpg',
		'/img/link.jpg',
		'/img/link-o.jpg',
		'/img/main.jpg',
		'/img/main-o.jpg',
		'/img/practice.jpg',
		'/img/practice-o.jpg',
		'/img/practice-dharma.jpg',
		'/img/practice-dharma-o.jpg',
		'/img/practice-mantra.jpg',
		'/img/practice-mantra-o.jpg',
		'/img/practice-meditation.jpg',
		'/img/practice-meditation-o.jpg',
		'/img/practice-pranayama.jpg',
		'/img/practice-pranayama-o.jpg',
		'/img/practice-antahkarana-o.jpg',
		'/img/practice-antahkarana.jpg',
		'/img/seminar.jpg',
		'/img/seminar-o.jpg',
		'/img/project.jpg',
		'/img/project-o.jpg');
}

function preload_en()
{
	MM_preloadImages(			// preload main menu images for english version
		'/en/img/main.jpg',
		'/en/img/main-o.jpg',
		'/en/img/integralyoga.jpg',
		'/en/img/integralyoga-o.jpg',
		'/en/img/practice.jpg',
		'/en/img/practice-o.jpg',
		'/en/img/practice-dharma.jpg',
		'/en/img/practice-dharma-o.jpg',
		'/en/img/practice-mantra.jpg',
		'/en/img/practice-mantra-o.jpg',
		'/en/img/practice-meditation.jpg',
		'/en/img/practice-meditation-o.jpg',
		'/en/img/practice-pranayama.jpg',
		'/en/img/practice-pranayama-o.jpg',
		'/en/img/practice-antahkarana-o.jpg',
		'/en/img/practice-antahkarana.jpg',
		'/en/img/seminar.jpg',
		'/en/img/seminar-o.jpg',
		'/en/img/project.jpg',
		'/en/img/project-o.jpg',
		'/en/img/centre.jpg',
		'/en/img/centre-o.jpg',
		'/en/img/centre-about.jpg',
		'/en/img/centre-about-o.jpg',
		'/en/img/centre-address.jpg',
		'/en/img/centre-address-o.jpg',
		'/en/img/centre-photo.jpg',
		'/en/img/centre-photo-o.jpg',
		'/en/img/library.jpg',
		'/en/img/library-o.jpg',
		'/en/img/library-audio.jpg',
		'/en/img/library-audio-o.jpg',
		'/en/img/library-photo-video.jpg',
		'/en/img/library-photo-video-o.jpg',
		'/en/img/library-text.jpg',
		'/en/img/library-text-o.jpg',	
		'/en/img/library-yoga-art.jpg',
		'/en/img/library-yoga-art-o.jpg',
		'/en/img/library-humor.jpg',
		'/en/img/library-humor-o.jpg',
		'/en/img/link.jpg',
		'/en/img/link-o.jpg');
}
