function parseNews() {
	var box = $('IDNews');
	var items = $$('#NewsItems li');
	var seq = 0;
	var z = items.length - 1;
	var speed = 3000;
	var period;
	var clicked = false;

	var rotate = function(){
		items[seq].removeClass('on');
		counter[seq].removeClass('on');
		(seq != z) ? seq++ : seq = 0;
		items[seq].addClass('on');
		counter[seq].addClass('on');
	}

	function timer() { period = rotate.periodical(speed);}

	var NewsNav = new Element ('ul', {'id': 'NewsNav'}).injectInside(box);

	items.each(function(el){ 
		el.addEvent('mouseenter', function(e){ $clear(period); })
		el.addEvent('mouseleave', function(e){ timer(); })
		var aLi = new Element ('li');
		var aAnchor = new Element('a', {'href': '#','html': ''});
		var aLia = aLi.grab(aAnchor);
		aLia.inject(NewsNav);
	});

	var counter = $$('#NewsNav li');
	counter[0].addClass('on');
	counter.each(function(el, i){ 
		el.addEvent('click', function(e){
			e = new Event(e).stop();
			$clear(period);
			counter[seq].removeClass('on');
			items[seq].removeClass('on');
			seq = i;
			items[i].addClass('on');
			counter[i].addClass('on');
			clicked = true;
		});
		el.addEvent('mouseenter', function(e){ $clear(period); })
		el.addEvent('mouseleave', function(e){	
			if (!clicked){ timer();} 
		});
	})
	timer();
} //parseNews

function searchSwitch() {
	var srchForm = $('search').getElement('form');
	var searchList = $('searchList');
	var searchIndex = searchList.selectedIndex;
	var hiddenExists = $('newfield');

	function addHidden(contentType) {
		var newfield = document.createElement("input");
		newfield.setAttribute("type","hidden");
		newfield.setAttribute("name","cmd");
		newfield.setAttribute("value", contentType);
		newfield.setAttribute("id","newfield");
		srchForm.appendChild(newfield);
	}

	function rmHidden() {
		if (hiddenExists) {
			srchForm.removeChild(hiddenExists);
		}
	}

	function changeQuery(queryLetter){
		srchForm.elements[0].name = queryLetter;
	}

	switch (searchIndex) {
		case 0: //toate sectiunile
		srchForm.action = "search.php";
		changeQuery('q');
		break;
		
		case 1: //balti
		srchForm.action = "balti-de-pescuit.php";
		changeQuery('q');
		rmHidden();
		if (!hiddenExists) {
			addHidden('search');
		}
		break;

		case 2: //Articole
		srchForm.action = "articole_de_pescuit.php";
		changeQuery('t');
		if (hiddenExists) {
			hiddenExists.value = 'search';
		} else {
			addHidden('search');
		}
		break;
	
		case 3: //Retete nada
		srchForm.action = "retete-nada-pescuit.php";
		changeQuery('t');
		if (hiddenExists) {
			hiddenExists.value = 'search';
		} else {
			addHidden('search');
		}
		break;

		case 4: //ingrediente Retete nada
		srchForm.action = "retete-nada-pescuit.php";
		changeQuery('ti');
		if (hiddenExists) {
			hiddenExists.value = 'search';
		} else {
			addHidden('search');
		}
		break;
		}

} //searchSwitch

Selector = new Class(
{
   Implements : Options, options :
   {
      setCookie : true, cookieName : null, action : 'click'
   }
   , initialize : function(tabs,activetab, contents, dinamic, options)
   {
	  this.activeTab = activetab; 
      this.setOptions(options);
      this.setElements(tabs, contents, dinamic);
      this.initSeq();
      //this.setCookieName();
      //this.checkCookie();
      this.tabs.each(function(el, i)
      {
         this.close(i);
         el.addEvent(this.options.action, function(e)
         {
            if( ! el.hasClass('external'))
            {
               e = new Event(e).stop();
               this.setSeq(i);
               this.close(this.seq.past);
               this.open(i);
               //this.setCookie()
            }
         }
         .bind(this))
      }
      .bind(this));
	  this.seq.current = this.activeTab;
      this.open(this.seq.current)
   }
   , setElements : function(tabs, contents, dinamic)
   {
      this.tabs = ($type(tabs) == 'array') ? tabs : [tabs];
	  this.dinamic = dinamic;
	  if (contents != null)
      	this.contents = ($type(contents) == 'array') ? contents : [contents]
		else
		this.contents = null
   }
   , initSeq : function()
   {
      this.seq =
      {
         current : 0, past : null
      }
   }
   , setSeq : function(i)
   {
      this.seq.past = this.seq.current;
      this.seq.current = i
   }
   , open : function(i)
   {
      this.tabs[i].addClass('on');
	  if(this.contents)
	  {
      	this.contents[i].setStyle('display', 'block')
	  }
	   	if(this.dinamic)
			if (this.seq.current > -1)
			{
			//var url_php = "http://localhost/pescuitmania/UserMessagesLoader.php";
			var url_php = "testAjax.php";
			var updateMe = $(this.dinamic);
			
			curenttab = this.seq.current;
			
			var req = new Request.HTML({
				method: 'get',
				url: url_php,
				data: ('lst='+this.seq.current+'&mode='+updateMe.getProperty('mode')),
				update: this.dinamic
			}).send();
			
			friend = '';
			//LoadCheckAll();
			}

   }
   , close : function(i)
   {
      this.tabs[i].removeClass('on');
 	  if (this.contents)
	      this.contents[i].setStyle('display', 'none')
   }
}
);

PositionPopUpBox = new Class(
{
   Implements : Options, options :
   {
      positionTo : null, inWindow : false, offEdge : 5, relative : null, offset :
      {
         x : 0, y : 0
      }
   }
   , initialize : function(elem, options)
   {
      this.setOptions(options);
      this.elem = $(elem);
      this.link = ($chk(this.options.positionTo)) ? $(this.options.positionTo) : null;
      this.elementSize = this.elem.getSize();
      if($chk(this.link))
      {
         this.linkCoords = this.link.getCoordinates(this.options.relative);
         this.yActual = this.linkCoords.bottom + this.elementSize.y;
         this.xActual = this.linkCoords.left + this.elementSize.x;
         if(this.options.inWindow)
         {
            this.windowStats();
            this.yMax = this.windowSize.y + this.windowScroll.y;
            this.xMax = this.windowSize.x + this.windowScroll.x;
            this.top = (this.yActual > this.yMax) ? this.linkCoords.bottom - ((this.yActual - this.yMax) + this.options.offEdge) : this.linkCoords.bottom;
            this.left = (this.xActual > this.xMax) ? this.linkCoords.left - ((this.xActual - this.xMax) + this.options.offEdge) : this.linkCoords.left
         }
         else
         {
            this.top = this.linkCoords.bottom + this.options.offset.y;
            this.left = this.linkCoords.left + this.options.offset.x
         }
      }
      else
      {
         this.windowStats();
         this.top = (this.windowSize.y / 2) - (this.elementSize.y / 2) + this.windowScroll.y + this.options.offset.y;
         if(this.top < 0)
         {
            this.top = this.options.offEdge
         }
         this.left = (this.windowSize.x / 2) - (this.elementSize.x / 2) + this.windowScroll.x + this.options.offset.x
      }
      this.setPosition()
   }
   , windowStats : function()
   {
      this.windowSize = $(window).getSize();
      this.windowScroll = $(window).getScroll()
   }
   , setPosition : function()
   {
      this.elem.set('styles',
      {
         'position' : 'absolute', 'top' : this.top, 'left' : 150/*this.left*/
      }
      )
   }
}
);

PopupBox = new Class(
{
   Extends : Selector, Implements : Options, options :
   {
      setCookie : false, cookieName : null, relative : null, shadow : false, offset :
      {
         x : 0, y : 0
      }
   }
   , initialize : function(tabs, contents, options)
   {
      this.setOptions(options);
      this.setElements(tabs, contents);
      this.initSeq();
      this.tabs.each(function(el, i)
      {
         this.close(i);
         var pos = new PositionPopUpBox(this.contents[i],
         {
            relative : this.options.relative, positionTo : el, offset :
            {
               x : 0/*this.options.offset.x*/, y : this.options.offset.y
            }
         }
         );
         this.attachEvents(el, i);
         this.attachEvents(this.contents[i], i);
         if(this.options.shadow)
         {
            //var shadow = new CNB.Shadow(this.contents[i])
         }
      }
      .bind(this))
   }
   , attachEvents : function(el, i)
   {
      el.addEvent('mouseover', function(e)
      {
         e = new Event(e).stop();
         this.setSeq(i);
         if(i != this.seq.past)
         {
            this.close(this.seq.past)
         }
         $clear(this.closeDelay);
         this.openDelay = this.open.pass(i, this).delay(100)
      }
      .bind(this));
      el.addEvent('mouseout', function(e)
      {
         e = new Event(e).stop();
         $clear(this.openDelay);
         this.closeDelay = this.close.pass(i, this).delay(150)
      }
      .bind(this))
   }
}
);

//on dom ready...
window.addEvent('domready', function() {

	if ($('IDNews')) 
		parseNews();
});