
// menudef.js v0.5

// *********************************************************
// Object: ControlCollection
// Container of activated client Web Controls
//
function ControlCollection() { 
	this.length = 0; 
	this.add = add; 
	// this.remove = remove; 
	// this.contains = contains;
	return this 
} 


function add(object) { 
	this.length++; 
	this[this.length] = object 
	this[object.id] = object;
} 


function MenuNavigation(name){ }

MenuNavigation.prototype.newItem = 

function(name,parent,txt,txt_en,lnk,targ,w,h,img1,img2,cl,cl2,align,rows,nolink,onclick,onmouseover,onmouseout) {
        if(this.langcode=="0"){
        clientCollection.add([onclick,txt,name,parent]);
        }else  {clientCollection.add([onclick,txt_en,name,parent]);}
}
        
var currLevel = 1;
var subLevel = 1;
var lastSubLevel = 1;
var hasSubnav = false;

function getBasename( url ) {
	if( url.contains("/") ) return url.split("/")[ url.split("/").length-1 ]; else return url;
}

MenuNavigation.prototype.construct = function() {
	var ConstructSubMenu="";
    var urlLocation  = (getBasename( document.location.href ).toLowerCase()).split('#')[0];
    var selectedTopMenu="";
    for (i=1; i<=clientCollection.length; i++)
    {
        
	    if(urlLocation.contains(getBasename( clientCollection[i][0].toLowerCase()))){
		    selectedTopMenu=clientCollection[i][3];
		    if(selectedTopMenu=="") selectedTopMenu=clientCollection[i][2];
		    break;
	    }
    }
    for (i=1; i<=clientCollection.length; i++)
    {
	if (clientCollection[i][2] == ("top"+currLevel))  {
		var id = "";
		var topClientCon = getBasename( clientCollection[i][2]);
	    var urlClientCon = getBasename( clientCollection[i][0] );
		if( (i == 1) && urlLocation==""  ) { 
			id = "current"; 
		} else {
			if( urlLocation.contains(urlClientCon) ) {
				
				if( urlClientCon.split("-")[4] == urlLocation.split("-")[4] ) {
					if( urlClientCon.split("-")[12] == urlLocation.split("-")[12] ) {
						id = "current";
					}
				}
			}else if(topClientCon==selectedTopMenu){
			    id="current"
			}
		}

		div += '<li id="'+id+'"><div><a href="'+clientCollection[i][0]+'"><span>' + clientCollection[i][1] +"</span></a></div>";
		currLevel++;
	}
	
	if( clientCollection[i][2] == ("sub"+ subLevel) ) {
		if( subLevel == lastSubLevel) div += "<ul>";
		div += '<li><a href="'+clientCollection[i][0]+'"><span>' + clientCollection[i][1] + '</span></a></li>';
		if(selectedTopMenu==getBasename( clientCollection[i][3].toLowerCase())) {
		    if(!(urlLocation.contains(getBasename(clientCollection[i][0].toLowerCase())))) ConstructSubMenu +='<DIV class=nav2i><A class=nav2i onclick="javascript:openLink(\''+clientCollection[i][0]+'\',\'0\',\'ex\',\'\',\'\',this);return false;" href="'+clientCollection[i][0]+'">'+clientCollection[i][1]+'</A></DIV></DIV><DIV class=mEven>';
		    else ConstructSubMenu +='<DIV class=nav2s><A class=nav2s onclick="javascript:openLink(\''+clientCollection[i][0]+'\',\'0\',\'ex\',\'\',\'\',this);return false;" href="'+clientCollection[i][0]+'">'+clientCollection[i][1]+'</A></DIV></DIV><DIV class=mEven>';
		    }
		    subLevel++;
	}
		if( (urlLocation=="bilgilerimiguncelle.aspx"||urlLocation=="aracbilgilerimiguncelle.aspx") && clientCollection[i][0]!="Default.aspx") {
		if( subLevel == lastSubLevel) div += "<ul>";
		if(clientCollection[i][0]!="#")
		    div += '<li><a href="'+clientCollection[i][0]+'"><span>' + clientCollection[i][1] + '</span></a></li>';
selectedTopMenu="top4";
		if(selectedTopMenu==getBasename( clientCollection[i][3].toLowerCase())) {
		    ConstructSubMenu +='<DIV class=nav2i><A class=nav2i onclick="javascript:openLink(\''+clientCollection[i][0]+'\',\'0\',\'ex\',\'\',\'\',this);return false;" href="'+clientCollection[i][0]+'">'+clientCollection[i][1]+'</A></DIV></DIV><DIV class=mEven>';
		    }
		    subLevel++;
	}
	if ( clientCollection[i+1] != null && clientCollection[i+1][2] == ("top"+ currLevel)  ) {
	
		if( subLevel > lastSubLevel ) {
			div += "</ul>"; 
			lastSubLevel = subLevel ;
		}
		
		div += '</li>';
		
	}

    }

    
    div += "</ul>";
    if(document.getElementById('subMenu')!=null) document.getElementById('subMenu').innerHTML = ConstructSubMenu;
    if(document.getElementById('menuBar')!=null)document.getElementById('menuBar').innerHTML = div;
  
}



MenuNavigation.prototype.init = function() {

//	var navRoot = document.getElementById("nav");	
//	
//	for (i=0;  i<navRoot.childNodes.length;  i++) 
//	{
//		var node = navRoot.childNodes[i];
//		if (node.nodeName=="LI") {
//			var urlClientCon = getBasename( node.childNodes[0].childNodes[0].href );
//			var aSel = ( $E('a.nav2s') != null ) ? $E('a.nav2s') : $E('a.nav2a');
//			if( aSel != null &&  aSel.href != null ) {
//				var urlSearch = getBasename( aSel.href );
//				if( urlClientCon.split("-")[12] == urlSearch.split("-")[12] ) {
//					node.id = "current";
//					break;
//				}
//			}

//		}
//	}

}



/**
* set events, w3c-compatible and ie
*/
function addEvent(obj, eventType, func, useCaption)
{
	if (!obj || !eventType || !func) {
		return false;
	} else if (obj.addEventListener) {
		obj.addEventListener(eventType, func, useCaption);
		return true;
	} else if (obj.attachEvent) {
		var retVal = obj.attachEvent("on"+eventType, func);
		return retVal;
	} else {
		return false;
	}
}





// Vars
var clientCollection = new ControlCollection(); 
var div = "<ul id=\"nav\">";
var objMenu = new MenuNavigation("objMenu") ;


startList = function() {

	objMenu.init();

	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		if(navRoot !=null){
		    for (i=0; i<navRoot.childNodes.length; i++) {
			    node = navRoot.childNodes[i];
			    if (node.nodeName=="LI") {
				    node.onmouseover=function() {
					    this.className+=" over";
				    }
				    node.onmouseout=function() {
					    this.className=this.className.replace(" over", "");
				    }
			    }
		    }
		}
	}
}
//window.onload=startList;
addEvent(window, "load", startList);





/**
	some common helper functions
*/

function getLayer( strID )
{
	if( document.all && !window.opera )
		return document.all[ strID ];
	else
		return document.getElementById( strID );
}




