
var root='http://www.networkbay.ro/';



// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// December 9, 2003: Added script to the Javascript Toolbox
// December 10, 2003: Added the preProcessTrees variable to allow user
//      to turn off automatic conversion of UL's onLoad
// March 1, 2004: Changed it so if a <li> has a class already attached
//      to it, that class won't be erased when initialized. This allows
//      you to set the state of the tree when painting the page simply
//      by setting some <li>'s class name as being "liOpen" (see example)
/*
This code is inspired by and extended from Stuart Langridge's aqlist code:
		http://www.kryogenix.org/code/browser/aqlists/
		Stuart Langridge, November 2002
		sil@kryogenix.org
		Inspired by Aaron's labels.js (http://youngpup.net/demos/labels/) 
		and Dave Lindquist's menuDropDown.js (http://www.gazingus.org/dhtml/?id=109)
*/

// Automatically attach a listener to the window onload, to convert the trees
addEvent(window,"load",convertTrees);

// Utility function to add an event listener
function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}

// utility function to set a global variable if it is not already set
function setDefault(name,val) {
	if (typeof(window[name])=="undefined" || window[name]==null) {
		window[name]=val;
	}
}

// Full expands a tree with a given ID
function expandTree(treeId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	expandCollapseList(ul,nodeOpenClass);
}

// Fully collapses a tree with a given ID
function collapseTree(treeId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	expandCollapseList(ul,nodeClosedClass);
}

// Expands enough nodes to expose an LI with a given ID
function expandToItem(treeId,itemId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	var ret = expandCollapseList(ul,nodeOpenClass,itemId);
	if (ret) {
		var o = document.getElementById(itemId);
		if (o.scrollIntoView) {
			o.scrollIntoView(false);
		}
	}
}

// Performs 3 functions:
// a) Expand all nodes
// b) Collapse all nodes
// c) Expand all nodes to reach a certain ID
function expandCollapseList(ul,cName,itemId) {
	if (!ul.childNodes || ul.childNodes.length==0) { return false; }
	// Iterate LIs
	for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
		var item = ul.childNodes[itemi];
		if (itemId!=null && item.id==itemId) { return true; }
		if (item.nodeName == "LI") {
			// Iterate things in this LI
			var subLists = false;
			for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
				var sitem = item.childNodes[sitemi];
				if (sitem.nodeName=="UL") {
					subLists = true;
					var ret = expandCollapseList(sitem,cName,itemId);
					if (itemId!=null && ret) {
						item.className=cName;
						return true;
					}
				}
			}
			if (subLists && itemId==null) {
				item.className = cName;
			}
		}
	}
}

// Search the document for UL elements with the correct CLASS name, then process them
function convertTrees() {
	setDefault("treeClass","mktree");
	setDefault("nodeClosedClass","liClosed");
	setDefault("nodeOpenClass","liOpen");
	setDefault("nodeBulletClass","liBullet");
	setDefault("nodeLinkClass","bullet");
	setDefault("preProcessTrees",true);
	if (preProcessTrees) {
		if (!document.createElement) { return; } // Without createElement, we can't do anything
		uls = document.getElementsByTagName("ul");
		for (var uli=0;uli<uls.length;uli++) {
			var ul=uls[uli];
			if (ul.nodeName=="UL" && ul.className==treeClass) {
				processList(ul);
			}
		}
	}
}

// Process a UL tag and all its children, to convert to a tree
function processList(ul) {
	if (!ul.childNodes || ul.childNodes.length==0) { return; }
	// Iterate LIs
	for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
		var item = ul.childNodes[itemi];
		if (item.nodeName == "LI") {
			// Iterate things in this LI
			var subLists = false;
			for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
				var sitem = item.childNodes[sitemi];
				if (sitem.nodeName=="UL") {
					subLists = true;
					processList(sitem);
				}
			}
			var s= document.createElement("SPAN");
			var t= '\u00A0'; // &nbsp;
			s.className = nodeLinkClass;
			if (subLists) {
				// This LI has UL's in it, so it's a +/- node
				if (item.className==null || item.className=="") {
					item.className = nodeClosedClass;
				}
				// If it's just text, make the text work as the link also
				if (item.firstChild.nodeName=="#text") {
					t = t+item.firstChild.nodeValue;
					item.removeChild(item.firstChild);
				}
				s.onclick = function () {
					this.parentNode.className = (this.parentNode.className==nodeOpenClass) ? nodeClosedClass : nodeOpenClass;
					return false;
				}
			}
			else {
				// No sublists, so it's just a bullet node
				item.className = nodeBulletClass;
				s.onclick = function () { return false; }
			}
			s.appendChild(document.createTextNode(t));
			item.insertBefore(s,item.firstChild);
		}
	}
}


// when the page loads, transform all product images into draggable items
// and allow them to be dropped on the cart

window.onload = function() {	
	// bind a progress indicator to all Ajax calls
	startAjax();
}

function startAjax()
{
	Ajax.Responders.register({
	  // when an Ajax request is started, show the indicator
		onCreate: function() {
		if (Ajax.activeRequestCount > 0)
		  Element.show($("indicator"));
	  },
		// when an Ajax request is finished, hide the indicator
		onComplete: function() {
		if (Ajax.activeRequestCount == 0)
		  Element.hide($("indicator"));
	  }
	});
}

// add item to cart
function addToCart(cid)
{
	var ptype=document.getElementsByName("price_type");
	
	for(var i=0;i<ptype.length;i++)
	{
		if (ptype[i].checked)
		{
			cid = cid + ptype[i].value;
			break;
		}
	}

	new Ajax.Request(root + "cart_server.php?action=addToCart", {
		parameters: "cid=" + cid,
		onSuccess: function(resp) {
			var cartUpdate = eval('(' + resp.responseText + ')');
			var isNew = cartUpdate['cartItemDetails'][0].isNew;
			// if this item is new in the cart, inject it inside, otherwise update the qty and subtotal
			if (isNew == 1)
			{
				var newItem = '<div id="cartItem_' + cid + '" style="display:none" class="row">';
				newItem += '<div class="cell1" id="cartItemQty_' + cid + '" valign="top">1</div>';
				newItem += '<div class="cell2"><a href="' + root + cartUpdate['cartItemDetails'][0].slug +'/" class="cart_link">' + cartUpdate['cartItemDetails'][0].title + '</a></div>';
				newItem += '<div class="cell3" id="cartItemPrice_' + cid + '">' + cartUpdate['cartItemDetails'][0].newPrice + ' </div>';
				newItem += '<div class="cell4"><a href="' + root + 'cart_server.php?action=removeFromCart&cid=' + cid + '" onclick="return removeFromCart(\'' + cid + '\')" title="Sterge din cos">';
				newItem += '<img src="' + root + '/images/x.gif" alt="x" /></a></div><div class="clear"></div></div>';
				
				if ($("cartIsEmpty"))
					Element.hide($("cartIsEmpty"));
				new Insertion.Bottom("cartItems", newItem);	
				
				Effect.Appear("cartItem_" + cid, { duration: 0.5 });
				Element.update($("cartTotalAmount"), "Total: " + cartUpdate['cartItemDetails'][0].total);
				//new Effect.Highlight("cartTotalAmount", {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
			}
			// so, the item already existed in the cart, therefore update its quantity and subtotal
			else
			{
				Element.update($("cartItemQty_" + cid), cartUpdate['cartItemDetails'][0].newQty);
				Element.update($("cartItemPrice_" + cid), cartUpdate['cartItemDetails'][0].newPrice);
				Element.update($("cartTotalAmount"), "Total: " + cartUpdate['cartItemDetails'][0].total);
				//new Effect.Highlight("cartTotalAmount", {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
				//new Effect.Highlight("cartItemPrice_" + id, {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
				//new Effect.Highlight("cartItemQty_" + id, {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
			}
		}
	});
	return false;
}

// remove an item from the cart
function removeFromCart(cid)
{
	Effect.Fade("cartItem_" + cid);
	new Ajax.Request(root + "cart_server.php?action=removeFromCart", {
		parameters: "cid=" + cid,
		onSuccess: function(resp) {
			var total = resp.responseText;
			if (total == 0)
			{
				// update the cart's total amount and contents
				Element.update($("cartItems"), '<div id="cartIsEmpty">Cosul este gol.</div>');
				Element.update($("cartTotalAmount"), "Total: 0 RON");
				//new Effect.Highlight("cartIsEmpty", {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
			}
			else
			{
				// update the cart's total amount
				Element.update($("cartTotalAmount"), "Total: " + total);
			}
			//new Effect.Highlight("cartTotalAmount", {startcolor:'#999999', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
		}
	});
	return false;
}

// empty the cart
function emptyCart()
{
	new Ajax.Request(root + "cart_server.php?action=emptyCart", {
		onSuccess: function(resp) {
			if (resp.responseText == 1)
			{
				// update the cart's total amount and contents
				Element.update($("cartItems"), '<div id="cartIsEmpty">Cosul este gol.</div>');
				Element.update($("cartTotalAmount"), "Total: 0 RON");
				//new Effect.Highlight("cartIsEmpty", {startcolor:'#999999', endcolor:'#777777', restorecolor:'#777777'});
				//new Effect.Highlight("cartTotalAmount", {startcolor:'#999999', endcolor:'#777777', restorecolor:'#777777'});
			}
		}
	});
	return false;
}



function validate_comment_form()
{
	errmsg = '';
	focusfield = '';
	
	name = document.getElementById('name').value;
	
	if (name=='')
	{
		errmsg += "Numele trebuie completat.\n";
		if (focusfield=='') focusfield = 'name';
	}
	
	comment = document.getElementById('comment').value;
	
	if (comment=='')
	{
		errmsg += "Trebuie sa introduceti un comentariu mai intai.\n";
		if (focusfield=='') focusfield = 'comment';
	}
	
	if (errmsg!='')
	{
		alert(errmsg);
		document.getElementById(focusfield).focus();
		
		return false;
	}
}

function validate_cere_form()
{
	errmsg = '';
	focusfield = '';
	
	name = document.getElementById('cere_name').value;
	
	if (name=='')
	{
		errmsg += "Numele trebuie completat.\n";
		if (focusfield=='') focusfield = 'cere_name';
	}
	
	email = document.getElementById('cere_email').value;
	
	if (email=='')
	{
		errmsg += "Adresa de e-mail trebuie completata.\n";
		if (focusfield=='') focusfield = 'cere_email';
	}
	
	comment = document.getElementById('cere_comment').value;
	
	if (comment=='')
	{
		errmsg += "Trebuie sa introduceti un comentariu mai intai.\n";
		if (focusfield=='') focusfield = 'cere_comment';
	}
	
	if (errmsg!='')
	{
		alert(errmsg);
		document.getElementById(focusfield).focus();
		
		return false;
	}
	else
	{
		cere_id1 = document.getElementById('cere_id').value;
		cere_name1 = document.getElementById('cere_name').value;
		cere_email1 = document.getElementById('cere_email').value;
		cere_tel1 = document.getElementById('cere_tel').value;
		cere_comment1 = document.getElementById('cere_comment').value;
		cere_captcha1 = document.getElementById('cere_captcha').value;
		
		document.getElementById('cere_msg_error').innerHTML = '';
		
		new Ajax.Request(root + "./?page=cere_info", {
			parameters: "&id=" + cere_id1 + "&cere_name=" + cere_name1 + "&cere_email=" + cere_email1 + "&cere_tel=" + cere_tel1 + "&cere_comment=" + cere_comment1 + "&cere_captcha=" + cere_captcha1,
			onSuccess: function(resp) {
			
				if (resp.responseText.indexOf("\"errormsg\"")== -1)
				{		
					tab6 = document.getElementById('tab6-content');	
					tab6.innerHTML = resp.responseText;
				}
				else
				{
					tab6 = document.getElementById('cere_msg_error');	
					tab6.innerHTML = resp.responseText;
				}
			}
		});
		
		return false;
	}
}

function validate_contact_form()
{
	errmsg = '';
	focusfield = '';
	
	name = document.getElementById('name').value;
	
	if (name=='')
	{
		errmsg += "Numele trebuie completat.\n";
		if (focusfield=='') focusfield = 'name';
	}
	
	email = document.getElementById('email').value;
	
	if (email=='')
	{
		errmsg += "Trebuie sa introduceti adresa de e-mail mai intai.\n";
		if (focusfield=='') focusfield = 'email';
	}
	else
	{
		if (! ( (email.indexOf(".") > 2) && (email.indexOf("@") > 0) ) )
		{
			errmsg += "Adresa de e-mail este invalida.\n";
			if (focusfield=='') focusfield = 'email';
		}
	}
	
	mesaj = document.getElementById('mesaj').value;
	
	if (mesaj=='')
	{
		errmsg += "Trebuie sa introduceti un mesaj mai intai.\n";
		if (focusfield=='') focusfield = 'mesaj';
	}
	
	if (errmsg!='')
	{
		alert(errmsg);
		document.getElementById(focusfield).focus();
		
		return false;
	}
	
	return true;
}

function form_submit (myform)
{
	theform = document.getElementById(myform);
	theform.submit();
}

function toggle_product_page_up (n)
{
	prod_up_div = document.getElementById('product_page_up');
	prod_up_gal_div = document.getElementById('product_page_up_galerie');
	
	if (n=='galerie')
	{
		prod_up_div.style.display = 'none';
		prod_up_gal_div.style.display = 'block';
	}
	else
	{
		prod_up_div.style.display = 'block';
		prod_up_gal_div.style.display = 'none';
	}
	
	return false;
}

function showfull (img)
{
	imgcontainer = document.getElementById('imgfull');
	imgcontainer.src = img;
	
	return false;
}



function open_submenu (id, me)
{
	el = document.getElementById('submenu' + id);
	
	if (!el)
	{
		return false;
	}
	
	if (el.className=='menu_show')
	{
		el.className='menu_hide';
	}
	else
	{
		el.className='menu_show';
	}
	
	if (me.className=='anchor_open')
	{
		me.className='anchor_closed';
	}
	else
	{
		me.className='anchor_open';
	}		
	
}

function applyfilters (pag, rval)
{
	var filters = document.getElementsByName("filter");
	
	filter_string = '';
	
	for (i=0; i<filters.length; i++)
	{
		filter_string = filter_string + filters[i].id + '=' + filters[i].value + ',';
	}
	
	products_div = document.getElementById('products');
	var cat_id1 = document.getElementById('cat_id').value;
	
	var ord1 = document.getElementById('ordprice').value;
	
	ppag1 = document.getElementById('ppag').value;
	
	new Ajax.Request(root + "./?page=ajax_filters", {
		parameters: "&cat=" + cat_id1 + "&filters=" + filter_string+ "&pag=" + pag + "&ppag=" + ppag1+ "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
	
	return rval;
}

function applysearchfilters (pag, rval)
{
	products_div = document.getElementById('products');
	var q1 = document.getElementById('qq').value;
	
	ppag1 = document.getElementById('ppag').value;
	
	var ord1 = document.getElementById('ordprice').value;
	
	new Ajax.Request(root + "./?page=ajax_search_filters", {
		parameters: "&pag=" + pag + "&q=" + escape(q1) + "&pord=" + ord1 + "&ppag=" + ppag1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
	
	return rval;
}

function applyppag (ppagx)
{
	var filters = document.getElementsByName("filter");
	
	filter_string = '';
	
	for (i=0; i<filters.length; i++)
	{
		filter_string = filter_string + filters[i].id + '=' + filters[i].value + ',';
	}
	
	products_div = document.getElementById('products');
	dppag = document.getElementById('ppag');
	var cat_id1 = document.getElementById('cat_id').value;

	var ord1 = document.getElementById('ordprice').value;
	
	dppag.value = ppagx;
	
	new Ajax.Request(root + "./?page=ajax_filters", {
		parameters: "&cat=" + cat_id1 + "&filters=" + filter_string+ "&pag=1&ppag=" + ppagx + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}

function applysearchppag (ppagx)
{
	
	products_div = document.getElementById('products');
	dppag = document.getElementById('ppag');
	var q1 = document.getElementById('qq').value;

	var ord1 = document.getElementById('ordprice').value;
	
	dppag.value = ppagx;
	
	new Ajax.Request(root + "./?page=ajax_search_filters", {
		parameters: "&q=" + q1 + "&pag=1&ppag=" + ppagx + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}




function ordprice ()
{
	var filters = document.getElementsByName("filter");
	
	filter_string = '';
	
	for (i=0; i<filters.length; i++)
	{
		filter_string = filter_string + filters[i].id + '=' + filters[i].value + ',';
	}
	
	products_div = document.getElementById('products');
	ppag1 = document.getElementById('ppag').value;
	var cat_id1 = document.getElementById('cat_id').value;
	
	var ordprice1 = document.getElementById('ordprice').value;
	
	if (ordprice1==1)
	{
		ordprice1 = 0;
	}
	else
	{		
		ordprice1 = 1;
	}
	
	 document.getElementById('ordprice').value = ordprice1;
	
	new Ajax.Request(root + "./?page=ajax_filters", {
		parameters: "&cat=" + cat_id1 + "&filters=" + filter_string+ "&pag=1&ppag=" + ppag1 + "&ord=" + ordprice1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}

function applyord ()
{
	var filters = document.getElementsByName("filter");
	
	filter_string = '';
	
	for (i=0; i<filters.length; i++)
	{
		filter_string = filter_string + filters[i].id + '=' + filters[i].value + ',';
	}
	
	products_div = document.getElementById('products');
	ppag1 = document.getElementById('ppag').value;
	var cat_id1 = document.getElementById('cat_id').value;
	
	var ord1 = document.getElementById('ord').value;
	
	 document.getElementById('ordprice').value = ord1;
	
	
	new Ajax.Request(root + "./?page=ajax_filters", {
		parameters: "&cat=" + cat_id1 + "&filters=" + filter_string+ "&pag=1&ppag=" + ppag1 + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}

function applysearchord ()
{
	products_div = document.getElementById('products');
	ppag1 = document.getElementById('ppag').value;
	var q1 = document.getElementById('qq').value;
	
	var ord1 = document.getElementById('ord').value;
	
	document.getElementById('ordprice').value = ord1;
	
	new Ajax.Request(root + "./?page=ajax_search_filters", {
		parameters: "&q=" + q1 + "&pag=1&ppag=" + ppag1 + "&pord=" + ord1,
		onSuccess: function(resp) {
			products_div.innerHTML = resp.responseText;
		}
	});
}






function seltab (id, n)
{
	prod_up_div = document.getElementById('product_page_up');
	prod_up_gal_div = document.getElementById('product_page_up_galerie');
	
	if (id==5)
	{
		prod_up_div.style.display = 'none';
		prod_up_gal_div.style.display = 'block';
	}
	else
	{
		prod_up_div.style.display = 'block';
		prod_up_gal_div.style.display = 'none';
	}
	
	
	
	for (i=1; i<=n; i++)
	{
		
		tab = document.getElementById("tab" + i);
		
		if (tab)
		{
			
			tabcontent = document.getElementById("tab" + i + "-content");
	
			if (id == i)
			{
				tab.className = "tab-selected";
				tabcontent.className = "tab-content-display";
			}
			else
			{
				tab.className = "tab";
				tabcontent.className = "tab-content-hide";
			}
		}
	}
	
	return false;
}

function default_seltab ()
{
	dhref = location.href;
		
	var anchorMatch = /#tab([0-9]+)/i,match;
		
	match=anchorMatch.exec(dhref);
	
	if (match && match[1])
	{
		seltab(match[1]);
	}
}



function opencompat(id)
{
	
	thisdiv = document.getElementById('compat' + id);
	zalink = document.getElementById('compatlink' + id);
	
	if (thisdiv.style.display == 'block')
	{
		thisdiv.style.display = 'none';
		zalink.innerHTML = '[+]';
	}
	else
	{
		thisdiv.style.display = 'block';
		zalink.innerHTML = '[-]';
	}
	
	
	
	return false;
}


function popup_open ( url, w, h, namepop )
{
	if (!w) w=400; 
	if (!h) h=400; 
	if (!namepop) namepop="Popup";
  	win = window.open( url, namepop, 'scrollbars=yes, status=no, toolbar=no,menubar=yes,titlebar=yes,resizable=yes, dependent=1, z-lock=1, width='+w+',height='+h );
 	
	if ( !win )
	{
		alert('It appears that pop-up blockers are enabled on your computer, which may prevent\nsome components from functioning properly. Please temporarily disable any\npop-up blockers.\n\nTo disable the Windows XP pop-up blocker, from the Tools menu in Internet Explorer,\nselect Pop-up Blocker, then Turn Off Pop-up Blocker. To disable other pop-up blockers\nthat are part of a search engine or toolbar, right-click on a toolbar in Internet Explorer\nand click to deselect all toolbars except Standard Buttons, Address Bar, and Links.');
	}	
	else
	{		
		win.moveTo( screen.width/2-w/2, screen.height/2-h/2);
		win.focus();
	}
}


//////////////////////////

if (mobile == undefined) var mobile = {};

var documentBody = $(document.body);

mobile.BrowserCheck = {};
//test for IE6
mobile.BrowserCheck.IE6 = (function(){
	
	var isIE6 = ((navigator.appName == "Internet Explorer") || navigator.appVersion.indexOf("MSIE") !=-1) && (parseInt(navigator.appVersion) >= 6);

	if (isIE6)
		return true;
	else
		return false;
})();


mobile.InfoIconsManager = Class.create({
	
	_DISPLAY_INFO_BOX_DELAY: 200,	// ms to keep pointer over icon to open box.
	
	_currentInfoIconElement: null,
	_infoBoxElement: null,
	_closeInfoBoxHandlerPrebound: null,
	_mouseoverTimeout: null,

	/**
	 * Constructor. Attaches all event Handlers. 
	 * @param {String} infoIconClassName The CSS class name for info icon links.
	 */
	initialize: function(infoIconClassName) {
		var infoIcons = $$("." + infoIconClassName);
		infoIcons.invoke("observe", "mouseover", this._startDisplayInfoBox.bindAsEventListener(this));
		infoIcons.invoke("observe", "mouseout", this._stopDisplayInfoBox.bind(this));
		infoIcons.invoke("observe", "click", (function(event) {
			Event.findElement(event, 'a').blur();
			event.stop();
		}).bindAsEventListener());
		if (mobile.BrowserCheck.IE6) {
			document.style = [];
			this._helper = new mobile.IE6Hover();
		}
	},
	
	/**
	 * Handler starting display of info box, will be bound to mouseover event.
	 * Will start a timeout which can be cancelled by a mouseout event, to prevent flickering
	 * if info boxes when moving the pointer across an info icon.
	 * Will call {@link #_displayInfoBox} when timeout is complete.
	 * @param {Object} event
	 */
	_startDisplayInfoBox: function(event) {
		this._stopDisplayInfoBox();
		// Prototype 1.6.0.3 event bug workaround:
		//    In IE we explicitly have to clone the event element.
		//    FF ist just fine with a reference.
		//    See MRO-1.
		var theEvent = Prototype.Browser.IE ? Object.clone(event) : event;
		this._mouseoverTimeout = setTimeout(this._displayInfoBox.bind(this, theEvent), this._DISPLAY_INFO_BOX_DELAY);
	},
	
	/**
	 * Handler stopping a running mouseover timeout.
	 * To be bound to mouseout events.
	 */
	_stopDisplayInfoBox: function() {
		if (this._mouseoverTimeout) {
			clearTimeout(this._mouseoverTimeout);
			this._mouseoverTimeout = null;
		}
	},
	
	/**
	 * Displays an info box belonging to a given info icon element.
	 * Retrieves info box contents, positions the box above the icon and
	 * chooses the proper box alignment depending on viewport position.
	 * @param {Object} event
	 */
	_displayInfoBox: function(event) {
		var element = Event.findElement(event, 'a');
		// console.log("_displayInfoBox %o", element);
		
		var box = this._getInfoBox();
		if (this._currentInfoIconElement != element) {
			var content = this._getInfoBoxContent(element);
			this._updateInfoBoxContent(content);
			this._updateInfoBoxTitle(element.getAttribute('title'));
			this._currentInfoIconElement = element;
			// this._setInfoBoxPosition(element);
		}
		if (mobile.BrowserCheck.IE6) {
			element.insert({after: this._getInfoBox()});
		}
		this._setInfoBoxAlignment(element);
		box.show();
		if (mobile.BrowserCheck.IE6) {
			this._helper.showBackgroundFrame(this._getInfoBox());
		}
	},
	
	/**
	 * Closes (hides) a currently open info box.
	 * To be bound to a mouseleave event.
	 * @param {Object} event
	 * @param {Object} element
	 */
	_closeInfoBoxHandler: function(event, element) {
		// Includes a "mouseleave" emulation for FF:
		if (Prototype.Browser.IE || (event.relatedTarget != event.currentTarget && !event.relatedTarget.childOf(event.currentTarget))) {
			element.hide();
			if (mobile.BrowserCheck.IE6) {
				this._helper.hideBackgroundFrame(this._getInfoBox());
			}
			event.stop();
		}
	},
	
	/**
	 * Getter for info box element. Element will be created ({@link #_createInfoBoxElement})
	 * and attached to DOM if it doesn't exist so far.
	 * @return The info box element. 
	 */
	_getInfoBox: function() {
		if (!this._infoBoxElement) {
			this._infoBoxElement = this._createInfoBoxElement();
		}
		return this._infoBoxElement;
	},
	
	/**
	 * Creates the info box HTML element with all substructures and attaches it to the DOM.
	 * Will also initialize the mouseleave event listening for closing the info box.
	 * @return The info box element.
	 */
	_createInfoBoxElement: function() {
		var documentBody = $(document.body);
		// console.log("_createInfoBoxElement");
		var element = new Element('div', {className: 'infoBoxWrapper'});
		element.innerHTML = "<div class='infoBox'><div class='infoIcon'></div><h4>Info</h4><a href='#' class='close'>[x]</a><div class='content'></div></div>";
		documentBody.insert({bottom: element});
		element.observe(Prototype.Browser.IE ? "mouseleave" : "mouseout", this._closeInfoBoxHandler.bindAsEventListener(this, element));
		element.down('.close').observe("click", (function(event) {
			element.hide();
			event.findElement('a').blur();
			event.stop();
		}).bindAsEventListener());
		return element;
	},
	
	_updateInfoBoxContent: function(contentHTML) {
		// console.log("_updateInfoBoxContent %o", contentHTML);
		this._getInfoBox().down('.content').update(contentHTML);
	},
	
	_updateInfoBoxTitle: function(title) {
		this._getInfoBox().down('h4').update(title);
	},
	
	_getInfoBoxContent: function(linkElement) {
		// the info element content will be contained in a .infoBoxContent div right after the link.
		var contentWrapper = linkElement.next('.infoBoxContent') || linkElement.up().next('.infoBoxContent');
		if (contentWrapper) {
			// console.log("found info content %o", contentWrapper.innerHTML);
			return contentWrapper.innerHTML;		
		}
	},
	
	/**
	 * Positions the info box element above an info icon.
	 * Does not do any alignment and seems to fail sometimes in IE6, therefore deprecated.
	 * @deprecated
	 * @see #_setInfoBoxAlignment
	 * @param {Object} linkElement
	 */
	_setInfoBoxPosition: function(linkElement) {
		this._getInfoBox().clonePosition(linkElement.down('img'), {
			setWidth: false,
			setHeight: false,
			offsetLeft: -11,
			offsetTop: -11
		});
	},
	
	/**
	 * Positions the info box element above an info icon and determines whether the
	 * info box should be aligned on top, bottom, left or right side.
	 * The code is a bit verbose but should make the calculation easier to understand, I hope.
	 * In IE6 the alignment won't be 
	 */ 
	_setInfoBoxAlignment: function(linkElement) {
		
		var box = this._getInfoBox();
		var element = linkElement.down('img');
		
		var viewportDimensions = document.viewport.getDimensions();
		var viewportOffset = element.viewportOffset();
		var elementOffset = element.cumulativeOffset();
		var boxDimensions = box.getDimensions();
		
		var paddingDistance = 10;
		var hasSpaceBelow = (viewportDimensions.height - viewportOffset.top - boxDimensions.height > paddingDistance);
		var hasSpaceAbove = (viewportOffset.top - boxDimensions.height > paddingDistance);
		var hasSpaceRight = (viewportDimensions.width - viewportOffset.left - boxDimensions.width > paddingDistance);
		var hasSpaceLeft = (viewportOffset.left - boxDimensions.width > paddingDistance);
		
		var boxElement = box.down('.infoBox');
		// console.log("Box has enough space below %o, above %o, left %o, right %o", hasSpaceBelow, hasSpaceAbove, hasSpaceLeft, hasSpaceRight);
		if (!hasSpaceBelow && hasSpaceAbove) {
			box.setStyle({top: (elementOffset.top - boxDimensions.height + 2 * paddingDistance + 1) + "px"});
			boxElement.addClassName("bottom");
		} else {
			box.setStyle({top: (elementOffset.top - paddingDistance - 1) + "px"});
			boxElement.removeClassName("bottom");
		}
		if (!hasSpaceRight && hasSpaceLeft) {
			box.setStyle({left: (elementOffset.left - boxDimensions.width + 2 * paddingDistance + 1) + "px"});
			boxElement.addClassName("right");
		} else {
			box.setStyle({left: (elementOffset.left - paddingDistance - 1) + "px"});
			boxElement.removeClassName("right");			
		}	
	}
});

Element.observe(window, "load", function() {
	new mobile.InfoIconsManager('infoIconLink');
})



function show_menu_slide (id, mya)
{
     	
	if ($j("#menu_ul"+id).is(":hidden")) {
		$j("#menu_ul"+id).slideDown("fast");
		
		mya.className = "menu_ul_a_level0_open";
		
	} else {
		$j("#menu_ul"+id).slideUp("fast");
		
		mya.className = "menu_ul_a_level0_closed";
	}
	
	return false;
}