(function() {

var ie6 = false;
if(typeof(DD_belatedPNG) != 'undefined') {ie6 = true;}
var ieX = /*@cc_on!@*/false;

var smartDevice = false;
var UA = navigator.userAgent;
if((UA.match(/iPhone/i)) || (UA.match(/iPod/i)) || (UA.match(/iPad/i))) {
    smartDevice = true;
}

function currentPageName() {
	var currentPage = window.location.href;
	if(currentPage.indexOf('?') != -1) {currentPage = currentPage.split('?')[0];}
	if(currentPage.indexOf('#') != -1) {currentPage = currentPage.split('#')[0];}
	currentPage = currentPage.split('/');
	currentPage = currentPage[currentPage.length-1];
	if(!currentPage) {currentPage = 'index.html';}
	return currentPage;
};

function navigationFeedback(aDiv) {
	var currentPage = currentPageName();
	var aMenu = aDiv.getElementsByTagName('ul')[0];
	var theButtons = aMenu.childNodes;
	for(var j = theButtons.length; j > 0; j--) {
		var aButton = theButtons[j-1];
		if(aButton.tagName) {
			var theLinks = aButton.getElementsByTagName('a');
			for(var k = theLinks.length; k > 0; k--) {
				var aLink = theLinks[k-1];
				var anHref = aLink.getAttribute('href');
				if(anHref && (anHref.indexOf(currentPage) != -1)) {
					theLinks[0].style.backgroundImage = 'url(images/nav_down.png)';
					return true;
				}
			}
		}
	}
};

function addJsInput() {
	var aForm = this;
	var anInput = document.createElement('input');
	anInput.type = 'hidden';
	anInput.id = 'js';
	anInput.name = 'js';
	anInput.value = 'on';
	aForm.appendChild(anInput);
	if(ie6) {return true;}
	var theNodes = aForm.getElementsByTagName('*');
	for(var i = theNodes.length; i > 0; i--) {
		var aNode = theNodes[i-1];
		if(aNode && aNode.getAttribute('type')) {
			if(aNode.getAttribute('type') == 'submit') {
				var timedFunction = function() {aNode.setAttribute('disabled','disabled');};
				setTimeout(timedFunction,350);
				break;
			}
		}
	}
	return true;
};
var overflowItems = null;
function currentPageActions() {
	var theDivs = document.getElementsByTagName('div');
	for(var i = 0; i < theDivs.length; i++) {
		var aDiv = theDivs[i];
		var aClass = aDiv.getAttribute('class') || aDiv.className;
		if(aClass == 'nav') {
			navigationFeedback(aDiv);
		}
	}
	var theForms = document.getElementsByTagName('form');
	for(var i = 0; i < theForms.length; i++) {
		var aForm = theForms[i];
		var formAction = aForm.getAttribute('action');
		if(formAction && (formAction != 'logout.php')) {
			aForm.onsubmit = addJsInput;
		}
	}
};
setTimeout(currentPageActions,1);


//!get style from class
function getStyle(x,styleProp) {
	if(x.currentStyle) {
		var y = x.currentStyle[styleProp];
	} else if(window.getComputedStyle) {
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	}
	return y;
};
//_get style from class
//!including files
function includeFile(filePath) {
	if(!filePath) {return;}
	var ext = filePath.substring(filePath.lastIndexOf('.')+1);
	switch (ext) {
		case 'js':
			var inc = document.createElement('script');
			inc.setAttribute('type','text/javascript');
			inc.setAttribute('charset','utf-8');
			inc.setAttribute('src',filePath);
			break;
		case 'css':
			var inc = document.createElement('link');
			inc.setAttribute('type','text/css');
			inc.setAttribute('rel','stylesheet');
			inc.setAttribute('media','screen');
			inc.setAttribute('href',filePath);
			break;
		default:
			return;
	}
	if(ieX) {
		document.body.appendChild(inc);		
	} else {
		document.getElementsByTagName('head').item(0).appendChild(inc);		
	}
};
//_including files


if(!!window.opera) {
	var theDivs = document.getElementsByTagName('div');
	for(var i = 0; i < theDivs.length; i++) {
		var aDiv = theDivs[i];
		var aClass = aDiv.getAttribute('class') || aDiv.className;
		if(aClass == 'nav') {
			var aMenu = aDiv.getElementsByTagName('ul')[0];
			var theButtons = aMenu.childNodes;
			for(var j = theButtons.length; j > 0; j--) {
				var aButton = theButtons[j-1];
				if(aButton.tagName) {
					aButton.style.backgroundImage = 'url(images/o_navbarbg.png)';
				}
			}
			return true;
		}
	}
}

})();
