var sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//SET MAIN MENU CURRENT PAGE
//------------------------------------------------------------------------------------
function extractPageName(hrefString)
{
	var arr = hrefString.split('.');
	arr = arr[arr.length-2].split('/');
	return arr[arr.length-1].toLowerCase();		
}

function setActiveMenu(arr, crtPage)
{
	for(var i=0; i < arr.length; i++)
		if(extractPageName(arr[i].href) == crtPage)
		{
			arr[i].className = "current";
			arr[i].parentNode.className = "current";
		}
}

function setPage()
{
	if(document.location.href) 
		var hrefString = document.location.href;
	else
		var hrefString = document.location;

	if (document.getElementById("nav")!=null) 
		setActiveMenu(document.getElementById("nav").getElementsByTagName("a"), extractPageName(hrefString));
}

// GO TO NEXT PAGE 
//------------------------------------------------------------------------------------

function nextPage() {
//We get the page name from the URL
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

//We get the numeric part of the page name
var r = sPage.match(/[\d\.]+/g);
var pageNum = parseInt(r);

//We add one
if((pageNum == null) || (isNaN(pageNum))) {
return window.location = "content_pageId0.aspx";
} else {
	if(pageNum == 12) {
		return window.location = "index.aspx";
	} else {
		var newPageNum = pageNum + 1;
		//New Link
		return window.location = sPage.replace(pageNum, newPageNum);
	}
}


}

function backPage() {
//We get the page name from the URL
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

//We get the numeric part of the page name
var r = sPage.match(/[\d\.]+/g);
var pageNum = parseInt(r);

//We substract one
if((pageNum == 0) || (pageNum == null) || (isNaN(pageNum))) {
return window.location = "index.aspx";
} else {
var newPageNum = pageNum - 1;
//New Link
return window.location = sPage.replace(pageNum, newPageNum);
}


}

//------------------------------------------------------------------------------------
// ACCORDION
//------------------------------------------------------------------------------------

window.addEvent('domready', function() {

	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	var r = sPage.match(/[\d\.]+/g);
	var pageNum = parseInt(r);
	
	if(pageNum == 0) { var elementId = 0; }
	if(pageNum == 1) { var elementId = 0; }
	if(pageNum >=2 && pageNum <=8) { var elementId = 1; }

    var accordion = new Accordion($$('.toggler'),$$('.element'), {
        opacity: 0,
        display: elementId,
        alwaysHide: true,
        onActive: function(toggler, element) {  
        	toggler.addClass('open');
        },
        onBackground: function(toggler, element) {  
        	toggler.removeClass('open'); 
        }
    });
});