var current_tab = 1;
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

function change_icon(tag)
{
	img = $('pageicon');
	if (img)
	{
		if (!IE6) img.hide();
		img.src = _base + 'img/im_'+tag+'.gif';
		img.appear({ duration: 1.0 });
	}
}

function activate(nr)
{		
	if (current_tab==nr) return;
	else current_tab = nr;

	if (nr==1) w = 400;
	else if (nr==2) w = 350;
	else w = 340; 
		
	$('hp_text').morph('width: '+w+'px', { duration: 0.5 });	

	cr = $('hpt_'+nr);
	$('hpt_1').hide();
	$('hpt_2').hide();
	$('hpt_3').hide();
	cr.appear({ duration: 0.5 });
}

function rezerva(ev_id)
{
	var updateDiv = 'ev_rez_' + ev_id;
	var oOptions = 
	{  
		method: "POST",  
		asynchronous: true,  
		parameters: "intervalPeriod=1",  
		onComplete: function (oXHR, Json) { $(updateDiv).innerHTML = oXHR.responseText; $(updateDiv).appear({ duration: 0.5 }); }  
	};
	url = _base + 'rezform/' + ev_id;
	var oRequest = new Ajax.Updater(updateDiv, url, oOptions); 
	return false;
}

function trimite_rezervare(ev_id)
{
	nm = $('nume_ev_' + ev_id);
	tel = $('telefon_ev_' + ev_id);
	nr = $('numar_persoane_ev_' + ev_id);
	mes = $('mesaj_ev_' + ev_id);

	if (!nm || !tel || !nr || !mes)
	{
		alert('Unul sau mai multe campuri din formular nu exista.');
		return false;
	}

	err = '';
	if (!nm.value) err += '- nu a fost completat un nume\n';
	if (!tel.value) err += '- nu a fost completat telefonul\n';
	if (!nr.value) err += '- nu a fost completat numarul de persoane\n';
	if (err != '')
	{
		err = 'Au aparut urmatoarele erori: ' + "\n" + err;
		alert(err);
		return false;
	}
	
	var updateDiv = 'ev_rezform_container_' + ev_id;
	var oOptions = 
	{  
		method: "POST",  
		asynchronous: true,  
		parameters: "nm="+nm.value+"&tel="+tel.value+"&nr="+nr.value+"&mes="+mes.value,  
		onComplete: function (oXHR, Json) { $(updateDiv).innerHTML = oXHR.responseText; $(updateDiv).appear({ duration: 0.5 }); }  
	};
	url = _base + 'rezervare/' + ev_id;
	var oRequest = new Ajax.Updater(updateDiv, url, oOptions); 
	return false;
}


/* Preloader */
function ImagePreloader(images, callback)
{

   // store the callback
   this.callback = callback;

   // initialize internal state.
   this.nLoaded = 0;
   this.nProcessed = 0;
   this.aImages = new Array;
 
   // record the number of images.
   this.nImages = images.length;

   // for each image, call preload()
   for ( var i = 0; i < images.length; i++ )
      this.preload(images[i]);
}

ImagePreloader.prototype.preload = function(image)
{
   // create new Image object and add to array
   var oImage = new Image;
   this.aImages.push(oImage);

   // set up event handlers for the Image object
   oImage.onload = ImagePreloader.prototype.onload;
   oImage.onerror = ImagePreloader.prototype.onerror;
   oImage.onabort = ImagePreloader.prototype.onabort;

   // assign pointer back to this.
   oImage.oImagePreloader = this;
   oImage.bLoaded = false;

   // assign the .src property of the Image object
   oImage.src = image;
}

ImagePreloader.prototype.onComplete = function()
{
   this.nProcessed++;
   if ( this.nProcessed == this.nImages )
   {
      this.callback(this.aImages, this.nLoaded);
   }
}

ImagePreloader.prototype.onload = function()
{
   this.bLoaded = true;
   this.oImagePreloader.nLoaded++;
   this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onerror = function()
{
   this.bError = true;
   this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onabort = function()
{
   this.bAbort = true;
   this.oImagePreloader.onComplete();
}

function preload_images(aImages, nImages)
{		
	var ip = null;

	if ( nImages != aImages.length )
	{		
		return;
	}
}

img = new Array();
img[0] = _base + "img/im_default.png";
img[1] = _base + "img/im_filosofie.png";
img[2] = _base + "img/im_meniu.png";
img[3] = _base + "img/im_galerie.png";
img[4] = _base + "img/im_evenimente.png";
img[5] = _base + "img/im_contact.png";

Event.observe(window, 'load', function() { ip = new ImagePreloader(img, preload_images); });
