var lang_msg = new Array();
lang_msg['sended_msg'] = 'Mesajul a fost trimis\r\nVa multumim';
lang_msg['no_name'] = 'Nu ati completat numele';
lang_msg['no_email'] = 'Nu ati completat adresa de email';
lang_msg['invalid_email'] = 'Adresa de email nu este valida';
lang_msg['no_phone'] = 'Nu ati completat numarul de telefon';
lang_msg['invalid_phone'] = 'Numarul de telefon nu este valabil';
lang_msg['no_comments'] = 'Nu ati scris comentariile';
lang_msg['message_send'] = 'Mesajul a fost trimis cu succes';
lang_msg['message_not_send'] = 'Mesajul nu a fost trimis\r\nMai incercati o data';
lang_msg['server_error'] = 'Eroare de server';
lang_msg['no_transaction_type'] = 'Nu ati completat tipul tranzactiei';
lang_msg['no_imobil_type'] = 'Nu ati completat tipul imobilului';
lang_msg['no_city'] = 'Nu ati completat localitatea';
lang_msg['no_zone'] = 'Nu ati completat zona';
lang_msg['no_price'] = 'Nu ati completat pretul';


// echivalentul functiei implode din PHP
function implode(chunk, array)
{
	var maxim = array.length;
	var response = '';
	for (I=0; I<maxim; I++)
	{
		response += array[I];
		if (I < (maxim-1))
		{
			response += chunk;
		}
	}
	return response;
}

function validate(email)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if(reg.test(email) == false)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function hidePoze(val){
	if(val=='cerere'){
		$('poze').style.display = 'none';
	}
	else{
		$('poze').style.display = 'block';
	}
}

function validate_add()
{
	var campuri = new Array('tip_tranzactie', 'tip_imobil', 'nume', 'localitate', 'telefon', 'pret');
	
	var err = new Array();
	
	var I = 0;
	
	if ($('tip_tranzactie').value.length < 1)
	{
		err[I] = ' '+lang_msg['no_transaction_type'];
		I++;
	}
	if ($('tip_imobil').value.length < 1)
	{
		err[I] = ' '+lang_msg['no_imobil_type'];
		I++;
	}
	if ($('nume').value.length < 1)
	{
		err[I] = ' '+lang_msg['no_name'];
		I++;
	}
	if ($('localitate').value.length < 1)
	{
		err[I] = ' '+lang_msg['no_city'];
		I++;
	}
	if ($('telefon').value.length < 1)
	{
		err[I] = ' '+lang_msg['no_phone'];
		I++;
	}
	if ($('pret').value.length < 1)
	{
		err[I] = ' '+lang_msg['no_price'];
		I++;
	}
	
	if (err.length > 0)
	{
		alert(implode("\r\n", err));
	}
	else
	{
		if($('poze').style.display == 'none'){
			$('poze').remove();
		}
			
		document.my_form.submit();
	}
}

/* afiseaza taxe detaliat*/
function show_taxes_details(){
	url = "/?section=calc&screen=taxe_detaliat";
	url +="&tranzactie="+$F('tranzactie');
	url +="&pret="+$F('pret');
	url +="&termen="+$F('termen');
	url +="&valuta="+$F('valuta');

	div_manager.show_popup('popup_articol',140,300,url);
	
/*	new Ajax.Request(
		url, 
		{
		onCreate: function() {$('taxes_details').update("<div style='width:320px; font-size:12px; font-weight:bold'>Se incarca ...</div>");},
		onSuccess: function(resp) {$('taxes_details').update(resp.responseText);}
		}
	);*/
}

function stop_scroll_pics()
{
	clearTimeout(sto);
}

var sto;
function scroll_pics(a,no)
{
	div_pics = $('scroll_box_'+no);
	if(a==0) return;
	else if(a<0)
	{
		if(div_pics.scrollLeft<=0) return;
	}
	else if(a>0)
	{
		if(div_pics.scrollLeft>=div_pics.scrollWidth) return;
	}
	div_pics.scrollLeft = div_pics.scrollLeft+a;
	sto=setTimeout('scroll_pics('+a+','+no+')',30);
}

function changePic(k,i){
	$('pic_'+k).src = "/usr/thumbs/thumb_620_x_343/"+pics[k][i]['filename'];
	$('txt_'+k).innerHTML = pics[k][i]['text'];
	$('rel_'+k).href = pics[k][i]['filename1'];
}
function show_hide_text(t,str,min_h){
	if(min_h>0); else min_h = 103;
	if($(str).offsetHeight==$(str).scrollHeight){
		$(str).morph('height:'+min_h+'px');
		t.innerHTML = "mai mult";
	} else {
		$(str).morph('height:'+$(str).scrollHeight+'px');
		t.innerHTML = "restrange";
	}
}















//input files js // by ady
var InputFile = Class.create();
InputFile.prototype = {
	initialize: function(input_file)
	{
		this.input_file = input_file;
		this.draw();
	},
	draw: function()
	{
		this.parent_all = this.input_file.parentNode
		this.my_form = document.createElement("FORM");
		this.my_form.setAttribute("method","post");
		this.my_form.setAttribute("action","/index.php?section=upload&screen=add_picture&layout=ajax&ajax=1");
		this.my_form.encoding = "multipart/form-data";
		this.parent_all.appendChild(this.my_form);

		this.max_size = document.createElement("INPUT");
		this.max_size.setAttribute("type","hidden");
		this.max_size.setAttribute("name","MAX_FILE_SIZE");
		this.max_size.setAttribute("value","2097152");
		this.my_form.appendChild(this.max_size);
		
		this.my_form.appendChild(this.input_file);
	
		this.fake_div = document.createElement("DIV");
		this.fake_div.className="fake_div";
		this.my_form.appendChild(this.fake_div);

		Event.observe(this.input_file, 'change', function(){
			if(this.fake_div.lastChild) this.fake_div.removeChild(this.fake_div.lastChild);
			this.my_text = document.createTextNode(this.input_file.value.substr(this.input_file.value.lastIndexOf("\\")+1));
			this.fake_div.appendChild(this.my_text);
			this.send_file();
			activ_inputs--;
			if(activ_inputs=="0")
			{
				this.add_input;
				activ_inputs++;
				total_inputs++;
				this.add_new_file();
			}
		}.bind(this), false);
	},
	send_file: function()
	{
		AIM.submit(this.my_form, {
			'onStart': function() {
				this.se_incarca = document.createElement("SPAN");
				this.se_incarca.style.color = "red";
				this.se_incarca.appendChild(document.createTextNode(" - se incarca"));
				this.fake_div.appendChild(this.se_incarca);
				status_incarcare = 1;
			}.bind(this),
			'onComplete': function(response) {
				json_response=response.evalJSON();
				while(this.parent_all.lastChild)
				{
					this.parent_all.removeChild(this.parent_all.lastChild);
				}
				this.resp_div = document.createElement("DIV");
				this.resp_div.className="resp";
				this.parent_all.appendChild(this.resp_div);
				//alert(json_response.error);
				if(json_response.error=="0")
				{
					this.resp_div.appendChild(document.createTextNode(json_response.name+" ("+json_response.size+")"));
					this.del_link = document.createElement("SPAN");
					this.del_link.className = "del_link";
					this.del_link.appendChild(document.createTextNode(" Sterge "));
					this.resp_div.appendChild(this.del_link);
					
					this.inp_hidden = document.createElement("INPUT");
					this.inp_hidden.setAttribute("type","hidden");
					this.inp_hidden.setAttribute("name","ul_file[]");
					this.inp_hidden.setAttribute("value",json_response.file);					
					$("my_form").appendChild(this.inp_hidden);
					
					Event.observe(this.del_link, 'click', function()
						{
							$("my_form").removeChild(this.inp_hidden);
							this.resp_div.removeChild(this.del_link);
							this.resp_div.className="resp strike";
							//total_inputs--;
						}.bind(this), false
					);

				}
				else this.resp_div.appendChild(document.createTextNode(json_response.error));
				status_incarcare = 0;
			}.bind(this)
		})
		this.my_form.submit();
	},
	add_new_file: function()
	{
		desp = document.createElement("DIV");
		desp.className = "desp_mn";
		$("files").appendChild(desp);
		
		label_part = document.createElement("DIV");
		label_part.className = "label_part padded";
		label_part.appendChild(document.createTextNode('Poza '+total_inputs));
		$("files").appendChild(label_part);
		
		input_part = document.createElement("DIV");
		input_part.className = "input_part";
		$("files").appendChild(input_part);
		
		input = document.createElement("INPUT");
		input.className = "type_file";
		input.setAttribute("type","file");
		input.setAttribute("name","poza[]");
		input_part.appendChild(input);
		
		new InputFile(input);
	}
}
var SearchInputFiles = Class.create();
SearchInputFiles.prototype = {
	initialize: function()
	{
		inputs = new Array();
		inputs = $$(".type_file");
		this.input_files = new Array();
		for(i=0;i<inputs.length;i++)
		{
			this.input_files[i] = new InputFile(inputs[i]);
		}
	}
}




//cautare js //by ady
// JavaScript Document

	function addOption(selectbox,text,value )
	{
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		selectbox.options.add(optn);
	}
	
	
	function setSelectedIndexByValue(selectbox,value){
		var i=0;
		numar_optiuni = selectbox.length;
		for(i=0;i<numar_optiuni;i++){
			option = selectbox.options[i];
			if(option.value==value){
				selectbox.selectedIndex=i;
				return;
			}
		}
		selectbox.selectedIndex=0;
	}
	
	function setIndexesFromValues(selectbox,values){
		var i=0;
		numar_optiuni = selectbox.length;
		numar_valori = values.length;
		for(i=0;i<numar_optiuni;i++){
			for(j=0;j<numar_valori;j++){
				option = selectbox.options[i];
				value = values[j];
				if(option.value==value){
					selectbox.options[i].selected = true;
				}
			}
		}
	}
	
	function updateJudete(tipImobil,tipTranzactie,judet_default,zone_default)
	{
		form_tip_imobil = $('filterCLS[TIP_IMOBIL]').value ;
		tipImobil = (typeof tipImobil  == 'undefined') ? form_tip_imobil : tipImobil ;
		tipTranzactie = (typeof tipTranzactie  == 'undefined') ? $('filterCLS[TIP_TRANZ]').value : tipTranzactie ;
		domain_base = (typeof domain_base  == 'undefined') ? '/' : domain_base;


		judet_selectat  = (typeof judet_default == 'undefined') ? $F("filterEQ[ORAS]"): judet_default;

		//resetam orase
		$("filterEQ[ORAS]").options.length = 0;
		addOption($("filterEQ[ORAS]"),"Alege judet","");
		
		
		new Ajax.Request(domain_base+'index.php?section=ajax&ajax=1&screen=search_box&cmd=judete&tip_imobil=' + tipImobil + '&tip_tranz=' + tipTranzactie, 	
		{
			method:'get',
			onSuccess: function(transport)
			{
		  
					var d = transport.responseText;
					if(d !='[]')  
					{
						var json = d.evalJSON();
					}
					else
					{
						//resetam orase
						$("filterEQ[ORAS]").options.length = 0;
						addOption($("filterEQ[ORAS]"),"Nu exista oferte","");
					}
		
					for ( keyVar in json )
					{
						v = json[keyVar];
						var l = '';
						if(v=="Bucuresti") l="Bucuresti/Ilfov"; else l=v;
						addOption($("filterEQ[ORAS]"),l,v);						
					}
					setSelectedIndexByValue($("filterEQ[ORAS]"),judet_selectat);
					
					updateZone(tipImobil,tipTranzactie,judet_selectat,zone_default);
					
			}.bind(judet_selectat)
		});
	
		
	}
	
	
	function updateZone(tipImobil, tipTranzactie, oras,zone_default)
	{	
		tipImobil = (typeof tipImobil  == 'undefined') ? $('filterCLS[TIP_IMOBIL]').value : tipImobil ;
		tipTranzactie = (typeof tipTranzactie  == 'undefined') ? $('filterCLS[TIP_TRANZ]').value : tipTranzactie ;
		oras = (typeof oras  == 'undefined') ? $('filterEQ[ORAS]').value : oras ;
		
		if(typeof zone_default != 'undefined'){
			if(zone_default.localeCompare("null")!=0)
				zone_selectate = zone_default.evalJSON();
			else 
				zone_selectate = {};
		} else {
			zone_selectate = {};
		}

		$("filterEQ[ZONA]").options.length = 0;
		$("filterEQ[ZONA]").innerHTML='';
		
		//alert(tipImobil);
		
		new Ajax.Request(domain_base+'index.php?section=ajax&ajax=1&screen=search_box&cmd=zone&tip_imobil=' + tipImobil + '&tip_tranz=' + tipTranzactie + '&oras=' + oras, 
		{
				method:'get',
				onSuccess: function(transport)
				{
					
						var d = transport.responseText;
						var json = d.evalJSON();
						if(d !='[]');
						/*{
							addOption($("filterEQ[ZONA]"),"Alege zona","");
						}*/
						else 
						{
							addOption($("filterEQ[ZONA]"),"Nu exista oferte","");	
						}
			
						var nume_zona='';
						for ( keyVar in json ) 
						{
							
							if(nume_zona != keyVar)
							{
								nume_zona = keyVar;
							
								objSelect=$("filterEQ[ZONA]");
								optGroup = document.createElement('optgroup');
								optGroup.label = nume_zona;
								
							}
							for ( indx in  json[keyVar])
							{
								v = json[keyVar][indx];
								if(json[keyVar].hasOwnProperty(indx))
								{
									objOption=document.createElement("option");
									objOption.innerHTML = v;
									objOption.value = v;
									optGroup.appendChild(objOption)
								}
							}
							
							objSelect.appendChild(optGroup);

//							optGroup.appendChild(objOption);
												
						}
						
						//alert(zone_selectate);
						setIndexesFromValues($("filterEQ[ZONA]"),zone_selectate);
							
						try{
							selcb.redraw();
						} catch(e){ alert(e); }
		
				}.bind(zone_selectate)
		});
	
	}
	function validate_id(){
		if(!IsNumeric($F('id'))){
			alert('Id invalid!');
			return false;
		}else{
			document.idsForm.submit();
		}
	}



//select checkbox js //by ady

// JavaScript Document

var SelectCheckbox = Class.create();
SelectCheckbox.prototype = {
	initialize: function(myselect,options)
	{
		this.myselect = myselect;
		this.total_options = myselect.length;
		this.width_1 = (options.width_1 || 0);
		this.width_2 = (options.width_2 || 0);
		this.height_lines = (options.height_lines || 0);
		this.line_height = (options.line_height || 15);
		this.type = (options.type || "hover");
		this.options_height = this.height_lines*this.line_height;
		this.optgruoup = '';
		this.blur_it = 1;
		this.bodyblur=0;
		this.draw();
	},
	draw: function()
	{
		this.parent_all = this.myselect.parentNode;

		//creeaza combobox-ul hiddenul care va tine valorile trimise
		this.myselect.setAttribute("style","display:none");
		
		//creeaza div-ul vizual cu optiunea aleasa: e nevoie de 3 divuri pentru a afisa backgroundul
		this.div_actual_1 = document.createElement("DIV");
		this.div_actual_1.className = "select_div_actual_1";
		this.parent_all.appendChild(this.div_actual_1);
		this.div_actual_2 = document.createElement("DIV");
		this.div_actual_2.className = "select_div_actual_2";
		this.div_actual_1.appendChild(this.div_actual_2);
		this.div_actual = document.createElement("DIV");
		this.div_actual.setAttribute("id",this.myselect.name+"_div_actual");
		this.div_actual.className = "select_div_actual";
		this.div_actual_2.appendChild(this.div_actual);
		this.div_actual_text = document.createElement("DIV");
		this.div_actual_text.className = "text_select";
		this.div_actual_text.setAttribute("id",this.myselect.name+"_div_actual_text");
		this.div_actual.appendChild(this.div_actual_text);
		
		this.div_actual_text.appendChild(document.createTextNode("Alege zona"));
		
		//creeaza catcherul de evenimente
		this.eventcatcher = document.createElement("INPUT");
		this.eventcatcher.setAttribute("type","text");
		this.eventcatcher.className = "select_eventcatcher";
		this.parent_all.appendChild(this.eventcatcher);
		
		
		if(this.type=="hover"){
			Event.observe(this.div_actual,"mouseover",function(){
				this.open_options();
				this.eventcatcher.focus();
			}.bind(this));
			Event.observe(this.div_actual,"mouseout",function(evt){
				this.close_options();
			}.bind(this));
		} else if(this.type=="click"){
			Event.observe(this.div_actual,"click",function(){
				this.bodyblur=0;
				this.open_options();
				this.eventcatcher.focus();
				setTimeout("selcb.bodyblur=1;",10);			
			}.bind(this));
			Event.observe(this.eventcatcher,"blur",function(evt){
				if(this.blur_it==1)
					this.close_options();					
			}.bind(this));
			Event.observe(document.body,"click",function(evt){
				if(this.bodyblur==1){
					this.bodyblur=0;
					this.close_options();					
				}
			}.bind(this));
		}
		Event.observe(this.div_actual,"keyup",function(evt){
			this.navigate(evt);
		}.bind(this));
		
		//insereaza un clear:both inainte de optiuni
		this.my_clear = document.createElement("DIV");
		this.my_clear.className = "clear";
		this.parent_all.appendChild(this.my_clear);
		
		
		//creeaza div-ul cu optiunile selectului
		this.options = document.createElement("DIV");
		this.options.setAttribute("id",this.myselect.name+"_options");
		this.options.className = "select_options selectcb_options";
		this.options.style.display = "none";
		this.div_actual.appendChild(this.options);
		
		//elimina bugul de blur() de pe eventcatcher
		Event.observe(this.options,"mousedown",function(){
			this.blur_it=0;
			this.bodyblur=0;
		}.bind(this));
		Event.observe(this.options,"mouseup",function(){
			setTimeout("selcb.bodyblur=1;",0);
			this.blur_it=1;
		}.bind(this));
		Event.observe(this.options,"scroll",function(){
			this.blur_it=1;
			this.eventcatcher.focus();			
		}.bind(this));
		
		//adaugarea dimensiunii pe orizontala daca are si selectul
		if(this.width_1!=0)
		{
			this.div_actual.style.width = this.width_1;
			this.div_actual_text.style.width = this.width_1;
		}
		if(this.width_2!=0)
		{
			this.options.style.width = this.width_2;
		}
		//adaugare scroll pe verticala
		if(this.height_lines!=0 && this.myselect.length>this.height_lines)
		{
			this.options.style.height = this.options_height+"px";
			this.options.style.overflow = "auto";
			this.options.style.width = parseInt(this.width_2)+20+"px";
		}
		
		//afisam opgroupurile
		for(i=0;i<this.myselect.length;i++)
		{
			if(this.myselect[i].parentNode.tagName=="OPTGROUP" && this.optgroup!=this.myselect[i].parentNode.label)
			{
				this.optgroup=this.myselect[i].parentNode.label;
				this.option_label = document.createElement("DIV");
				this.option_label.className = "select_option_label";
				this.option_label.appendChild(document.createTextNode(this.myselect[i].parentNode.label));
				this.options.appendChild(this.option_label);				
			}
			new SelectCheckboxOption(this.myselect[i],this.myselect,i,this);
		}
		//cautam elementul selectat si il afisam
		//if(this.myselect.options[i].selected == true)
		//{
		//	this.act_option(this.myselect.options[i],1);
		//}
		
		//this.myselect.options[0].selected = false;
		//eliminam vechiul element <select>
		//this.parent_all.removeChild(this.myselect);
	},
	navigate:function(evt)
	{
		if(evt.keyCode=="38" || evt.keyCode=="40" || evt.keyCode=="13" || evt.keyCode=="27")
		{
			maxim = this.total_options;
			curent = -1;
			for(i=0;i<this.total_options;i++)
			{
				if($(this.myselect.name+"_my_option_"+i).className=="select_my_option hover" && curent==-1)
				{
					curent = i;
					$(this.myselect.name+"_my_option_"+i).className="select_my_option";
					break;
				}
			}
			if(curent == -1)
			{
				for(i=0;i<this.total_options;i++)
				{
					if($(this.myselect.name+"_my_option_"+i).className=="select_my_option act")
					{
						curent = i;
						break;
					}
				}
			}
			if(maxim==0) return;
			if(evt.keyCode=="40")
			{
				prev_i = curent+1;
				if(prev_i==maxim) prev_i = 0;
				my_i = prev_i;
			}
			else if(evt.keyCode=="38")
			{
				next_i = curent-1;
				if(next_i<0) next_i = maxim-1;
				my_i = next_i;
			}
			else if(evt.keyCode=="13")
			{
				my_i = curent;
				this.act_option(my_i,0);
				return;
			}
			else if(evt.keyCode=="27")
			{
				this.close_options();
				return;
			}
			if($(this.myselect.name+"_my_option_"+my_i).className!="select_my_option act")
			{
				$(this.myselect.name+"_my_option_"+my_i).className="select_my_option hover";
				poz_option = $(this.myselect.name+"_my_option_"+my_i).offsetTop;
				///*console.log*/alert(parseInt(poz_option)+"-"+(parseInt(this.options.scrollTop)+this.options_height)+' => '+(parseInt(poz_option)+this.line_height)+"px");
				if(parseInt(poz_option)>(parseInt(this.options.scrollTop)+this.options_height-this.line_height))
					this.options.scrollTop = (parseInt(poz_option)+this.line_height-this.options_height);
				else if(parseInt(poz_option)<parseInt(this.options.scrollTop))
					this.options.scrollTop = parseInt(poz_option);
			}
			return;
		}
	},
	open_options:function()
	{
		this.options.style.display = "";
	},
	close_options:function()
	{
		for(i=0;i<this.total_options;i++)
		{
			if($(this.myselect.name+"_my_option_"+i).className=="select_my_option hover")
			{
				$(this.myselect.name+"_my_option_"+i).className="select_my_option";
				break;
			}
		}
		this.options.style.display = "none";
	},
	act_option:function(my_i,ondefault)
	{	
		if($(this.myselect.name+"_my_option_"+my_i).className=="select_my_option act"){
			$(this.myselect.name+"_my_option_"+my_i).className="select_my_option";
			$(this.myselect.name+"_my_option_"+my_i).getElementsByTagName('input')[0].checked=false;
			$(this.myselect).options[my_i].selected = false;
		} else {
			$(this.myselect.name+"_my_option_"+my_i).className="select_my_option act";
			$(this.myselect.name+"_my_option_"+my_i).getElementsByTagName('input')[0].checked=true;
			$(this.myselect).options[my_i].selected = true;
		}
		
		this.setActualText();
		
		if(this.myselect.onchange!=undefined && this.myselect.onchange!="" && ondefault==0)
		{
			this.myselect.onchange.call();
		}
	},
	get_value:function(){
		return $(this.myselect.name+"_hidden_input").value;
	},
	setActualText:function(){
		var tot=0;
		var str="";
		$(this.myselect.name+"_div_actual_text").innerHTML = "";
		for(var i=0;i<this.myselect.length;i++){
			if($(this.myselect).options[i].selected){
				tot++;
				str += $(this.myselect).options[i].value+', ';
			}
		}
		str = str.substr(0,str.length-2);
		if(tot==0)
			if($("filterEQ[ORAS]").options.length>1)
				$(this.myselect.name+"_div_actual_text").innerHTML = "Alege zona";
			else
				$(this.myselect.name+"_div_actual_text").innerHTML = "nu exista oferte";
		else if(tot>2)
			$(this.myselect.name+"_div_actual_text").innerHTML = tot + " Zone selectate"; 
		else 
			$(this.myselect.name+"_div_actual_text").innerHTML = str;
	},
	redraw:function(){
		this.options.innerHTML = '';
			
		//adaugarea dimensiunii pe orizontala daca are si selectul
		if(this.width_1!=0)
		{
			this.div_actual.style.width = this.width_1;
			this.div_actual_text.style.width = this.width_1;
		}
		if(this.width_2!=0)
		{
			this.options.style.width = this.width_2;
		}
		
		//afisam opgroupurile
		var u = 0;
		for(i=0;i<this.myselect.length;i++)
		{
			if(this.myselect[i].parentNode.tagName=="OPTGROUP" && this.optgroup!=this.myselect[i].parentNode.label)
			{
				this.optgroup=this.myselect[i].parentNode.label;
				this.option_label = document.createElement("DIV");
				this.option_label.className = "select_option_label";
				this.option_label.appendChild(document.createTextNode(this.myselect[i].parentNode.label));
				this.options.appendChild(this.option_label);			
				u++;
			}
			new SelectCheckboxOption(this.myselect[i],this.myselect,i,this);
		}
		
		//adaugare scroll pe verticala
		if(this.height_lines!=0 && this.myselect.length>this.height_lines)
		{
			this.options.style.height = this.options_height+"px";
			this.options.style.overflow = "auto";
			this.options.style.width = parseInt(this.width_2)+"px";
		} else {
			this.options.style.height = (this.myselect.length+u+1)*this.line_height+"px";
		}
		
		this.setActualText();
	}
}

var SelectCheckboxOption = Class.create();
SelectCheckboxOption.prototype = {
	initialize: function(myoption,myselect,current,master_reference)
	{
		this.myselect = myselect;
		this.current = current;
		this.text = myoption.text;
		this.value = myoption.value;
		this.master_reference = master_reference;
		this.draw();
	},
	draw: function()
	{
		this.my_option = document.createElement("DIV");
		this.checkb = document.createElement("INPUT");
		this.val = document.createElement("SPAN");
		this.checkb.setAttribute("type","checkbox");
		this.checkb.className = "checkbox_opt";
		this.checkb.setAttribute("id",this.myselect.name+"_cb_"+this.current);
		this.my_option.appendChild(this.checkb);
		this.val.setAttribute("id",this.myselect.name+"_val_"+this.current);
		this.val.appendChild(document.createTextNode(this.text));
		this.my_option.appendChild(this.val);
		this.my_option.className = "select_my_option";
		this.my_option.setAttribute("value",this.value);
		this.my_option.setAttribute("id",this.myselect.name+"_my_option_"+this.current);
		$(this.myselect.name+"_options").appendChild(this.my_option);
		if(this.myselect.options[i].selected==true){
			this.checkb.checked = true;
			this.my_option.className = "select_my_option act";
		}
		Event.observe(this.my_option,"click",function(){
			this.master_reference.act_option(this.current,0);
		}.bind(this));
		Event.observe(this.my_option,"mouseover",function(){
			if(this.my_option.className!="select_my_option act")
				this.my_option.className="select_my_option hover";
		}.bind(this));
		Event.observe(this.my_option,"mouseout",function(){
			if(this.my_option.className!="select_my_option act")
				this.my_option.className="select_my_option";
		}.bind(this));
	}
}







/*
Class: Scroller
    Adds a scrollbar to a specific div. The scrollbar is implemented using a Script.aculo.us slider.
    The class reparents the original div, creates a slider and ties the reparented div to the slider,
    setting any properties necessary on the divs to make it all work. The scrollbar can be styled using
    CSS. The track of the scrollbar has class 'scroll-track', 'scroll-track-top' and 'scroll-track-bot',
    the thumb has class 'scroll-handle', 'scroll-handle-top' and 'scroll-handle-bot'.
    
properties:
    myIndex - an integer used to generate a unique ID for use in, for example, div ids.
    outerBox - the div that holds the scrollpane + scrollbar
    innerBox - the div that holds the scrollpane
    innerHeight - the height of the inner box.
    viewportHeight - the height of the view onto the scrolled div.
    track - a div that holds the script.aculo.us slider (the scrollbar)
    trackHeight - the height of the slider
    handle - the div for the 'thumb' of the scrollbar
    handleHeight - the height of the thumb
    slider - the script.aculo.us slider itself
    ieDecreaseBy - a fudge factor used when calculating the width of innerBox
    
*/
var Scroller = Class.create();

/*
property: Scroller.ids
    A cache of Scrollers indexed by the ID of the original div.
 */
Scroller.ids = new Object();

/*
property: Scroller.i
    A unique ID generator.
 */
Scroller.i = 0;

Scroller.prototype = {
    /*
    constructor: initialize 
        Wrap the passed div in a scrollpane.
    
    parameters: 
        el - the div to add a scrollbar to.
     */
  initialize: function(el) {
    this.outerBox = el;
    this.decorate();
  },
  
  /*
  function: decorate  
    create the necessary elements to implement the scrollbar and wire up events.
   */
  decorate: function() {
    $(this.outerBox).makePositioned(); // Fix IE
    
    // Seed a unique ID
    Scroller.i = Scroller.i + 1;
    this.myIndex = Scroller.i;
    
    //wrap the existing content in an intermediate inner box
    this.innerBox = document.createElement("DIV");
    this.innerBox.className="scroll-innerBox";
    $(this.innerBox).makePositioned();  // Fix IE
    this.innerBox.style.cssFloat=this.innerBox.style.styleFloat='left'; // Need the scrollbar to appear next to the scrollpane
    this.innerBox.id="scroll-innerBox-"+Scroller.i;
    this.innerBox.style.top = "0px";
    
    //Transfer the contents of Outer Box to Inner Box
    while (this.outerBox.hasChildNodes()) {
        this.innerBox.appendChild(this.outerBox.firstChild);
    }
    this.innerBox.style.overflow="hidden";
    //turn off scrolling on the outer div
    this.outerBox.style.overflow="hidden";

    // create a track
    this.track=document.createElement('div');
    this.track.className="scroll-track";
    $(this.track).makePositioned();
    this.track.style.cssFloat=this.track.style.styleFloat='left';
    this.track.id="scroll-track-"+Scroller.i;
    // Fix IE line-height bug. Sigh.
    this.track.appendChild(document.createComment(''));

    // Create the top button
    this.tracktop=document.createElement('div');
    this.tracktop.className="scroll-track-top";
    $(this.tracktop).makePositioned();
    this.tracktop.style.cssFloat=this.tracktop.style.styleFloat='left';
    this.tracktop.id="scroll-track-top-"+Scroller.i;
    // Fix IE line-height bug. Sigh.
    this.tracktop.appendChild(document.createComment(''));
    
    // Create the bottom button
    this.trackbot=document.createElement('div');
    this.trackbot.className="scroll-track-bot";
    $(this.trackbot).makePositioned();
    this.trackbot.style.cssFloat=this.trackbot.style.styleFloat='left';
    this.trackbot.id="scroll-track-bot-"+Scroller.i;
    // Fix IE line-height bug. Sigh.
    this.trackbot.appendChild(document.createComment(''));

    // Create the handle
    this.handle=document.createElement('div');
    this.handle.className="scroll-handle-container";
    this.handle.id="scroll-handle-container"+Scroller.i;

    // Create the handle middle
    this.handle_middle=document.createElement('div');
    this.handle_middle.className="scroll-handle";
    $(this.handle_middle).makePositioned();
    this.handle_middle.id="scroll-handle-"+Scroller.i;
    // Fix IE line-height bug. Sigh.
    this.handle_middle.appendChild(document.createComment(''));

    // Create the handle top cap
    this.handletop=document.createElement('div');
    this.handletop.className="scroll-handle-top";
    $(this.handletop).makePositioned();
    this.handletop.id="scroll-handle-top-"+Scroller.i;
    // Fix IE line-height bug. Sigh.
    this.handletop.appendChild(document.createComment(''));

    // Create the handle bottom cap
    this.handlebot=document.createElement('div');
    this.handlebot.className="scroll-handle-bot";
    $(this.handlebot).makePositioned();
    this.handlebot.id="scroll-handle-bot-"+Scroller.i;
    // Fix IE line-height bug. Sigh.
    this.handlebot.appendChild(document.createComment(''));

    this.track.hide();
    this.tracktop.hide();
    this.trackbot.hide();

    this.outerBox.appendChild(this.innerBox);
    this.outerBox.appendChild(this.tracktop);
    this.handle.appendChild(this.handletop);
    this.handle.appendChild(this.handle_middle);
    this.handle.appendChild(this.handlebot);
    this.track.appendChild(this.handle);
    this.outerBox.appendChild(this.track);
    this.outerBox.appendChild(this.trackbot);

    this.slider = new Control.Slider($(this.handle).id, $(this.track).id, {axis:'vertical',
                                     minimum: 0,
                                     maximum: $(this.outerBox).clientHeight});
    this.slider.options.onSlide = this.slider.options.onChange = this.onChange.bind(this);
    setTimeout(this.resetScrollbar.bind(this, false), 10);

    this.domMouseCB = this.MouseWheelEvent.bindAsEventListener(this, this.slider);
    this.mouseWheelCB = this.MouseWheelEvent.bindAsEventListener(this, this.slider);
    this.trackTopCB = this.tracktopEvent.bindAsEventListener(this, this.slider);
    this.trackBotCB = this.trackbotEvent.bindAsEventListener(this, this.slider);
    
    //Events control
    $(this.outerBox).observe('DOMMouseScroll', this.domMouseCB); // Mozilla
    $(this.outerBox).observe('mousewheel', this.mouseWheelCB);// IE/Opera
    $(this.tracktop).observe('mousedown', this.trackTopCB);
    $(this.trackbot).observe('mousedown', this.trackBotCB);
  },
  
  release: function() {
    $(this.outerBox).stopObserving('DOMMouseScroll', this.domMouseCB);
    $(this.outerBox).stopObserving('mousewheel', this.mouseWheelCB);// IE/Opera
    $(this.tracktop).stopObserving('mousedown', this.trackTopCB);
    $(this.trackbot).stopObserving('mousedown', this.trackBotCB);
  },
  
  /*
  function: resetScrollbar  
    Re-calculate the geometry of the scrollbar. Typically called from an event handler.
    
    args:   
        repeat - if true, set timer to re-calculate to fix IE bug on resize window.
   */
  resetScrollbar: function(repeat) {
        this.track.hide();
        this.tracktop.hide();
        this.trackbot.hide();
        this.enableScroll = false;
        this.innerHeight = $(this.outerBox).clientHeight;
        this.innerBox.style.height = this.innerHeight + "px";
        var newWidth = $(this.outerBox).clientWidth;

        var tth = Element.getStyle(this.tracktop,"height");
        if (tth)
           tth = tth.replace("px","");
        else
           tth = 0;
    
        var hth = Element.getStyle(this.handletop,"height");
        if (hth)
           hth = hth.replace("px","");
        else
           hth = 0;
    
        if (this.innerHeight < this.innerBox.scrollHeight) {
            this.viewportHeight = this.innerHeight - tth*2;
            this.slider.trackLength = this.viewportHeight;
            this.track.style.height = this.viewportHeight + "px";       
            this.handleHeight = Math.round(this.viewportHeight * this.innerHeight / this.innerBox.scrollHeight);    
            if(this.handleHeight < (hth*2))
                this.handleHeight = (hth*2);
            if (this.handleHeight < 10)
                 this.handleHeight = 10;
            this.handle.style.height = this.handleHeight + "px";
            this.handle_middle.style.height = this.handleHeight - hth*2 + "px";
            this.handletop.style.height = hth + "px";
            this.slider.handleLength = this.handleHeight;
            this.track.style.display = 'inline';
            this.tracktop.style.display = 'inline';
            this.trackbot.style.display = 'inline';
            this.ieDecreaseBy = 1;   // Firefox seems to have an off-by one error, so allow for it.
            if (this.outerBox.currentStyle) {
                var borderWidth = this.outerBox.currentStyle["borderWidth"].replace("px","");
                if(!isNaN(borderWidth)) {
                    this.ieDecreaseBy = (borderWidth) * 2;
                }
            }
            newWidth = ($(this.outerBox).clientWidth - $(this.track).clientWidth - this.ieDecreaseBy);
            this.enableScroll = true;
        }
        //Set the width of of the scrollpane (aka innerBox).
        this.innerBox.style.width = newWidth + "px";
        //Fix IE resize event Bug 
        if(repeat) {
            setTimeout(this.resetScrollbar.bind(this, false), 10);
        }
  },
  
    //Mouse wheel code from http://adomas.org/javascript-mouse-wheel/
    MouseWheelEvent: function(event, slider) {
        var delta = 0;
        if (!event) //For IE.
            event = window.event;
        if (event.wheelDelta) { //IE/Opera.
            delta = event.wheelDelta / 120;
            /*if (window.opera) //In Opera 9, delta differs in sign as compared to IE
                delta = -delta;   But it isn't necessary with Opera v9.51*/
        } else if (event.detail) { //Mozilla case
            delta = -event.detail / 3;
        }
        if (delta)
            slider.setValueBy(-delta / 10);
        Event.stop(event);
    },

    trackbotEvent: function(event, slider) {
        if (Event.isLeftClick(event)) { 
            slider.setValueBy(0.2);
            Event.stop(event);
        }
    },

    tracktopEvent: function(event, slider) {
        if (Event.isLeftClick(event)) {
            slider.setValueBy(-0.2);
            Event.stop(event);
        }
    },

  /*
  function: onChange  
    Called when the script.aculo.us slider has changed (i.e. when it has been dragged). Scroll the inner box.
    
    args:   
        val - not used.
   */
    onChange: function(val) {
        if(this.enableScroll)
            this.innerBox.scrollTop = Math.round (val * (this.innerBox.scrollHeight-this.innerBox.offsetHeight));
    }
}

/*
function: Scroller.setAll
    Search for divs of the class 'makeScroll' and wrap them in a Scroller.
 */
Scroller.setAll = function () {
    $$('.makeScroll').each(function(item) {
        Scroller.ids[item.id] = new Scroller(item);
    });
}

/*
function: Scroller.reset
    If the passed element has class 'makeScroll', wrap it in a Scroller.
 */
Scroller.reset = function (body_id) {
    if ($(body_id).className.match(new RegExp("(^|\\s)makeScroll(\\s|$)"))) {
       if (Scroller.ids[body_id])
           Scroller.ids[body_id].release();
           
        Scroller.ids[body_id] = new Scroller($(body_id));
    }
}

/*
property: Scroller.updateAll
    Reset all of the scrollbars.
 */
Scroller.updateAll = function () {
    $H(Scroller.ids).each(function(pair) {
        Scroller.ids[pair.key].resetScrollbar(true);
    });
}

/*
    Hook up some global event handlers.
 */
Event.observe(window, "load", Scroller.setAll);
Event.observe(window, "resize", Scroller.updateAll);




//lightbox js // de la romanialibera //by ady

// -----------------------------------------------------------------------------------
//
//	Lightbox v2.03.2
//	by Lokesh Dhakar - http://www.huddletogether.com
//	4/30/06
//
//	For more information on this script, visit:
//	http://huddletogether.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------
/*

	Table of Contents
	-----------------
	Configuration
	Global Variables

	Extending Built-in Objects	
	- Object.extend(Element)
	- Array.prototype.removeDuplicates()
	- Array.prototype.empty()

	Lightbox Class Declaration
	- initialize()
	- start()
	- changeImage()
	- resizeImageContainer()
	- showImage()
	- updateDetails()
	- updateNav()
	- enableKeyboardNav()
	- disableKeyboardNav()
	- keyboardAction()
	- preloadNeighborImages()
	- end()
	
	Miscellaneous Functions
	- getPageScroll()
	- getPageSize()
	- getKey()
	- listenKey()
	- showSelectBoxes()
	- hideSelectBoxes()
	- showFlash()
	- hideFlash()
	- pause()
	- initLightbox()
	
	Function Calls
	- addLoadEvent(initLightbox)
	
*/
// -----------------------------------------------------------------------------------

//
//	Configuration
//
var fileLoadingImage = "/plugins/lgt/images/loading.gif";		
var fileBottomNavCloseImage = "/plugins/lgt/images/closelabel.gif";
var fileBottomSigla = "/plugins/lgt/images/sigla.jpg";

var overlayOpacity = 0.6;	// controls transparency of shadow overlay

var animate = true;			// toggles resizing animations
var resizeSpeed = 7;		// controls the speed of the image resizing animations (1=slowest and 10=fastest)

var borderSize = 10;		//if you adjust the padding in the CSS, you will need to update this variable

// -----------------------------------------------------------------------------------

//
//	Global Variables
//
var imageArray = new Array;
var activeImage;

var track_open=0;

if(animate == true){
	overlayDuration = 0.2;	// shadow fade in/out duration
	if(resizeSpeed > 10){ resizeSpeed = 10;}
	if(resizeSpeed < 1){ resizeSpeed = 1;}
	resizeDuration = (11 - resizeSpeed) * 0.15;
} else { 
	overlayDuration = 0;
	resizeDuration = 0;
}

// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//	- array.removeDuplicates()
//	- array.empty()
//
Array.prototype.removeDuplicates = function () {
    for(i = 0; i < this.length; i++){
        for(j = this.length-1; j>i; j--){        
            if(this[i][0] == this[j][0]){
                this.splice(j,1);
            }
        }
    }
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

// -----------------------------------------------------------------------------------

//
//	Lightbox Class Declaration
//	- initialize()
//	- start()
//	- changeImage()
//	- resizeImageContainer()
//	- showImage()
//	- updateDetails()
//	- updateNav()
//	- enableKeyboardNav()
//	- disableKeyboardNav()
//	- keyboardNavAction()
//	- preloadNeighborImages()
//	- end()
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//
var Lightbox = Class.create();

Lightbox.prototype = {
	
	// initialize()
	// Constructor runs on completion of the DOM loading. Loops through anchor tags looking for 
	// 'lightbox' references and applies onclick events to appropriate links. The 2nd section of
	// the function inserts html at the bottom of the page which is used to display the shadow 
	// overlay and the image container.
	//
	initialize: function() {	
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');
		var areas = document.getElementsByTagName('area');
		this.relAttribute = '';
		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.getAttribute('rel'));
			this.relAttribute = relAttribute;
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
				anchor.onclick = function () {myLightbox.start(this); return false;}
			}
		}

		// loop through all area tags
		// todo: combine anchor & area tag loops
		for (var i=0; i< areas.length; i++){
			var area = areas[i];
			
			var relAttribute = String(area.getAttribute('rel'));
			this.relAttribute = relAttribute;
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (area.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
				area.onclick = function () {myLightbox.start(this); return false;}
			}
		}

		// The rest of this code inserts html at the bottom of the page that looks similar to this:
		//
		//	<div id="overlay"></div>
		//	<div id="lightbox">
		//		<div id="outerImageContainer">
		//			<div id="imageContainer">
		//				<img id="lightboxImage">
		//				<div style="" id="hoverNav">
		//					<a href="#" id="prevLink"></a>
		//					<a href="#" id="nextLink"></a>
		//				</div>
		//				<div id="loading">
		//					<a href="#" id="loadingLink">
		//						<img src="/plugins/lgt/images/loading.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//		<div id="imageDataContainer">
		//			<div id="imageData">
		//				<div id="imageDetails">
		//					<span id="caption"></span>
		//					<span id="numberDisplay"></span>
		//				</div>
		//				<div id="bottomNav">
		//					<a href="#" id="bottomNavClose">
		//						<img src="/plugins/lgt/images/close.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//	</div>


		var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myLightbox.end(); }
		objBody.appendChild(objOverlay);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
			if (!e) var e = window.event;
			var clickObj = Event.element(e).id;
			if ( clickObj == 'lightbox') {
				myLightbox.end();
			}
		};
		objBody.appendChild(objLightbox);
			
		var objOuterImageContainer = document.createElement("div");
		objOuterImageContainer.setAttribute('id','outerImageContainer');
		objLightbox.appendChild(objOuterImageContainer);

		// When Lightbox starts it will resize itself from 250 by 250 to the current image dimension.
		// If animations are turned off, it will be hidden as to prevent a flicker of a
		// white 250 by 250 box.
		if(animate){
			Element.setWidth('outerImageContainer', 250);
			Element.setHeight('outerImageContainer', 250);			
		} else {
			Element.setWidth('outerImageContainer', 1);
			Element.setHeight('outerImageContainer', 1);			
		}

		var objImageContainer = document.createElement("div");
		objImageContainer.setAttribute('id','imageContainer');
		objOuterImageContainer.appendChild(objImageContainer);
	
		var objLightboxImage = document.createElement("img");
		objLightboxImage.setAttribute('id','lightboxImage');
		objImageContainer.appendChild(objLightboxImage);
	
		var objHoverNav = document.createElement("div");
		objHoverNav.setAttribute('id','hoverNav');
		objImageContainer.appendChild(objHoverNav);
	
		var objPrevLink = document.createElement("a");
		objPrevLink.setAttribute('id','prevLink');
		objPrevLink.setAttribute('href','#');
		objHoverNav.appendChild(objPrevLink);
		
		var objNextLink = document.createElement("a");
		objNextLink.setAttribute('id','nextLink');
		objNextLink.setAttribute('href','#');
		objHoverNav.appendChild(objNextLink);
	
		var objLoading = document.createElement("div");
		objLoading.setAttribute('id','loading');
		objImageContainer.appendChild(objLoading);
	
		var objLoadingLink = document.createElement("a");
		objLoadingLink.setAttribute('id','loadingLink');
		objLoadingLink.setAttribute('href','#');
		objLoadingLink.onclick = function() { myLightbox.end(); return false; }
		objLoading.appendChild(objLoadingLink);
	
		var objLoadingImage = document.createElement("img");
		objLoadingImage.setAttribute('src', fileLoadingImage);
		objLoadingLink.appendChild(objLoadingImage);

		var objImageDataContainer = document.createElement("div");
		objImageDataContainer.setAttribute('id','imageDataContainer');
		objLightbox.appendChild(objImageDataContainer);

		var objImageData = document.createElement("div");
		objImageData.setAttribute('id','imageData');
		objImageDataContainer.appendChild(objImageData);
	
		var objImageDetails = document.createElement("div");
		objImageDetails.setAttribute('id','imageDetails');
		objImageData.appendChild(objImageDetails);
	
		var objCaption = document.createElement("span");
		objCaption.setAttribute('id','caption');
		objImageDetails.appendChild(objCaption);
	
		var objDescription = document.createElement("span");
		objDescription.setAttribute('id','lbDescription');
		objImageDetails.appendChild(objDescription);

		var objnumberLink = document.createElement("span");
		objnumberLink.setAttribute('id','numberLink');
		objImageDetails.appendChild(objnumberLink);

		var objNumberDisplay = document.createElement("span");
		objNumberDisplay.setAttribute('id','numberDisplay');
		objnumberLink.appendChild(objNumberDisplay);

		var objlinkArticol = document.createElement("span");
		objlinkArticol.setAttribute('id','linkArticol');
		objnumberLink.appendChild(objlinkArticol);		

		var objBottomNav = document.createElement("div");
		objBottomNav.setAttribute('id','bottomNav');
		objImageData.appendChild(objBottomNav);
	
		var objBottomNavCloseLink = document.createElement("a");
		objBottomNavCloseLink.setAttribute('id','bottomNavClose');
		objBottomNavCloseLink.setAttribute('href','#');
		objBottomNavCloseLink.onclick = function() { myLightbox.end(); return false; }
		objBottomNav.appendChild(objBottomNavCloseLink);

		var objBottomNavCloseImage = document.createElement("img");
		objBottomNavCloseImage.setAttribute('src', fileBottomNavCloseImage);
		objBottomNavCloseLink.appendChild(objBottomNavCloseImage);

/*		var objBottomNavCloseLink = document.createElement("img");
		objBottomNavCloseLink.setAttribute('id','fileBottomSigla');
		objBottomNavCloseLink.setAttribute('src', fileBottomSigla);*/
		
		objBottomNav.appendChild(objBottomNavCloseLink);	
	},
	
	//
	//	start()
	//	Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
	//
	start: function(imageLink) {	

		hideSelectBoxes();
		hideFlash();

		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setHeight('overlay', arrayPageSize[1]);

		new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity });

		imageArray = [];
		imageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName( imageLink.tagName);


		// if image is NOT part of a set..
		if((imageLink.getAttribute('rel') == 'lightbox')){
			// add single image to imageArray
			imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title'), imageLink.getAttribute('id'), 'lightbox'));			
		} else {
		// if image is part of a set..

			// loop through anchors, find other images in set, and add them to imageArray
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					rel = anchor.getAttribute('rel').substring(anchor.getAttribute('rel').indexOf('[')+1, anchor.getAttribute('rel').lastIndexOf(']'));
					imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title'), anchor.getAttribute('id'), rel));
				}
			}
			imageArray.removeDuplicates();
			while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
		}

		// calculate top offset for the lightbox and display 
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);

		Element.setTop('lightbox', lightboxTop);
		Element.show('lightbox');
		
		this.changeImage(imageNum);
	},

	//
	//	changeImage()
	//	Hide most elements and preload image in preparation for resizing image container.
	//
	changeImage: function(imageNum) {	
		
		activeImage = imageNum;	// update global var

		// hide elements during transition
		if(animate){ Element.show('loading');}
		Element.hide('lightboxImage');
		Element.hide('hoverNav');
		Element.hide('prevLink');
		Element.hide('nextLink');
		Element.hide('imageDataContainer');
		Element.hide('numberLink');
	
		imgPreloader = new Image();
		
		// once image is preloaded, resize image container
		imgPreloader.onload=function(){
			Element.setSrc('lightboxImage', imageArray[activeImage][0]);
			//Element.setWidth('lightboxImage', imageArray[activeImage][0]);
			myLightbox.resizeImageContainer(imgPreloader.width, imgPreloader.height);
//			alert('a');
//			alert(imgPreloader.width + " " +  imgPreloader.height);
			imgPreloader.onload=function(){};	//	clear onLoad, IE behaves irratically with animated gifs otherwise 
		}
		imgPreloader.src = imageArray[activeImage][0];
	},

	//
	//	resizeImageContainer()
	//
	resizeImageContainer: function( imgWidth, imgHeight) {

		// get curren width and height
		this.widthCurrent = Element.getWidth('outerImageContainer');
		this.heightCurrent = Element.getHeight('outerImageContainer');

		// get new width and height
		var widthNew = (imgWidth  + (borderSize * 2));
		var heightNew = (imgHeight  + (borderSize * 2));

		// scalars based on change from old to new
		this.xScale = ( widthNew / this.widthCurrent) * 100;
		this.yScale = ( heightNew / this.heightCurrent) * 100;

		// calculate size difference between new and old image, and resize if necessary
		wDiff = this.widthCurrent - widthNew;
		hDiff = this.heightCurrent - heightNew;

		if(!( hDiff == 0)){ new Effect.Scale('outerImageContainer', this.yScale, {scaleX: false, duration: resizeDuration, queue: 'front'}); }
		if(!( wDiff == 0)){ new Effect.Scale('outerImageContainer', this.xScale, {scaleY: false, delay: resizeDuration, duration: resizeDuration}); }

		// if new and old image are same size and no scaling transition is necessary, 
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);} 
		}

		Element.setHeight('prevLink', imgHeight);
		Element.setHeight('nextLink', imgHeight);
		Element.setWidth( 'imageDataContainer', widthNew);
		
		Element.setWidth( 'lightboxImage',imgWidth);
		Element.setHeight( 'lightboxImage',imgHeight);

		this.showImage();
	},
	
	//
	//	showImage()
	//	Display image and begin preloading neighbors.
	//
	showImage: function(){
		Element.hide('loading');
		new Effect.Appear('lightboxImage', { duration: resizeDuration, queue: 'end', afterFinish: function(){	myLightbox.updateDetails(); } });
		this.preloadNeighborImages();
		if(track_open==0 && $('for_ganal')){
			pageTracker._trackEvent('lightbox', 'open', $('for_ganal').innerHTML);
			track_open = 1;
		}
	},

	//
	//	updateDetails()
	//	Display caption, image number, and bottom nav.
	//
	updateDetails: function() {
	
		Element.show('caption');
		Element.setInnerHTML( 'caption', imageArray[activeImage][1]);

		if(imageArray[activeImage][2] && $("description_"+imageArray[activeImage][2]))
		{
			Element.show('lbDescription');
			Element.setInnerHTML( 'lbDescription', $("description_"+imageArray[activeImage][2]).innerHTML);
		}
		else
		{
			Element.setInnerHTML( 'lbDescription', '');
		}
		
		if(imageArray[activeImage][2] && $(imageArray[activeImage][3]+"_description_"+imageArray[activeImage][2]))
		{
			Element.show('lbDescription');
			Element.setInnerHTML( 'lbDescription', $(imageArray[activeImage][3]+"_description_"+imageArray[activeImage][2]).innerHTML);
		}
		else
		{
			Element.setInnerHTML( 'lbDescription', '');
		}		

		if(imageArray[activeImage][2] && $(imageArray[activeImage][3]+"_link_"+imageArray[activeImage][2]))
		{
			Element.show('linkArticol');
			Element.setInnerHTML( 'linkArticol', $(imageArray[activeImage][3]+"_link_"+imageArray[activeImage][2]).innerHTML);
		}
		else
		{
			Element.setInnerHTML( 'linkArticol', '');
		}

		// if image is part of set display 'Image x of x' 
		if(imageArray.length > 1){
			Element.show('numberLink');
			Element.setInnerHTML( 'numberDisplay', "Imaginea " + eval(activeImage + 1) + "/" + imageArray.length);
		}

		new Effect.Parallel(
			[ new Effect.SlideDown( 'imageDataContainer', { sync: true, duration: resizeDuration, from: 0.0, to: 1.0 }), 
			  new Effect.Appear('imageDataContainer', { sync: true, duration: resizeDuration }) ], 
			{ duration: resizeDuration, afterFinish: function() {
				// update overlay size and update nav
				var arrayPageSize = getPageSize();
				Element.setHeight('overlay', arrayPageSize[1]);
				myLightbox.updateNav();
				}
			} 
		);
	},

	//
	//	updateNav()
	//	Display appropriate previous and next hover navigation.
	//
	updateNav: function() {

		Element.show('hoverNav');				

		// if not first image in set, display prev image button
		if(activeImage != 0){
			Element.show('prevLink');
			document.getElementById('prevLink').onclick = function() {
				//if($('for_ganal')) pageTracker._trackEvent('lightbox', 'prev', $('for_ganal').innerHTML);
				myLightbox.changeImage(activeImage - 1); return false;
			}
		}

		// if not last image in set, display next image button
		if(activeImage != (imageArray.length - 1)){
			Element.show('nextLink');
			document.getElementById('nextLink').onclick = function() {
				//if($('for_ganal')) pageTracker._trackEvent('lightbox', 'next', $('for_ganal').innerHTML);
				myLightbox.changeImage(activeImage + 1); return false;
			}
		}
		
		this.enableKeyboardNav();
	},

	//
	//	enableKeyboardNav()
	//
	enableKeyboardNav: function() {
		document.onkeydown = this.keyboardAction; 
	},

	//
	//	disableKeyboardNav()
	//
	disableKeyboardNav: function() {
		document.onkeydown = '';
	},

	//
	//	keyboardAction()
	//
	keyboardAction: function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
			escapeKey = 27;
		} else { // mozilla
			keycode = e.keyCode;
			escapeKey = e.DOM_VK_ESCAPE;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapeKey)){	// close lightbox
			myLightbox.end();
		} else if((key == 'p') || (keycode == 37)){	// display previous image
			if(activeImage != 0){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage - 1);
			}
		} else if((key == 'n') || (keycode == 39)){	// display next image
			if(activeImage != (imageArray.length - 1)){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage + 1);
			}
		}

	},

	//
	//	preloadNeighborImages()
	//	Preload previous and next images.
	//
	preloadNeighborImages: function(){

		if((imageArray.length - 1) > activeImage){
			preloadNextImage = new Image();
			preloadNextImage.src = imageArray[activeImage + 1][0];
		}
		if(activeImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = imageArray[activeImage - 1][0];
		}
	
	},

	//
	//	end()
	//
	end: function() {
		this.disableKeyboardNav();
		Element.hide('lightbox');
		new Effect.Fade('overlay', { duration: overlayDuration});
		showSelectBoxes();
		showFlash();
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
// ---------------------------------------------------


function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}


// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Help from Ran Bar-On [ran2103@gmail.com]
//

function pause(ms){
	var date = new Date();
	curDate = null;
	do{var curDate = new Date();}
	while( curDate - date < ms);
}
/*
function pause(numberMillis) {
	var curently = new Date().getTime() + sender;
	while (new Date().getTime();	
}
*/
// ---------------------------------------------------



function initLightbox() { myLightbox = new Lightbox(); }
Event.observe(window, 'load', initLightbox, false);

















//lightdiv js //by ady

Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

var	overlayDuration = 0.2;	// shadow fade in/out duration
var overlayOpacity = 0.6;	// controls transparency of shadow overlay

var Lightdiv = Class.create();

//
//  Configurationl
//
LightdivOptions = Object.extend({
    fileLoadingImage:        '/plugins/lightbox/images/loading.gif',     
    fileBottomNavCloseImage: '/plugins/lightbox/images/closelabel.gif',

    overlayOpacity: 0.8,   // controls transparency of shadow overlay

    animate: true,         // toggles resizing animations
    resizeSpeed: 7,        // controls the speed of the image resizing animations (1=slowest and 10=fastest)

    borderSize: 10,         //if you adjust the padding in the CSS, you will need to update this variable

	// When grouping images this is used to write: Image # of #.
	// Change it for non-english localization
	labelImage: "Imaginea",
	labelOf: "din"
}, window.LightdivOptions || {});

Lightdiv.prototype = {
	    initialize: function() {    

	        this.keyboardAction = this.keyboardAction.bindAsEventListener(this);
			this.load_ajax=true;

        var objBody = document.body;
//		alert(objBody);

		var node_popup = Builder.node('div',{id:'popup_overlay'});
		objBody.appendChild(node_popup);
	
        objBody.appendChild(Builder.node('div',{id:'popup_lightbox'}, [
            Builder.node('div',{id:'popup_outerContainer'}, 
                Builder.node('div',{id:'popup_Container'}, [
                    Builder.node('div',{id:'popup_lightboxImage'})
                ])
            )
        ]));
//		$('popup_overlay').hide();
		$('popup_overlay').hide().observe('click', (function() { this.end_overlay(); }).bind(this));
//	$('popup_lightbox').hide();//.observe('click', (function() { this.end_overlay(); }).bind(this));

		},
		
    getPageSize: function() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}
	,

	showSelectBoxes:function (){
		var selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
		}
	},

// ---------------------------------------------------

	hideSelectBoxes:function(){
		var selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "hidden";
		}
	},

	// ---------------------------------------------------
	
	showFlash: function (){
		var flashObjects = document.getElementsByTagName("object");
		for (i = 0; i < flashObjects.length; i++) {
			flashObjects[i].style.visibility = "visible";
		}
	
		var flashEmbeds = document.getElementsByTagName("embed");
		for (i = 0; i < flashEmbeds.length; i++) {
			flashEmbeds[i].style.visibility = "visible";
		}
	},

// ---------------------------------------------------
	
	hideFlash:function (){
		var flashObjects = document.getElementsByTagName("object");
		for (i = 0; i < flashObjects.length; i++) {
			flashObjects[i].style.visibility = "hidden";
		}
	
		var flashEmbeds = document.getElementsByTagName("embed");
		for (i = 0; i < flashEmbeds.length; i++) {
			flashEmbeds[i].style.visibility = "hidden";
		}
	
	},

	keyboardAction: function(event) {
        var keycode = event.keyCode;
        var escapeKey;
/*        if (event.DOM_VK_ESCAPE) {  // mozilla
            escapeKey = event.DOM_VK_ESCAPE;
        } else { // ie
            escapeKey = 27;
        }

        var key = String.fromCharCode(keycode).toLowerCase();
        if (key.match(/x|o|c/) || (keycode == escapeKey)){ // close lightdiv
            this.end_overlay();
        } */
    },
	start_overlay:function(){
			this.hideSelectBoxes();
			this.hideFlash();	
			var arrayPageSize = this.getPageSize();
			$('popup_overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
			new Effect.Appear('popup_overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity });
	},
	end_overlay: function(){
			this.showSelectBoxes();
			this.showFlash();	
			new Effect.Fade('popup_overlay', { duration: overlayDuration});
			$('popup_lightbox').hide()
	},

	show_popup: function (id,x,y,url){
			this.start_overlay();
			var popUp = document.getElementById(id);
			var w=240;
			var h=100;
			x = x + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
			y = (screen.width-y)/2;
				
			$('popup_lightbox').setStyle({ top: x + 'px', left: y + 'px' }).show();
			new Effect.Appear('popup_lightbox', { 
				duration: 2, 
				queue: 'end'
			});
			//if(this.load_ajax==true)
			
			new Ajax.Updater('popup_lightboxImage',url,{evalScripts:true});

			this.load_ajax=false;
	        document.observe('keydown', this.keyboardAction); 
	        //alert($(id).offsetWidth);
	},
	
	next_reload:function(){
		this.load_ajax=true;
	},
	
	hide_popup:function(){
/*		var popUp = document.getElementById("popupcontent");
		 $('popup_lightbox').hide();
		popUp.style.visibility = "hidden";
*/		this.end_overlay();
        document.stopObserving('keydown', this.keyboardAction); 
	}


}

var div_manager;
document.observe('dom:loaded', function () { div_manager=new Lightdiv(); });

//show toolbox
function show_toolbox(id){
	$('toolbox_'+id).style.display = "block";
	$('tailShadow_'+id).style.display = "block";
	$('tail_'+id).style.display = "block";		
}

function hide_toolbox(id){
	$('toolbox_'+id).style.display = "none";
	$('tailShadow_'+id).style.display = "none";
	$('tail_'+id).style.display = "none";		
}
