/****************************
Copyright Domenca
****************************/
//addEvent( window, 'load', load );
var popID;
var tID;
var flash;

inMenu = false;
menuFixOverlay = true;
flash = getNode( "flash" );


last = null;

//function load() {
//inMenu = false;
//menuFixOverlay = true;
//flash = getNode( "flash" );
//body = document.getElementsByTagName( "body" )[0];
//last = null;
//
//var first  = new MenuP( getNode( "difar_first" ));
//var second = new MenuP( getNode( "difar_second" ));
//var third  = new MenuP( getNode( "difar_third" ));
//
//
//
//
//		first.add( new Menu( "Docteur Nature", "http://dev.domenca.com/difar/katalog/index.php?cat_id=5", "" ) );
//		first.add( new Menu( "Natural Wealth", "http://dev.domenca.com/difar/katalog/index.php?cat_id=6", "" ) );
//		first.add( new Menu( "Aprosan", "http://dev.domenca.com/difar/katalog/index.php?cat_id=7", "" ) );
//		first.add( new Menu( "Prodiet", "http://dev.domenca.com/difar/katalog/index.php?cat_id=8", "" ) );
//		first.add( new Menu( "Nutripharm", "http://dev.domenca.com/difar/katalog/index.php?cat_id=24", "" ) );
//		
//	first.create();
//	first.menuFixOverlay();
//
//		second.add( new Menu( "športniki", "http://dev.domenca.com/difar/katalog/index.php?cat_id=9", "" ) );
//		second.add( new Menu( "otroci", "http://dev.domenca.com/difar/katalog/index.php?cat_id=10", "" ) );
//		second.add( new Menu( "starejši", "http://dev.domenca.com/difar/katalog/index.php?cat_id=11", "" ) );
//		second.add( new Menu( "moški", "http://dev.domenca.com/difar/katalog/index.php?cat_id=12", "" ) );
//		second.add( new Menu( "ženske", "http://dev.domenca.com/difar/katalog/index.php?cat_id=13", "" ) );
//		second.add( new Menu( "nosečnice", "http://dev.domenca.com/difar/katalog/index.php?cat_id=14", "" ) );
//		second.create();
//	second.menuFixOverlay();
//
//		third.add( new Menu( "vitamini", "http://dev.domenca.com/difar/katalog/index.php?cat_id=15", "" ) );
//		third.add( new Menu( "minerali", "http://dev.domenca.com/difar/katalog/index.php?cat_id=16", "" ) );
//		third.add( new Menu( "multivitaminske - mineralne formule", "http://dev.domenca.com/difar/katalog/index.php?cat_id=17", "" ) );
//		third.add( new Menu( "izdelki za hujšanje", "http://dev.domenca.com/difar/katalog/index.php?cat_id=18", "" ) );
//		third.add( new Menu( "kozmetika", "http://dev.domenca.com/difar/katalog/index.php?cat_id=19", "" ) );
//		third.add( new Menu( "naravni izdelki", "http://dev.domenca.com/difar/katalog/index.php?cat_id=20", "" ) );
//		third.add( new Menu( "naravni repelenti", "http://dev.domenca.com/difar/katalog/index.php?cat_id=21", "" ) );
//		third.add( new Menu( "fito obliži", "http://dev.domenca.com/difar/katalog/index.php?cat_id=22", "" ) );
//		third.add( new Menu( "fitoterapija", "http://dev.domenca.com/difar/katalog/index.php?cat_id=23", "" ) );
//		third.create();
//	third.menuFixOverlay();
//
//
//
//}

function MenuP (div_id,  node , selected_button) {
	//alert(selected_button);

	this.node = node;
	this.menuItems = new Array();
	MenuP.prototype.add = function( menuItem ) {
	this.menuItems[ this.menuItems.length ] = menuItem;	
	}
	MenuP.prototype.create = function( ) {
	//var dNode = document.createElement( "div" );
	
	var dNode = document.getElementById(div_id);
	
	dNode.className = "jsMenu";
	var str = "_" + this.node.id;
	dNode.setAttribute( "id", str );
	var w = this.node.offsetWidth;	
	if(!menuFixOverlay){	
		dNode.style.padding = "1px";
		dNode.style.border = "1px solid #555";
	}
	dNode.style.width = w > 135 ? w+"px" : "141px";
	
	dNode.style.top = ( this.node.offsetTop + this.node.offsetHeight ) + "px";
	dNode.style.left = this.node.offsetLeft + "px";
	addEvent( this.node, "mouseover", function() { showMenuInTime(str, 150) } );
	addEvent( this.node, "mouseout", function() { setInMenu(false) } );
	dNode.setAttribute( "pItemID", this.node.id );
	addEvent( dNode, "mouseover", function() { setInMenu(true) } );
	addEvent( dNode, "mouseout", function() { setInMenu(false) } );
	
	if(menuFixOverlay){
		if (div_id == "div_first") {
			var file = "1";
		} else if (div_id == "div_second") {
			var file = "2";
		} else if (div_id == "div_third") {
			var file = "3";
		}
		
		
		var html = "<iframe id=\"fixOverlayIFRAME_" + this.node.id + "\" frameborder=\"0\" scrolling=\"no\" src=\"\" width=\"141\" height=\"1\" style=\"background-color:#FFFFFF; z-index: 0; filter: Beta(Style=0,Opacity=0);\"></iframe>";
		
//		if (selected_button == 1) {
//		
//			html += "<div id=\"fixOverlayDIV_" + this.node.id + "\" class=\"menu_js\"><img src='http://www.difar.si/skins/difar/images/button" + file + "_over.gif' width='143' height='94' alt='/' />";
//	
//		} else {
		
			html += "<div id=\"fixOverlayDIV_" + this.node.id + "\" class=\"menu_js\"><img src='http://www.difar.si/skins/difar_new/images/button_green" + file + ".gif' width='143' height='94' alt='' />";
	
//		}
		
		
		html += "<ul>";
	} else {
		var html = "<ul>";
	}
	for( var i=0; i<this.menuItems.length; i++ ) {
		html += this.menuItems[i].getLinkHTML();
	}
	
	if(menuFixOverlay){
		dNode.innerHTML = html + "</ul>" + "<div style='padding-left:4px; text-align:left;'><img src='http://www.difar.si/skins/difar_new/images/button_bottom.gif' border='1' alt='' /></div></div>";
	} else {
		dNode.innerHTML = html + "</ul>";
	}
	//body.appendChild( dNode );
	}
	MenuP.prototype.menuFixOverlay = function( ) {
		var objF = document.getElementById('fixOverlayIFRAME_' + this.node.id);
		var objD = document.getElementById('fixOverlayDIV_' + this.node.id);
		var objO = document.getElementById('_' + this.node.id);
		
		if(objF && objD && objO){		
			objF.height = parseInt(parseInt(objD.offsetHeight));		
			objO.style.display = 'none';
		}
	}
}

function Menu( value, href, icon ) {
this.value = ( value == null ) ? "" : value;
this.href = ( href == null ) ? "" : href;
this.icon = ( icon == null ) ? "" : icon;
if( this.href != "" && typeof useAbsPath != "undefined" )
	if( useAbsPath && this.href.indexOf( "http://" ) == -1 && this.href.indexOf( "https://" ) == -1 )
		this.href = "http://www.test.com" + this.href;
Menu.prototype.getLinkHTML = function () {	
		
	if( this.value != "" && this.href != "" && this.icon != "")
		return "<li><a onclick=\"setInMenu(false); hideMenu(); return true;\" href=\"" + this.href + "\"><img src=\"" + this.icon + "\"  align=\"absmiddle\" border=\"0\" alt=\"\" />" + this.value + "</a></li>";
	else if( this.value != "" && this.href != "" )
		return "<li><a onclick=\"setInMenu(false); hideMenu(); return true;\" href=\"" + this.href + "\">" + this.value + "</a></li>";
	else if( this.value != "" && this.href == "" )
		return "<li class='heading'>" + this.value + "</li>";
	else if( this.value != "" && this.href == "" && this.icon != "")
		return "<li class='heading'><img src=\"" + this.icon + "\" align=\"absmiddle\" border=\"0\" alt=\"\" />" + this.value + "</li>";
	else
		return "<li class='separator'>&nbsp;</li>";
}
}
function showMenuInTime( node, time ) {
popID = setTimeout( "showMenu('" + node + "')", time );
}
function showMenu( node ) {

	clearTimeout( popID );
	if( typeof node == "string" )
		node = getNode( node );
	if( last != null && last != node )
		hideMenu( last );
	else if( last == node ) {
		setInMenu( true );
		return;
	}
	var pItem = getNode( node.getAttribute( "pItemID" ) );
	var menuLeft = 0;
	var menuTop = pItem.offsetHeight;
	var tmp = pItem;
	while(tmp!=null && tmp.tagName!="BODY") {
		if( tmp.tagName == "html:body" ) break;
		
		menuLeft += tmp.offsetLeft;
		menuTop  += tmp.offsetTop;
		tmp = tmp.offsetParent;
	}
	node.style.left = menuLeft + "px";
	node.style.top = menuTop + "px";
	var w = pItem.offsetWidth;
	node.style.width = w > 135 ? w+"px" : "135px";
	node.style.display = "block";	
	setInMenu( true );
	last = node;
	if( flash != null )	flash.style.visibility = "hidden";
	tID = setTimeout( "hideMenu( last )", 500 );

}

function hideMenu( node ) {
if( node == null ) {
	setInMenu( false );
	hideMenu( last );
	return;
}
if( typeof node == "string" )
	node = getNode( node );
if( !inMenu ) {
	node.style.display = "none";
	var pItem = getNode( node.getAttribute( "pItemID" ) );
	last = null;
	clearTimeout( tID );
	if( flash != null )	flash.style.visibility = "visible";
} else
	tID = setTimeout( "hideMenu( last )", 500 );	
}
function setInMenu( value ) {
inMenu = value;	
if( !value ) clearTimeout( popID );
}
function addEvent( node, evtType, func ) {
if( node.addEventListener ) {
	node.addEventListener( evtType, func, false );
	return true;
} else if( node.attachEvent )
	return node.attachEvent( "on" + evtType, func );
else
	return false;
}
function getNode( nodeId ) {
if( document.getElementById )
	return document.getElementById( nodeId );
else if( document.all && document.all( nodeId ) )
	return document.all( nodeId );
else if( document.layers && document.layers[ nodeId ] )
	return document.layers[ nodeId ];
else
	return false;
}
