function Link(_id, _imgOut, _imgOver) {
	this.id = _id;
	this.imgOut = _imgOut;
	this.imgOver = _imgOver;
	this.children = null;
}

Link.getOverImg = function(id) {
	var link;
	var childLink; 
	for (var i=0; i<myLinks.length; i++) {
		link = myLinks[i];		
		if (link.children!=null && link.children.length > 0) {
			for (var j=0; j<link.children.length; j++) {
				childLink = link.children[j];
				if (childLink.id==id) {
					return childLink.imgOver;
				}
			}
		}
		if (link.id==id) {  
			return link.imgOver;
		}
	}
	return null;
}
Link.getOutImg = function(id) {
	var link;
	var childLink;
	for (var i=0; i<myLinks.length; i++) {
		link = myLinks[i]; 
		if (link.children!=null && link.children.length > 0) {  	
			for (var j=0; j<link.children.length; j++) {
				childLink = link.children[j];
				if (childLink.id==id) {
					return childLink.imgOut;
				}
			}
		}
		if (link.id==id) { 
			return link.imgOut;
		}
	}
	return null;
}

Link.getLinkChildren = function(parentId) {
	var link;
	var childLink;
	for (var i=0; i<myLinks.length; i++) {
		link = myLinks[i];
		if (link.id==parentId) {
			return link.children;
		}
	}
	return null;
}

var myLinks = new Array(0);

function linksRollOver(contextPath) {		
	var absPath = "http://" + location.host + contextPath + "/";
//	alert(absPath);
	var link;
	var ref;
	var childLink;
	var aux;
	
	// meniu (nou) header; ca noutate, aceastea sunt formate din 2 divuri	
	link = new Link("menupp_1_rollOver", absPath+"/images/layout/vo_meniupp_concurs.png", absPath+"/images/layout/vo_meniupp_concurs_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_2_rollOver", absPath+"/images/layout/vo_meniupp_clasament.png", absPath+"/images/layout/vo_meniupp_clasament_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_3_rollOver", absPath+"/images/layout/vo_meniupp_resurse.png", absPath+"/images/layout/vo_meniupp_resurse_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_4_rollOver", absPath+"/images/layout/vo_meniupp_utilizatori.png", absPath+"/images/layout/vo_meniupp_utilizatori_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_5_rollOver", absPath+"/images/layout/vo_meniupp_galeria.png", absPath+"/images/layout/vo_meniupp_galeria_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_7_rollOver", absPath+"/images/layout/vo_meniupp_echipa.png", absPath+"/images/layout/vo_meniupp_echipa_o.png");	
	myLinks.push(link);

	for (var i=0; i<myLinks.length; i++) {
		link = myLinks[i]; 		
		setEvents(link.id, link.children);
	}
}
function linksRollOverLogica(contextPath) {		
	var absPath = "http://" + location.host + contextPath + "/";
//	alert(absPath);
	var link;
	var ref;
	var childLink;
	var aux;
	
	// meniu (nou) header; ca noutate, aceastea sunt formate din 2 divuri	
	link = new Link("menupp_1_rollOver", absPath+"/images/logica/layout/vo_meniupp_concurs.png", absPath+"/images/logica/layout/vo_meniupp_concurs_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_2_rollOver", absPath+"/images/logica/layout/vo_meniupp_clasament.png", absPath+"/images/logica/layout/vo_meniupp_clasament_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_3_rollOver", absPath+"/images/logica/layout/vo_meniupp_resurse.png", absPath+"/images/logica/layout/vo_meniupp_resurse_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_4_rollOver", absPath+"/images/logica/layout/vo_meniupp_utilizatori.png", absPath+"/images/logica/layout/vo_meniupp_utilizatori_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_5_rollOver", absPath+"/images/logica/layout/vo_meniupp_galeria.png", absPath+"/images/logica/layout/vo_meniupp_galeria_o.png");	
	myLinks.push(link);
	
	link = new Link("menupp_7_rollOver", absPath+"/images/logica/layout/vo_meniupp_echipa.png", absPath+"/images/logica/layout/vo_meniupp_echipa_o.png");	
	myLinks.push(link);

	for (var i=0; i<myLinks.length; i++) {
		link = myLinks[i]; 		
		//setEvents(link.id, link.children);
	}
}
function setEvents(id, children) { 
	ref = document.getElementById(id);
	if (ref!=null) {	
	//	if (ref.nodeType=="img")
	//	alert(ref.nodeType);
		ref.onmouseover = function() {				
			this.style.backgroundImage = "url(" + Link.getOverImg(this.id) + ")";
			if (children!=null && children.length > 0) {
				for (var j=0; j<children.length; j++) {
					childLink = children[j];
					document.getElementById(childLink.id).style.backgroundImage = "url(" + Link.getOverImg(childLink.id) + ")";
				}
			}
		}
		ref.onmouseout = function() {
			this.style.backgroundImage = "url(" + Link.getOutImg(this.id) + ")"; 
			if (children!=null && children.length > 0) {
				for (var j=0; j<children.length; j++) {
					childLink = children[j];
					document.getElementById(childLink.id).style.backgroundImage = "url(" + Link.getOutImg(childLink.id) + ")";
				}
			}
		}			
	}
}

function setBackground(id) { 
	var children = Link.getLinkChildren(id);
	ref = document.getElementById(id);
	if (ref!=null) {				
		ref.style.backgroundImage = "url(" + Link.getOverImg(id) + ")";
		if (children!=null && children.length > 0) {
			for (var j=0; j<children.length; j++) {
				childLink = children[j];
				document.getElementById(childLink.id).style.backgroundImage = "url(" + Link.getOverImg(childLink.id) + ")";
			}
		}
		
		ref.onmouseover = null;
		ref.onmouseout = null;		
	}
}



// cookie functions ***********************************************
function getCookie(c_name) {
	if (document.cookie.length>0) { 
		//alert(document.cookie);
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
		  	c_start=c_start + c_name.length+1; 
		    c_end=document.cookie.indexOf(";",c_start);
		    if (c_end==-1) c_end=document.cookie.length;
		    return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function setCookie(c_name, value, expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
// *******************

function singleClickLink(ref, url) {				
	if (ref.nodeName != "A") return;		
	window.location.href = url; 	
	ref.onclick = function() {}		
//	var overlay = new DialogOverlay(); 
	
	var dialog = new Element('div');
//	dialog.insert(new Element('h2').insert('Dialogue'));
//	dialog.insert(new Element('p').insert('<center><img src="/KpK/images/loading.gif"></center>'));	
//	dialog.insert(new Element('p').insert('<center><img src="/KpK/images/loading.gif"><br>Te rugam sa astepti...</center>'));
	var overlay = new DialogOverlay(dialog);

	overlay.show();
}

/* chestie necesara pt swf-urile din statistici */
function setStage(nWidth, nHeight) {	
	document.getElementById('myFlash').style.width = nWidth + "px";
	document.getElementById('myFlash').style.height = nHeight + "px";
}

function popupWindow(url) {
	var w = 550;
	var h = 400;
	var properties = "toolbar=0,status=0,location=0,menubar=0,resizable=0,width=550,height=400,left="+((screen.width-w)/2)+",top="+((screen.height-h)/2);
	window.open(url, "mywindow", properties);
}