var menu=null;
var menup=null;
var mlayer=null;
var mlayerp=null;

var num=0;
var nowosci=new Array();
var timer1=null;
var timer2=null;
var timer3=null;
var opacity=100;
var fade=-2;

function AddNews(id,nazwa,opis,is_prod) {
	if(is_prod==1)
		nowosci.push(new Array('picture.php?lok=img_small&nr='+id,'<div>'+nazwa+'</div><a href="produkt.php?id='+id+'">'+opis+'</a>'));
	else
		nowosci.push(new Array('picture.php?lok=img_small&nr='+id,'<div>'+nazwa+'</div><a href="produktp.php?id='+id+'">'+opis+'</a>'));
}

function TestImage() {

	if (document.getElementById('n_img').complete) {
	    SetCurrentNews(num);
	    ChangeNews();
	}
	else
	    timer3=setTimeout('TestImage()',10);
}

function ChangeNews() {
	opacity+=fade;
	var nowosc=document.getElementById('nowosc');
	nowosc.style.filter='alpha(opacity='+opacity+')';
	nowosc.style.MozOpacity=opacity/100;
	if (opacity<=0) {
		fade=2;
		num=(num>=nowosci.length-1)?0:num+1;
		document.getElementById('n_img').src=nowosci[num][0];
		document.getElementById('n_txt').innerHTML=nowosci[num][1];
		TestImage();
		return;
	}
	else if (opacity>=100) {
		fade=-2;
		timer1=setTimeout('ChangeNews()',5000);
		return;
	}
	timer2=setTimeout('ChangeNews()',10);
}

function DisplayNews() {
	var n_img=document.getElementById('n_img');
	var n_txt=document.getElementById('n_txt');
	
	num=parseInt(GetCurrentNews());
	if (nowosci.length>0) {
		if (num>nowosci.length-1)
			num=0;
		n_img.src=nowosci[num][0];
		n_txt.innerHTML=nowosci[num][1];
		timer1=(nowosci.length>1)?setTimeout('ChangeNews()',5000):null;
	}
	else
		n_img.parentNode.innerHTML='';
}

function SetCurrentNews(n) {
	document.cookie='news='+n;
}

function GetCurrentNews() {
	var name="news=";
	var start=document.cookie.indexOf(name);
	if (start==-1) return 0;
	start+=name.length;
	var end=document.cookie.indexOf(";",start);
	if (end==-1) end=document.cookie.length;
	return document.cookie.substring(start,end);
}

/*var timer=null;
var o_ie=0;
var o_ff=0.0;
function WczytajMenu() {
	menu.Show();
	menu.tab.style.filter = 'alpha(opacity=0)';
	menu.tab.rows[1].cells[1].firstChild.style.filter = 'alpha(opacity=0)';
	menu.tab.style.MozOpacity=0.0;

	o_ie+=2;
	o_ff+=0.03;
	menu.tab.style.filter = 'alpha(opacity='+o_ie+')';
	menu.tab.rows[1].cells[1].firstChild.style.filter = 'alpha(opacity='+o_ie+')';
	menu.tab.style.MozOpacity=o_ff;
	if (o_ie<95)
		timer=setTimeout('WczytajMenu()',1);
}*/

Object.prototype.Super = function (supClass) {
	tempObj=new supClass();
	for (property in tempObj)
		this[property]=tempObj[property];
};
function Menu(_parent) {
	this.level=(_parent==null)?0:_parent.level+1;
	this.parent=(_parent==null)?null:_parent;
	this.classname=(arguments.length<2)?null:arguments[1];
	this.tab=null;
	this.cell=null;
	this.element=null;
	this.submenu=null;
	this.count=0;

	this.Show=function() {
		this.tab.style.display="";
	};
	this.Hide=function() {
		this.tab.style.display="none";
	};
	this.addItem=function(label) {
		var el;
		var submenu=null;
		if (arguments.length>1) {
			el=document.createElement("a");
			el.href=arguments[1];
			el.innerHTML=label;
		}
		else {
			el=document.createElement("div");
			el.innerHTML=label;
			submenu=new Menu(this,this.classname);
			submenu.element=el;
			el.onmouseover=function() {
				this.className="hover";
				submenu.Show();
				submenu.parent.submenu=submenu;
			};
			el.onmouseout=function() {
				this.className="";
				submenu.Hide();
			};
		}
		this.cell.appendChild(el);
		this.count++;
		if (submenu!=null)
			return submenu;
	};
	this.Create=function() {
		this.tab=document.createElement("table");
		this.tab.cellSpacing=0;
		this.tab.cellPadding=0;
		this.tab.style.display="none";
	    if (this.level>0) {
	    	this.tab.style.position="relative";
	    	this.tab.style.marginTop=(this.classname=="top")?this.parent.count*20:this.parent.count*25+3;
	    	this.tab.style.marginLeft=-10;
	    }

	    var tr=this.tab.insertRow(0);
	    with(tr.insertCell(0)) {width=7;height=7;}
	    tr.insertCell(1);
	    with(tr.insertCell(2)) {width=7;className="c_tr";}

	    tr=this.tab.insertRow(1);
	    tr.insertCell(0);
	    var sm=(this.classname=="top")?"sm_t":"sm_l";
	    with(tr.insertCell(1)) {
	    	var tab=document.createElement("table");
	    	tab.cellSpacing=0;
	    	tab.cellPadding=0;
	    	tab.className=sm;
	    	tab.insertRow(0).insertCell(0).height=10;
		    this.cell=tab.insertRow(1).insertCell(0);
		    this.cell.style.borderBottom=(this.classname=="top")?"0":"1px solid #BFB8A7";
		    tab.insertRow(2).insertCell(0).height=10;
		    appendChild(tab);
	    }
	    tr.insertCell(2).className="c_r";

	    tr=this.tab.insertRow(2);
	    with(tr.insertCell(0)) {height=7;className="c_bl";}
	    tr.insertCell(1).className="c_b";
	    tr.insertCell(2).className="c_br";
	    document.getElementById(sm+this.level).appendChild(this.tab);

	    var self=this;
		this.tab.onmouseover=function(e) {
			self.Show();
			var pm=self.parent;
			var el=self.element;
			while(pm!=null) {
				pm.Show();
				el.className="sel";
				el=pm.element;
				pm=pm.parent;
			}
		};
		this.tab.onmouseout=function(e) {
			self.Hide();
			var el=self.element;
			var pm=self.parent;
			while(pm!=null) {
				pm.Hide();
				el.className="";
				el=pm.element;
				pm=pm.parent;
			}
			if (self.classname=="top") {
				if (!e) var e=window.event;
				var cel=e.relatedTarget || e.toElement;
				if (cel!=null && (cel==self.tab || isChildOf(self.tab,cel) ||
					(self.submenu!=null && isChildOf(self.submenu.tab,cel)) ||
					(self.parent!=null && isChildOf(self.parent.tab,cel)) || cel==mlayer )) ;
				else
					HideLayer();
			}
		};
	};
	if(arguments.length>0)
		this.Create();
}


function MenuP(_parent) {
	this.level=(_parent==null)?0:_parent.level+1;
	this.parent=(_parent==null)?null:_parent;
	this.classname=(arguments.length<2)?null:arguments[1];
	this.tab=null;
	this.cell=null;
	this.element=null;
	this.submenu=null;
	this.count=0;

	this.Show=function() {
		this.tab.style.display="";
	};
	this.Hide=function() {
		this.tab.style.display="none";
	};
	this.addItem=function(label) {
		var el;
		var submenu=null;
		if (arguments.length>1) {
			el=document.createElement("a");
			el.href=arguments[1];
			el.innerHTML=label;
		}
		else {
			el=document.createElement("div");
			el.innerHTML=label;
			submenu=new MenuP(this,this.classname);
			submenu.element=el;
			el.onmouseover=function() {
				this.className="hover";
				submenu.Show();
				submenu.parent.submenu=submenu;
			};
			el.onmouseout=function() {
				this.className="";
				submenu.Hide();
			};
		}
		this.cell.appendChild(el);
		this.count++;
		if (submenu!=null)
			return submenu;
	};
	this.Create=function() {
		this.tab=document.createElement("table");
		this.tab.cellSpacing=0;
		this.tab.cellPadding=0;
		this.tab.style.display="none";
	    if (this.level>0) {
	    	this.tab.style.position="relative";
	    	this.tab.style.marginTop=(this.classname=="top")?this.parent.count*20:this.parent.count*25+3+316;//kk
	    	this.tab.style.marginLeft=-10;
	    }

	    var tr=this.tab.insertRow(0);
	    with(tr.insertCell(0)) {width=7;height=7;}
	    tr.insertCell(1);
	    with(tr.insertCell(2)) {width=7;className="c_tr";}

	    tr=this.tab.insertRow(1);
	    tr.insertCell(0);
	    var sm=(this.classname=="top")?"sm_t":"sm_l";
	    with(tr.insertCell(1)) {
	    	var tab=document.createElement("table");
	    	tab.cellSpacing=0;
	    	tab.cellPadding=0;
	    	tab.className=sm;
	    	tab.insertRow(0).insertCell(0).height=10;
		    this.cell=tab.insertRow(1).insertCell(0);
		    this.cell.style.borderBottom=(this.classname=="top")?"0":"1px solid #BFB8A7";
		    tab.insertRow(2).insertCell(0).height=10;
		    appendChild(tab);
	    }
	    tr.insertCell(2).className="c_r";

	    tr=this.tab.insertRow(2);
	    with(tr.insertCell(0)) {height=7;className="c_bl";}
	    tr.insertCell(1).className="c_b";
	    tr.insertCell(2).className="c_br";
	    document.getElementById(((this.classname=="top")?"smp_t":"smp_l")+this.level).appendChild(this.tab);

	    var self=this;
		this.tab.onmouseover=function(e) {
			self.Show();
			var pm=self.parent;
			var el=self.element;
			while(pm!=null) {
				pm.Show();
				el.className="sel";
				el=pm.element;
				pm=pm.parent;
			}
		};
		this.tab.onmouseout=function(e) {
			self.Hide();
			var el=self.element;
			var pm=self.parent;
			while(pm!=null) {
				pm.Hide();
				el.className="";
				el=pm.element;
				pm=pm.parent;
			}
			if (self.classname=="top") {
				if (!e) var e=window.event;
				var cel=e.relatedTarget || e.toElement;
				if (cel!=null && (cel==self.tab || isChildOf(self.tab,cel) ||
					(self.submenu!=null && isChildOf(self.submenu.tab,cel)) ||
					(self.parent!=null && isChildOf(self.parent.tab,cel)) || cel==mlayerp )) ;
				else
					HideLayerP();
			}
		};
	};
	if(arguments.length>0)
		this.Create();
}


function LeftMenu() {
	this.Super(Menu); //LeftMenu.prototype=new Menu();

	this.Show=function() {
	};
	this.Hide=function() {
	};
	this.Create=function() {
		this.cell=document.getElementById("sm_l0");
	};
	this.Create();
}

function LeftMenuP() {
	this.Super(MenuP); //LeftMenuP.prototype=new MenuP();

	this.Show=function() {
	};
	this.Hide=function() {
	};
	this.Create=function() {
		this.cell=document.getElementById("smp_l0");
	};
	this.Create();
}

// PRZESUNAC WARTSWE O PIKSEL ZEBY NIE ZNIKAL KURSOR w IE ?!
function ShowLayer() {
	//WczytajMenu();
	mlayer.style.display="";
	menu.Show();
  	//getMenu().TSetProperty("/submenu", 6,1);
}

function ShowLayerP() {
	//WczytajMenu();
	mlayerp.style.display="";
	menup.Show();
  	//getMenu().TSetProperty("/submenu", 6,1);
}

function HideLayer() {
	getMenu().TGotoFrame("/sprite2",16);
	getMenu().TPlay("/sprite2");
	mlayer.style.display="none";
}

function HideLayerP() {
	getMenu().TGotoFrame("/sprite3",16);
	getMenu().TPlay("/sprite3");
	mlayerp.style.display="none";
}

function getMenu() {
	return (navigator.appName.indexOf("Microsoft")!=-1)?
		window['menuswf']:
		document['menuswf'];
}

function isChildOf(parent,node) {
	var child=parent.getElementsByTagName(node.nodeName);
	for (var i=0;i<child.length;i++)
		if (child[i]==node) return true;
	return false;
}

function BothMenu(_left,_top) {
	this.left=_left;
	this.top=_top;
	this.addItem=function(p1,p2) {
		if (p2==null)
			return new BothMenu(this.left.addItem(p1),this.top.addItem(p1));
		return new BothMenu(this.left.addItem(p1,p2),this.top.addItem(p1,p2));
	};
}

window.onload=function()
{
	mlayer=document.createElement("div");
	mlayer.id="prod";
	mlayer.style.display="none";
	document.getElementById("sm_t0").appendChild(mlayer);

	with(mlayer) {
		onmouseover=function() {
			menu.Show();
		};
		onmouseout=function(e) {
			if (!e) var e=window.event;
			var cel=e.relatedTarget || e.toElement;
			if (cel!=null && (cel==menu.tab || isChildOf(menu.tab,cel))) return;
			menu.Hide();
			HideLayer();
		};
	}
	
	menu=new Menu(null,"top");
	CreateMenu();
	
	
	mlayerp=document.createElement("div");
	mlayerp.id="prodp";//??
	mlayerp.style.display="none";
	document.getElementById("smp_t0").appendChild(mlayerp);

	with(mlayerp) {
		onmouseover=function() {
			menup.Show();
		};
		onmouseout=function(e) {
			if (!e) var e=window.event;
			var cel=e.relatedTarget || e.toElement;
			if (cel!=null && (cel==menup.tab || isChildOf(menup.tab,cel))) return;
			menup.Hide();
			HideLayerP();
		};
	}
	
	menup=new MenuP(null,"top");
	CreateMenuP();
	
	
	DisplayNews();
};


