// JavaScript Document

function submenu() {
	var area = getArea();
	var sMenuActive = document.getElementById(area);
	sMenuActive.style.display = 'block';
	
	/*var submenu = document.getElementById('submenu');
	var pagebody = document.getElementById('pageBody');
	var submenuHeight = document.defaultView.getComputedStyle(submenu, null).getPropertyValue("height");
	var pageHeight = document.defaultView.getComputedStyle(pagebody, null).getPropertyValue("height");
	if ( pageHeight < submenuHeight) {
		document.getElementById('shell').style.height = menuHeight+'px';
	}*/
	
}

function swapOver(imgAnchor) {
	children = imgAnchor.childNodes;
	for(i=0; i < children.length; i++) {
		child = children[i];
		if(child.nodeName == 'IMG') {
			src = child.getAttribute('src');
			
			if(src.indexOf('_') != -1) {
				clipIndex = src.lastIndexOf('_');
			} else {
				clipIndex = src.indexOf('.gif');
			}
			
			filename = src.substring(0,clipIndex)
			newSrc = filename+'_over'+'.gif';
			child.setAttribute('src',newSrc);
		}
	}

}

function swapOut(imgAnchor) {
	
	var caste;
	var children = imgAnchor.childNodes;
	var srcState;
	
	if(imgAnchor.parentNode.id == 'navigation') {
		caste = getSection();
		if(imgAnchor.firstChild.id.substring(imgAnchor.firstChild.id.indexOf('_')+1, imgAnchor.firstChild.id.length) == caste) {
			srcState = '_down';
		} 
	} else {
		caste = getArea();
		if(imgAnchor.parentNode.id.substring(0, imgAnchor.parentNode.id.indexOf('_')) == caste) {
			srcState = '_down';
		}
	}
	
	for(i=0; i < children.length; i++) {
	
		var child = children[i];
		
		if(child.nodeName == 'IMG') {
			var src = child.getAttribute('src');
			filename = src.substring(0, src.lastIndexOf('_'));
			if(srcState != null) {
				newSrc = filename+srcState+'.gif';
				
			} else {
				newSrc = filename+'.gif';
			}
		
		}
		child.setAttribute('src', newSrc);
	}		

}

function showMenu(actArea) {
	var area = getArea();
	var sMenuActive = getMenu(actArea);
	if(actArea != area) {
		sMenuActive.style.display = 'block';
		setTimeout(hideMenu, 3000, sMenuActive);
	}
}

function hideMenu(actArea) {
	var area = getArea();
	var menu = getMenu(area);
	alert(menu);
	var sMenuActive = getMenu(actArea);
	if(actArea != area) {
		sMenuActive.style.display = 'none';
		menu.style.display = 'block';
	}		
}

function getMetas() {
			
			if(document.all) {
				var metas = document.all.tags('meta');
			} else {
				var metas = document.getElementsByTagName('meta');
			}
			
			return metas;
}

function getServer() {
	var metas = getMetas();
	var serverValue;
	
	for(var i=0; i < metas.length; i++) {
			meta = metas[i];
			
			if(meta.getAttribute('name') == 'server') {
				serverValue = meta.getAttribute('content');
			}
		}
	return serverValue;
}

function getArea() {
	
		var metas = getMetas();
		var areaValue;
		
		for(var i=0; i < metas.length; i++) {
			meta = metas[i];
			
			if(meta.getAttribute('name') == 'area') {
				areaValue = meta.getAttribute('content');
			}
		}
		return areaValue;
}

function getSection() {
	
		var metas = getMetas();
		var areaValue;
		
		for(var i=0; i < metas.length; i++) {
			meta = metas[i];
			
			if(meta.getAttribute('name') == 'section') {
				areaValue = meta.getAttribute('content');
			}
		}
		return areaValue;
}

function getMenu(id) {
	var children = document.getElementById(id).childNodes;
	var menu;
	for(var i=0; i < children.length; i++) {
		var menuTest = children[i];
		if(menuTest.nodeName == 'DIV' && menuTest.getAttribute('class')) {
			menu = menuTest;
		}
	}
	return menu;		
}

function galleryExplode(imgAnchor) {
	var server = getServer();
	var img = imgAnchor.firstChild;
	var inSrc = img.src;
	var domain = 'http://'+inSrc.substring(inSrc.indexOf('http://')+7, inSrc.indexOf('/img/')+5);
	var filename = inSrc.substring(inSrc.lastIndexOf('/')+1, inSrc.length);
	var imgUrl = domain+filename;
	var outSrc = server+'explode.php?src='+imgUrl;
	
	var newWin = window.open(outSrc, 'loupe', 'scrollbars,height=600,width=800');
	
	//alert(img);
	//alert(imgContainer);
}

function galleryHighlight(imgAnchor) {
	var img = imgAnchor.firstChild;
		
	if(img.getAttribute('class') != 'floatRight') {
		img.setAttribute('class', 'imgOver');
	} else {
		img.setAttribute('class', 'floatOver');
	}

}

function galleryDelight(imgAnchor) {
	var img = imgAnchor.firstChild;
	
	if(img.getAttribute('class') != 'floatOver') {
		img.setAttribute('class', null);
	} else {
		img.setAttribute('class','floatRight');
	}
}
		