var LinkManager={
	pagelinks:new Array(),
	scriptFolder:3,
	adres:new Array(),
	getAllLinks: function(){
		//alert('cloning links');
		this.pageLinks=new Array();
		$$('a').each(function(el){LinkManager.pageLinks.push(el.href)});
	},
	manuAjaxUpdate: function(man){
		new Ajax.Request('ajax.php?page=menu&opcja=get&producent='+man+this.decodeAdres(location.href),{
			method:'get',
			//onLoad: alert('???'),
			onSuccess:function(response){
				//alert(response.responseText);
				$('left_menu_container').update(response.responseText);
			}
		});
	},
	changeManufacture: function(man){
		this.manuAjaxUpdate(man);
		this.addManufactureToLinks(man);
	},
	decodeAdres: function(url){
		var data=url.split('?');
		var adres=data[0].split('/');
		var script=adres[this.scriptFolder];
		this.adres=new Array();
		//atybuty=data[1];
		atybuty='';
		switch(script){
		case 'produkty.php':
			nazwy=['zakladka_dzial','kat','pkat','ppkat','idprod','group'];
			for(var i=0;i<adres.length-this.scriptFolder-1;i++)
			{
				if(adres[i+this.scriptFolder+1]!=undefined)
				this.adres[nazwy[i]]=adres[i+this.scriptFolder+1];
				atybuty+='&'+nazwy[i]+"="+adres[i+this.scriptFolder+1];
			}
		break;
		case 'produkt.php':
			nazwy=['idprod','group'];
			for(var i=0;i<adres.length-this.scriptFolder-1;i++)
			{
				if(adres[i+this.scriptFolder+1]!=undefined)
				this.adres[nazwy[i]]=adres[i+this.scriptFolder+1];
				atybuty+='&'+nazwy[i]+"="+adres[i+this.scriptFolder+1];
			}
		break;
		default:
			//alert('inny');
		}
			
		return atybuty;
	},
	addManufactureToLinks: function(man){
		var producent_replace=/$|(?=#)|\b\?producent=[0-9]*\b/;
		var amp_remove=/&(?=#)|&(?=$)|&amp\;(?=$)|&amp\;(?=#)/g;
		var question_remove=/\?(?=#)|\?(?=$)/g;
		var i=0;
		if(man>0)
		$$('a').each(function(el){
			if(el.href.match('produkt')){
				//el.href=LinkManager.pageLinks[i]+'?producent='+man;
				href=el.href.replace(producent_replace,'?producent='+man+'&',1);
				href=href.replace(amp_remove,'');
				el.href=href;
				//alert('link:'+el.href+"\n"+'tablica:'+LinkManager.pageLinks[i]);
			}
			i++;
		});
		else
		$$('a').each(function(el){
			if(el.href.match('produkt')){
				//el.href=LinkManager.pageLinks[i]+'?producent='+man;
				href=el.href.replace(producent_replace,'',1);
				href=href.replace(question_remove,'');
				el.href=href;
				//alert('link:'+el.href+"\n"+'tablica:'+LinkManager.pageLinks[i]);
			}
			i++;
		});
	}
}
