

var currentHeader = "images/logobar.jpg";

var defaultHeader = "images/logobar.jpg";

function restoreHeader()
{
	if( currentHeader != defaultHeader ) E('logobar').style.background = "url(" + WSD_WEBROOT + defaultHeader + ")";
	currentHeader = defaultHeader;
	return true;
}

function setHeader( h )
{
	if( currentHeader != h ) E('logobar').style.background = "url(" + WSD_WEBROOT + h + ")";
	currentHeader = h;
	return true;
}



function dn_MenuItemByCode(itemCode, menuType, mainID, subID , otherTop )
{
	restoreHeader();

	if(!WSD_AJAX) return true;

	//if(menuType == "main" && displayMenuIndex == menuID) return false;
	
	try
	{
		if(menuType == "sub" && subID && displaysubMenuIndex == subID) return false;
	}
	catch( e )
	{
	};

	if(menuType == "main")
		var qAddon = "?page="+itemCode;
	else
		var qAddon = "?pageSub="+itemCode;

	var url = WSD_WEBROOT+"dn-menu.php"+qAddon;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop, url );};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);

	return false;
}

function dn_MenuItemByType(itemCode, menuType, mainID, subID , otherTop)
{
	restoreHeader();

	if(!WSD_AJAX)
	{
		return true;
	}

	if(menuType == "main")
		var qAddon = "?type="+itemCode;
	else
		var qAddon = "?typeSub="+itemCode;

	var url = WSD_WEBROOT+"dn-menu.php"+qAddon;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop, url );};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
		
	return false;
}

function dn_ImageCategoryByCode(itemCode, menuType, mainID, subID , otherTop)
{
	restoreHeader();

	if(!WSD_AJAX)
	{
		return true;
	}


	var url = WSD_WEBROOT+"dn-img-cat.php?imgCat="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop, url );};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	
	return false;
}

function dn_ArchiveByCode(itemCode, menuType, mainID, subID , otherTop, videoFile)
{
	restoreHeader();

	if(!WSD_AJAX)
	{
		return true;
	}


	var url = WSD_WEBROOT+"dn-archive.php?archive="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop, url);};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	
	return false;
}

function dn_NewsByCode(itemCode, menuType, mainID, subID , otherTop)
{
	restoreHeader();

	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-news.php?news="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop, url );};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	
	return false;
}

function dn_StageByCode(itemCode, menuType, mainID, subID, otherTop,h)
{
	setHeader( h );

	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-stage.php?stage="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop, url );};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	
	return false;
}

function dn_DJByCode(itemCode, menuType, mainID, subID , otherTop,h )
{
	if(h) setHeader( h );
	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-dj.php?dj="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop, url );};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	
	return false;
}



function dn_VideoByCode(itemCode, menuType, mainID, subID, otherTop)
{
	restoreHeader();

	if(!WSD_AJAX)
	{
		return true;
	}

	var url = WSD_WEBROOT+"dn-video.php?video="+itemCode;
	
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop, url );};
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);

	return false;
}

function updateMenuRequest(xmlHttp, itemCode, menuType, menuID, subID , otherTop , url)
{
    if(xmlHttp.readyState == 4)
	{
        if(xmlHttp.status == 200)
		{
			//set_page();

			var responseStatus = xmlHttp.responseText;
			var menuContent = responseStatus;	// Content

			var dnContent = E('dnContent');

			dnContent.innerHTML = menuContent;

			if(menuID)
			{
				if(menuType == "main")
					var global_currentID = displayMenuIndex;
				else
					var global_currentID = displaysubMenuIndex;

				// only switch images if enabled:
				if(WSD_FIMG)
				{
					/* REMOVE */ 

					// remove old sub button
					if(E('subMenu_'+displaysubMenuIndex+'_n') && E('subMenu_'+displaysubMenuIndex+'_h'))
					{
						E('subMenu_'+displaysubMenuIndex+'_h').style.display = 'none';
						E('subMenu_'+displaysubMenuIndex+'_n').style.display = 'block';
					}

					// remove old main button
					if(E('mainMenu_'+displayMenuIndex+'_n') && E('mainMenu_'+displayMenuIndex+'_h'))
					{
						E('mainMenu_'+displayMenuIndex+'_h').style.display = 'none';
						E('mainMenu_'+displayMenuIndex+'_n').style.display = 'block';

						/*E('mainMenu_'+displayMenuIndex+'_td').style.backgroundImage = 'none';*/
						
						// remove submenu holder:
						if(E('submenuHolder_'+displayMenuIndex))
							E('submenuHolder_'+displayMenuIndex).style.displayMenuIndex = 'none';
					}


					/* DISPLAY */

					// display new main button
					if(E('mainMenu_'+menuID+'_h') && E('mainMenu_'+menuID+'_n'))
					{
						E('mainMenu_'+menuID+'_h').style.display = 'block';
						E('mainMenu_'+menuID+'_n').style.display = 'none';

						/*E('mainMenu_'+menuID+'_td').style.backgroundImage = 'url('+WSD_WEBROOT+'images/menu-selected.png)';*/

					}

					// display new sub button
					if(E('subMenu_'+subID+'_h') && E('subMenu_'+subID+'_n'))
					{
						E('subMenu_'+subID+'_h').style.display = 'block';
						E('subMenu_'+subID+'_n').style.display = 'none';
					}

					// reset submenu
					if(menuType == "main")
					{
						// reset submenu
						displaysubMenuIndex = 0;
					}
				}

				// set new display index:
				if(menuType == "main")
					displayMenuIndex = menuID;
				else
				{
					displayMenuIndex = menuID;
					displaysubMenuIndex = subID;
				}
			}
			
			// img boxes:
			currentBox = 0;

			
			if( ! otherTop ) scroll(0,0);
			else 
			{
				var el= document.getElementsByName(otherTop);
				if( el.length ) scroll(0,el[0].offsetTop );
			}
			
			
			if( url )
			{
				if( url != document.lastUrl )
				{
					document.lastUrl = url;
				
					E( 'navigator' ).contentWindow.location = 'navigator.php?url=' + escape( url )
										+'&itemCode='+escape(itemCode)+'&menuType='+escape(menuType)+'&mainID='+escape(menuID)+'&subID='+escape(subID)+'&otherTop='+otherTop;
				}
			}
			
			var istart = menuContent.indexOf('<!--TITLE:');
			var iend = menuContent.indexOf('-->' , istart );
			
			if( istart >= 0 )
			{
				document.title = menuContent.substr( istart + 10  , iend - istart - 12 );
			}
		}
	}
}

function navigateBack( url , itemCode, menuType, mainID, subID , otherTop )
{
//alert( url );
	if( url != document.lastUrl )
	{
		if( url )
		{
			var xmlHttp = createXMLHttpRequest();
			xmlHttp.onreadystatechange = function(){updateMenuRequest(xmlHttp, itemCode, menuType, mainID, subID , otherTop );};
			
			
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		}
	}
}


