var currentURL = window.location.href;
currentURL = currentURL.replace(URL, '')
if(currentURL.indexOf("#") == -1 && currentURL != language + '/' && currentURL != language ) {
	var newURL = language + '/#/' + currentURL.substr(3);
	window.location.replace(newURL);
} 

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function addDOMLoadEvent(f){if(!window.__ADLE){var n=function(){if(arguments.callee.d)return;arguments.callee.d=true;if(window.__ADLET){clearInterval(window.__ADLET);window.__ADLET=null}for(var i=0;i<window.__ADLE.length;i++){window.__ADLE[i]()}window.__ADLE=null};if(document.addEventListener)document.addEventListener("DOMContentLoaded",n,false);/*@cc_on @*//*@if (@_win32)document.write("<scr"+"ipt id=__ie_onload defer src=//0><\/scr"+"ipt>");var s=document.getElementById("__ie_onload");s.onreadystatechange=function(){if(this.readyState=="complete")n()};/*@end @*/if(/WebKit/i.test(navigator.userAgent)){window.__ADLET=setInterval(function(){if(/loaded|complete/.test(document.readyState)){n()}},10)}window.onload=n;window.__ADLE=[]}window.__ADLE.push(f)}


function showImages() {
	if(status != 'inceput') {
	if(window.opera) {toggle_fotos('visible');}
	else {
	if($('fotos')) {
		$('fotos').getElements('img').each( function(item) { item.addEvent('load', function() { this.setStyle('visibility', 'visible'); });  });
	}
	}
	
	}
}

function toggle_fotos (property) {
	if($('fotos')) {
		 $('fotos').getElements('img').each( function(item) { item.setStyle('visibility',property);});
	}
}

var desero;
var desero_drag;
var wrapper;
var wrapper_width;
var wrapper_height;
var h1_width;
var h1;
var h1_top;
var h1_left;
var main_menu;
var status;
var mouse_movement = true;
var foto_scrolled;
var h1_state;
var desero_state;
var main_menu_lks;
var req;
var initialize_history;
var menu_lks;
var ajaxfy_links;
var div_scroll1 = new Array();
var clearcache = new Date-1;
var visited;
var otherLinks;
var legend;


function externalLinks() {
	$$('a[rel=external]').setProperty('target', '_blank');
	}
	

function hoverOn () {
	this.addClass('hover'); }
function hoverOff () {
	this.removeClass('hover'); 	}

function contact() {
	if($('submitContact')) {
		$('submitContact').addEvent('click', function(e) {
			var clickEvent = new Event(e);
			clickEvent.stop();
			$('contact_form').setProperty('action', 'xmlhttp/' + language + '/contact');
			$('contact_form').send({ 
				update: $('content'), 
				onSuccess: function () {
					otherLinks();
					externalLinks();
					focus_inputs();
					contact();
				}
			});
		});
	}
}

function careers() {
	
	
	
	if($('submitDefault')) {
		$('submitDefault').addEvent('click', function(e) {
			var clickEvent = new Event(e);
			clickEvent.stop();
			
			$('default_form').setProperty('action', 'xmlhttp/' + language + '/about/career');
			$('default_form').send({ 
				update: $('content'),
				onSuccess: function () {
					otherLinks();
					externalLinks();
					focus_inputs();
					careers();
		  			facts_scroll();
					activate_cariere();
					//alert(legend.getAttribute('id'));
					document.getElementById(legend.getAttribute('id')).style.display = 'block';
				}
			});
		});
	}
	
}

function echipa () {
	
	var membri_echipa = $('membri_echipa');
	if(!membri_echipa) {return false;}
	var membri_echipa_char = $$('#membri_echipa span.character span');
	var membri_echipa_name = $$('#membri_echipa strong');
	
	
	var membri_echipa_span  = $$('#membri_echipa span.character');
	
	
	
	
	for(i=0; i<membri_echipa_span.length; i++)
	{
		membri_echipa_span[i].onmouseover = function () {
			
			this.getElementsByTagName('span')[0].className = 'on';
			this.parentNode.getElementsByTagName('strong')[0].style.display = 'block';
		}
		
		membri_echipa_span[i].onmouseout = function () {
			
			for(x=0; x<membri_echipa_char.length; x++)
			{
				membri_echipa_char[x].className = '';
				membri_echipa_name[x].style.display = 'none';
			}
		}

		
		
	}
}
	

function menu() {

/**
 *  language switch
 */	
 	languageLinks = $('lang').getElements('a');
	
	languageLinks.addEvent('click', function(e) {
		var clickEvent = new Event(e);
		clickEvent.stop();
		
		var currentURL = window.location.href;
		
		var newURL = currentURL.replace(URL, '');

		if(this.getProperty('rel') == 'en')
			newURL = newURL.replace('ro/','en/');
		else
			newURL = newURL.replace('en/','ro/');

		window.location.href = URL + newURL;
	}); 


/**
 *  main menu
 */

	wrapper = $('wrapper');
	var bg = $('bg');
	var container = $('container');
	h1 = $('logo');
	var desero = $('desero');
	var main_menu = $('main_menu');

	var bgs = new Array();
	if(language == 'ro') {
		bgs['despre_toggler'] = 'images/bg1.jpg'; 
		bgs['servicii_toggler'] = 'images/bg2.jpg';
		bgs['portofoliu_toggler'] = 'images/bg3.jpg';
		bgs['clienti_toggler'] = 'images/bg4.jpg';
		bgs['contact_toggler'] = 'images/bg5.jpg';
	}
	else {
		bgs['despre_toggler'] = 'images/bg1_en.jpg'; 
		bgs['servicii_toggler'] = 'images/bg2_en.jpg';
		bgs['portofoliu_toggler'] = 'images/bg3_en.jpg';
		bgs['clienti_toggler'] = 'images/bg4_en.jpg';
		bgs['contact_toggler'] = 'images/bg5_en.jpg';
	}

	document.body.className = '';

	status = 'inceput';

	var wrapper_values = wrapper.getCoordinates();
	wrapper_width = wrapper_values.width;
	wrapper_height = wrapper_values.height;
	var h1_values = h1.getCoordinates();
	h1_width = h1_values.width;

	h1.style.margin = 0;
	h1.style.top = wrapper_height/2 -h1_width/2 + 'px';
	h1.style.left = wrapper_width/2 -h1_width/2 + 'px';
	var mouse_fx = new Fx.Styles(h1, {duration: 500,transition: Fx.Transitions.Quad.easeOut});
	h1.onmouseover = function () {h1_state = 'on'}
	h1.onmouseout = function () {h1_state = 'off'}


	/* start logo follow mouse	 */
	$('container').addEvent('click', function(event){
		event = new Event(event);
	
		h1_top = h1.getTop();
		h1_left = h1.getLeft();
		
		y_event = event.page.y - h1_width/2;
		x_event = event.page.x - h1_width/2; 
		
		if(y_event < 0) y_event=0;
		if(x_event < 0) x_event=0;
		
	 	if(y_event>wrapper_height-h1_width) y_event=wrapper_height-h1_width;
		if(x_event>wrapper_width-h1_width) x_event=wrapper_width-h1_width;
		
		if(mouse_movement && h1_state != 'on')
			mouse_fx.start({ 'top': [h1_top, y_event], 'left': [h1_left, x_event] });
	});


	/* start reset logo */
	desero_drag = new Drag.Move(h1, {'container': container, 'handle': h1 });

	var main_menu_fx = new Fx.Style('main_menu_wrapper','width',{duration:500,transition: Fx.Transitions.Quad.easeOut,onStart: function () {if(status=='inceput') {lang_fx.start(23,0);}}, onComplete: function () { if(status=='sfarsit') { main_menu.style.visibility = 'visible'; $('content').style.visibility =  'visible'; toggle_fotos('visible'); var wrapper_facts= $('wrapper_facts'); if(wrapper_facts) {wrapper_facts.className = '';}  } else {main_menu.style.visibility = 'hidden'; desero_fx.start({ 'top': [40,wrapper_height/2 -60], 'left': [0,wrapper_width/2 -h1_width/2]}); desero_drag.attach(); mouse_movement = true;}}});
	var lang_fx = new Fx.Style('lang','width',{duration:500,transition: Fx.Transitions.Quad.easeOut});
	var desero_fx = new Fx.Styles(h1, {duration: 500,transition: Fx.Transitions.Quad.easeOut, onComplete: function() { if(status=='sfarsit') {main_menu_fx.start(0,600); lang_fx.start(0,23);} }});


	desero.addEvent('click', function(e) {
		if (e) new Event(e).stop();

		if(status == 'inceput') {
			if(bg.getAttribute('src').indexOf('holiday-ro')!=-1&&language=='ro') {
				bg.setAttribute('src','images/bg1.jpg');
				bg.className = 'despre_toggler_bg';
			}
			if(bg.getAttribute('src').indexOf('holiday-en')!=-1&&language=='en') {
				bg.setAttribute('src','images/bg1_en.jpg');
				bg.className = 'despre_toggler_bg';
			}
			status = 'sfarsit';	
			mouse_movement = false;
			desero_drag.detach();
			h1_top = h1.getTop();
			h1_left =h1.getLeft();
			desero_fx.start({'top': [h1_top, 40],'left': [h1_left, 0] });
		}
		else {
			status = 'inceput';	
			toggle_fotos('hidden');
			$('content').style.visibility =  'hidden';
			var wrapper_facts = $('wrapper_facts');
			if(wrapper_facts)
				wrapper_facts.addClass('hide_facts');
				
			main_menu_fx.start(600,0);
		}
	});


	var main_menu_tabs = $ES('span',main_menu);
	main_menu_lks = $ES('a',main_menu);
	var main_menu_togglers = main_menu_tabs.concat(main_menu_lks);
	var main_menu_uls = $ES('ul',main_menu);
	var main_menu_lis = $ES('li',main_menu);
	var main_menu_divs = $$('.links_wrapper');


	main_menu_togglers.each( function(item) {
		item.addEvent('mouseover', hoverOn);
		item.addEvent('mouseout', hoverOff);
	});

	
	/* add the ids to all the menu items */
	var idLinks = $('id').getElements('a');
	var printLinks = $('print').getElements('a');
	var webLinks = $('web').getElements('a');
	var clientsLinks = $('clienti_links').getElements('a');
	var aboutLinks = $('about').getElements('a');
	
	idLinks.each( function(item) { item.setProperty('id', item.getProperty('href').substr(3) ); });
	printLinks.each( function(item) { item.setProperty('id', item.getProperty('href').substr(3) ); });
	webLinks.each( function(item) { item.setProperty('id', item.getProperty('href').substr(3) ); });
	clientsLinks.each( function(item) { item.setProperty('id', item.getProperty('href').substr(3) ); });
	aboutLinks.each( function(item) { item.setProperty('id', item.getProperty('href').substr(3) ); });

	/* start history */
 	menu_lks = $ES('a',main_menu);
	 
	ajaxfy_links = function () {
		menu_lks.each( function(item) { item.addEvent('click', handleMouseClick) });
	}
	    
	/* get the possible links */
	var hrefs = main_menu_lks.getProperty('href');
	
	/* no index now */
	var currentIndex = -1;

	var req = new Ajax('', {
		update: $('content'),
		onRequest: function () {$('content').innerHTML = ''},
		onSuccess: function () {
			galerie_proiect();
			echipa();
			other_projects();
			otherLinks();
			externalLinks();
			focus_inputs();
			facts_scroll();
			fix_opera_8();
			showImages();
			contact();
			careers();
			visited();
			activate_cariere();
		} 
	});

	initialize_history = function () {

		ajaxfy_links();

		/* initialize the DHTML History framework */
		dhtmlHistory.initialize();
   
		/* add ourselves as a DHTML History listener */
		dhtmlHistory.addListener(handleHistoryChange);
  
		var currentLocation = dhtmlHistory.getCurrentLocation();
//		currentLocation = currentLocation.substr(currentLocation.lastIndexOf('\/'));

		if (currentLocation == "") currentLocation = "/home";
	
		currentLocation = currentLocation.replace(/\//, "");
		displayLocation(currentLocation, null);
	}

	/** Handles history change events. */
	function handleHistoryChange(newLocation) {

		if (newLocation == "") newLocation = "/home";
	   
		newLocation = newLocation.replace(/\//, "");
		displayLocation(newLocation);
		
		if(newLocation=='home') {
			
			h1.style.top = wrapper_height/2 -h1_width/2 + 'px';
			h1.style.left = wrapper_width/2 -h1_width/2 + 'px';
			$('main_menu_wrapper').style.width = 0;
			$('lang').style.width = 0;
			$('content').innerHTML = '';
			status = 'inceput';
			mouse_movement = true;
			desero_drag.attach();
			var visibles = $$('.visible');
			for(i=0; i<visibles.length; i++) {
				  visibles[i].removeClass('visible'); 
				}
			var openeds = $$('.opened');
			for(i=0; i<openeds.length; i++) {
				  openeds[i].removeClass('opened'); 
			}
		}
	}


	function displayLocation(newLocation) {
		
		/**
		 *  get the location X from the newLocation string
		 *  if it is something like portfolio/web/X
		 */
/*		if( newLocation.indexOf('\/') != -1 )
			newLocation = newLocation.substr(newLocation.lastIndexOf('\/') + 1);
*/
		var selectedElement = $(newLocation);

		if(!selectedElement)
			return false;
		
		for (var i=0; i < menu_lks.length; i++) {
       var currentElement = menu_lks[i];
       currentElement.removeClass('ajax_selected');
      } 
		
		status = 'sfarsit';	
		mouse_movement = false;
		desero_drag.detach();
		h1.style.top = 40 + 'px';
		h1.style.left = 0;
		$('main_menu_wrapper').style.width = 600 + 'px';
		$('lang').style.width = 23 + 'px';
	
		selectedElement.addClass('ajax_selected');
		
		req.url = URL + 'xmlhttp/' + selectedElement.getProperty('href')+'?clearcache=' + clearcache;
		req.request();
		
		visited = function () {
		var selectedElement_id = selectedElement.getAttribute('id');
		if(selectedElement_id!='services'&&selectedElement_id!='contact') {
		//selectedElement.style.opacity = 0.6;
		//selectedElement.style.filter = 'alpha(opacity=60)';
		selectedElement.style.color = '#CFCDCB';
		}
		}
	           
		/*
		
		if( main_menu.getElementById(newLocation) ) {
			
			main_menu_uls.each( function(item) { item.removeClass('visible'); });
			main_menu_divs.each( function(item) { item.removeClass('visible'); });
			
			selectedElement.getParent().addClass('opened');
			
			
			 
			
			var test_scrollable = selectedElement.getParent().getParent().getParent().getParent();

			if(test_scrollable.hasClass('links_wrapper')) {   				 
				test_scrollable = test_scrollable.getFirst();
				test_scrollable_index = test_scrollable.getProperty('id').replace(/scrollable/, "").toInt();

				var scroll = new Fx.Scroll(test_scrollable, {
					wait: false,
					duration: 0,
					offset: {'x': 0, 'y': 0}
				});
					
				var parent = test_scrollable.getPosition(scroll.options.overflown);
				var target = selectedElement.getPosition(scroll.options.overflown);
							
				if(Math.abs(div_scroll1[test_scrollable_index].scrollCursor-(target.y - parent.y))>=90)	{
					scroll.toElement(selectedElement);
					div_scroll1[test_scrollable_index].scrollCursor = target.y - parent.y;
				}
							
				if(div_scroll1[test_scrollable_index].scrollCursor>target.y - parent.y)	{
					scroll.toElement(selectedElement);
					div_scroll1[test_scrollable_index].scrollCursor = target.y - parent.y;
				}
			}

			 var origin = selectedElement.getParent();
			// var origin = selectedElement.parentNode;
			var this_lis_parent = new Array();
			
			while(origin.getProperty('id') != 'main_menu' ) {
				//origin = origin.parentNode;
				origin = origin.getParent();
				if(origin.tagName.toLowerCase() == 'li') {
					origin.className='opened';
					this_lis_parent.push(origin.getElementsByTagName('span')[0]);
				}
				if(origin.tagName.toLowerCase() == 'ul')
					origin.className='visible';
				if(origin.tagName.toLowerCase() == 'div' && origin.hasClass('links_wrapper'))
					origin.addClass('visible');
			}
					
			this_lis_parent = this_lis_parent.reverse();
			
			for(i=0; i<this_lis_parent.length; i++) {
				this_lis_parent[i].fireEvent('click'); 
			}
			
			
			
			
			for(x=0; x<main_menu_lis.length; x++) { 
				if( $ES('.ajax_selected', main_menu_lis[x]).length < 1) { 
					main_menu_lis[x].className = '';  
				}
			}
			
			var opened_li = $$('#main_menu .opened');
			var opened_li_child = opened_li[0].getFirst();
			
			var this_toggler = opened_li_child.className;
			
			if(this_toggler.test(' hover')) {
				this_toggler = this_toggler.split(' hover');
				this_toggler = this_toggler[0];
			}
			
			if(this_toggler.test(' ajax_selected')) {
				this_toggler = this_toggler.split(' ajax_selected');
				this_toggler = this_toggler[0];
			}
			if(bgs[this_toggler])
				bg.setProperty('src',bgs[this_toggler]);
				
			$('content').style.visibility = 'visible';
			
		}
		*/
		
		
		var test_main_menu = main_menu.getElementById(newLocation);
	if(test_main_menu) {
					
		         
	           
				    for(z=0; z<main_menu_uls.length; z++)
						{  
						  main_menu_uls[z].removeClass('visible'); 
						 }
	              for(y=0; y<main_menu_divs.length; y++)
					  {  
						  main_menu_divs[y].removeClass('visible');
					  }
					
					
					
					 selectedElement.parentNode.className = 'opened';
					 var test_scrollable = selectedElement.parentNode.parentNode.parentNode.parentNode;
					 if(test_scrollable.className=='links_wrapper')
					 {   
						 
						test_scrollable = test_scrollable.getFirst();
						test_scrollable_index =  test_scrollable.getAttribute('id');
						test_scrollable_index = test_scrollable_index.replace(/scrollable/, "");
						test_scrollable_index = test_scrollable_index.toInt();
						
						
						
						var scroll = new Fx.Scroll(test_scrollable, {
							wait: false,
							duration: 0,
							offset: {'x': 0, 'y': 0}
						});
						 
						
							
							var parent = test_scrollable.getPosition(scroll.options.overflown);
							var target = selectedElement.getPosition(scroll.options.overflown);
							
							if(Math.abs(div_scroll1[test_scrollable_index].scrollCursor-(target.y - parent.y))>=90)
							{
								scroll.toElement(selectedElement);
								div_scroll1[test_scrollable_index].scrollCursor = target.y - parent.y;
							}
							
							if(div_scroll1[test_scrollable_index].scrollCursor>target.y - parent.y)
							{
								scroll.toElement(selectedElement);
								div_scroll1[test_scrollable_index].scrollCursor = target.y - parent.y;
							}
							
							
							if(div_scroll1[test_scrollable_index].scrollCursor==0) {div_scroll1[test_scrollable_index].up_name.style.visibility = 'hidden'}
							else {div_scroll1[test_scrollable_index].up_name.style.visibility = 'visible'}
							
							var test_scrollable_ul = test_scrollable.getFirst();
							test_scrollable_ul = test_scrollable_ul.getCoordinates();
							test_scrollable_ul = test_scrollable_ul.height;
							test_scrollable = test_scrollable.getCoordinates();
							test_scrollable_height = test_scrollable.height;
							var test_scrollable_top = test_scrollable.top;
							if(test_scrollable_ul)
							if(test_scrollable_ul-(target.y-test_scrollable_top)>test_scrollable_height)
							{
							  div_scroll1[test_scrollable_index].dn_name.style.visibility = 'visible'	
							}
							else {div_scroll1[test_scrollable_index].dn_name.style.visibility = 'hidden'}
							
							/*
							if((target.y - parent.y)>=90) {div_scroll1[test_scrollable_index].dn_name.style.visibility = 'visible'}
							else {div_scroll1[test_scrollable_index].dn_name.style.visibility = 'hidden'}
							*/
							
						
						 
					 }
					 
					 
					 
					 
					 var origin = selectedElement.parentNode;
					 var this_lis_parent = new Array();
					 while(origin.getAttribute('id')!='main_menu')
					 {
					    origin = origin.parentNode;
						if(origin.tagName.toLowerCase()=='li') {
							origin.className='opened';
							this_lis_parent.push(origin.getElementsByTagName('span')[0]);
							
							}
						 if(origin.tagName.toLowerCase()=='ul') {origin.className='visible'}
						 if(origin.tagName.toLowerCase()=='div'&&origin.hasClass('links_wrapper'))
						 {
							 origin.addClass('visible');
						 }
					 }
					
					 this_lis_parent = this_lis_parent.reverse();
					 for(i=0; i<this_lis_parent.length; i++)
					 {
						this_lis_parent[i].fireEvent('click'); 
					 }
					 
					 
					 
					 
					 for(x=0; x<main_menu_lis.length; x++)
					 { if($ES('.ajax_selected',main_menu_lis[x]).length<1)
						{ main_menu_lis[x].className = '';  }
					 }
					 
					 var opened_li = $$('#main_menu .opened');
					 var opened_li_child = opened_li[0].getFirst();
					
					 var this_toggler = opened_li_child.className;
					
					 if(this_toggler.test(' hover')) {
					 this_toggler = this_toggler.split(' hover');
					 this_toggler = this_toggler[0];
					 }
					 
					 if(this_toggler.test(' ajax_selected')) {
					 this_toggler = this_toggler.split(' ajax_selected');
					 this_toggler = this_toggler[0];
					 }
					
					 bg.setAttribute('src',bgs[this_toggler]);
					 bg.className = this_toggler + '_bg';
					 $('content').style.visibility = 'visible';
					
	
	             
	}
		
		
		
		
		
		
	}


	function handleMouseClick(e) {
		
		if(e) new Event(e).stop();
	
		// get the location the user clicked on
		var newLocation = this.getProperty('id');
	
		var modifiedLocation = "/" + newLocation;
	   
		dhtmlHistory.add(modifiedLocation);

		displayLocation(newLocation, null);
	
	}
		
	initialize_history();

/*
	main_menu_tabs.each( function(item) {
		item.addEvent('click', function() {
			$('content').removeClass('content_off');
			
			if(this.getParent().getParent().getProperty('id') == 'main_menu') {
			
				var this_toggler = this.className;
		
				this_toggler = this_toggler.split(' hover');
				this_toggler = this_toggler[0];
		
				if(bgs[this_toggler]) bg.setProperty('src',bgs[this_toggler]);
			}
	
			main_menu_uls.each( function(item) { item.removeClass('visible'); });
			main_menu_divs.each( function(item) { item.removeClass('visible'); });
			
			this.getParent().getParent().addClass('visible');
			
			if(!this.getParent().getElementById('opened')) {
				var opened = $('opened');
				if(opened) opened.removeAttribute('id');
				this.setProperty('id','opened');
			}
			 
			this.getParent().addClass('opened');
			
			
			 
			main_menu_lis.each( function(item) { if(!item.getElementById('opened')) item.className = '' });
			
			this.getNext().addClass('visible');
		});
	});
	
*/


for(i=0; i<main_menu_tabs.length; i++)
{
  main_menu_tabs[i].onclick = function () {
	 $('content').removeClass('content_off');
	 $('content').innerHTML = '';
	 if(this.parentNode.parentNode.getAttribute('id')=='main_menu') {
	 var this_toggler = this.className;
	 this_toggler = this_toggler.split(' hover');
	 this_toggler = this_toggler[0];
	 
	 bg.setAttribute('src',bgs[this_toggler]);
	 bg.className = this_toggler + '_bg';
	 }
	 
	 for(x=0; x<main_menu_uls.length; x++)
	   {  
		  main_menu_uls[x].removeClass('visible'); 
		 }
	  
	  for(y=0; y<main_menu_divs.length; y++)
	  {  
		  main_menu_divs[y].removeClass('visible');
	  }
	  
		
		
	  //this.parentNode.parentNode.addClass('visible');	
	 // this.parentNode.getElementsByTagName('ul')[0].addClass('visible');	
	 // this.parentNode.getElementsByTagName('div')[0].addClass('visible');	
	   this.parentNode.parentNode.addClass('visible');
		
		 if(!this.parentNode.getElementById('opened'))
		 {
		 var opened = $('opened');
		 if(opened) {opened.removeAttribute('id');}
		 this.setAttribute('id','opened');
		 }
		 this.parentNode.className = 'opened'; 
		 
		 
		 for(x=0; x<main_menu_lis.length; x++)
		 { if(!main_menu_lis[x].getElementById('opened'))
			{ main_menu_lis[x].className = '';  }
		 }
		
		
		
		
		this.getNext().addClass('visible');
	  
	 } 	
}
	
	
	
	
}

Fx.Properties = Fx.Styles.extend({	
	increase: function(){for (	var p in this.now) this.element[p] = this.now[p];	}	
});

Fx.FlyingScroller = Fx.Properties.extend({
	initialize: function(el, options){
		this.parent(el, options);
		this.options = Object.extend(this.options || {}, Object.extend({
			paddingLeft: 0,
			paddingTop: 0
		}, options || {}));
	},
	toElement: function(el, paddingLeft, paddingTop){
		this.goTo(el.offsetLeft - (paddingLeft || this.options.paddingLeft || 0), el.offsetTop - (paddingTop || this.options.paddingTop || 0));
	},
	goTo: function(x, y){
		this.start({
			'scrollLeft': [this.element.scrollLeft, x],
			'scrollTop': [this.element.scrollTop, y]
		})
	}});

/* project image gallery */
function galerie_proiect () {
	var proiect_gallery = $('proiect_gallery');
	
	
	if(proiect_gallery) {
	var proiect_shaddow = document.createElement('div');
	proiect_shaddow.setAttribute('id','proiect_shaddow');
	proiect_gallery.appendChild(proiect_shaddow);
	}
	
	
	if(!proiect_gallery || !$('proiect_nav') || !$ES('a',proiect_nav))
		return false;
	
	var proiect_nav = $('proiect_nav');
	var proiect_links = $ES('a',proiect_nav);
	
	proiect_links[0].addClass('thumb_on');
	
	var fotos  = $$('#fotos img');
	var proiect_fotos = $('proiect_fotos');
	var proiect_hovers = new Array();
	
	
	$$('#fotos img').each( function(item, i){
		item.setStyle('left', i*348);
		proiect_hovers[i] = new Element('div', {
			'styles': { 'width': Math.round(348/fotos.length),'left': Math.round(348/fotos.length) * i	},
			'events': {
				'mouseover': function(){
					var target_foto = this.getProperty('rel'); 
					main_nav.transition = 'Fx.Transitions.linear';
					main_nav.clearTimer().toElement($(target_foto)); 
					foto_scrolled = target_foto;
					var toggler_index = foto_scrolled.split('foto');
					toggler_index = toggler_index[toggler_index.length-1];
					toggler_index = parseInt(toggler_index);
					
					proiect_links.each( function(item) {item.className = ''});
					
					proiect_links[toggler_index-1].addClass('thumb_on');
				}
			},
			'class': 'proiect_hovers',
			'rel': 'foto' + (i + 1)
		}).injectInside(proiect_gallery);
	});
	

	var main_nav = new Fx.FlyingScroller($('proiect_fotos'), {
		transition: Fx.Transitions.quadInOut,
		duration: 1000,
		paddingLeft: 0,
		paddingTop: 0
	});
	main_nav.clearTimer().toElement($('foto1'));


	proiect_links.each( function(item, i) {
		item.setProperty('id','toggler' + (i+1) );
		item.addEvent('click', function(e) {

			e = new Event(e);
			e.stop();

			var target_foto = this.getProperty('id');
			target_foto = target_foto.split('toggler');
			target_foto =  target_foto[target_foto.length-1];
			target_foto = 'foto' + target_foto;
			main_nav.transition = 'Fx.Transitions.quadInOut';
			main_nav.clearTimer().toElement($(target_foto));
			
			foto_scrolled = target_foto;
			var toggler_index = foto_scrolled.split('foto');
			toggler_index = toggler_index[toggler_index.length-1];
			toggler_index = parseInt(toggler_index);
			
			proiect_links.each( function(item) {item.className = ''});
			
			proiect_links[toggler_index-1].className='thumb_on';
			
		});
	});}

/* other projects gallery */
function other_projects() {

	var projects_list = $('projects_list');
	if(!projects_list) 
		return false;
	
	var kwicks = $$('#projects_list li');
	var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});

	kwicks.each(function(kwick, i){
		kwick.addEvent('click', function(e){
			var obj = {};
			obj[i] = {
				'width': [kwick.getStyle('width').toInt(), 207]
			};
			kwick.setProperty('id','hovered');
			kwicks.each(function(other, j){
				if (other != kwick) {
					var w = other.getStyle('width').toInt();
					if (w != 61) obj[j] = {'width': [w, 61]};
					other.removeAttribute('id');
					
					var dt_unhovered = $$('#projects_list img');
					dt_unhovered.each( function(element) {
						if(element.getParent().getParent().getParent().getProperty('id')=='hovered')
						return false;
						var fx = new Fx.Styles(element, {duration:200, wait:false});
						fx.start({'left': -55});
					});
				}
			});	
			fx.start(obj);
			e.cancelBubble = true;
		});
	});
	
	
	var dt = $$('#projects_list img');
	dt.each(function(element) {
		var fx = new Fx.Styles(element, {duration:200, wait:false});
		element.addEvent('mouseenter', function() {
			fx.start({'left': 0	});
		});
	 
		element.addEvent('mouseleave', function() {
			if(this.getParent().getParent().getParent().getProperty('id')=='hovered')
				return false;									 
			fx.start({'left': -55});
		});
	});}

/* other links // later edit */

	
function otherLinks () {
	 
	 var olks = $$('#content a');
	 for(i=0; i<olks.length; i++) {
	 olks[i].onclick = function () {
		 var redirect = false;
		 for(x=0;x<main_menu_lks.length; x++) {
			if(this.getAttribute('href')==main_menu_lks[x].getAttribute('href')) {
				redirect=main_menu_lks[x];	
			} 
		 }
		 if(redirect!=false) {
			 redirect.fireEvent('click');
			 return false;
		 }
		else {
			if(this.getAttribute('rel')=='external') {
			new_window = window.open(this.getAttribute('href'));
			return false;
			}
		}
	 } 
 }
}	


/* start scroll */
var allow_wheel = true;
function TextScroll(scrollname, div_name) {

	this.div_name = div_name;
	this.name = scrollname;
	this.scrollCursor = 0;
	this.speed = 5;
	this.timeoutID = 0;
	this.div_obj = null;
	this.navs = null;
	this.up_name = null;
	this.dn_name = null;
	
	{
		if (document.getElementById) {
			div_obj = document.getElementById(this.div_name);
			if (div_obj) {
				this.div_obj = div_obj;
				this.up_name = div_obj.getParent().getElementsByTagName('img')[0];
				this.dn_name = div_obj.getParent().getElementsByTagName('img')[1]; 
                this.div_obj.style.overflow = 'hidden';
			}
           
			div_obj.getParent().addEvent('mouseover', function(e) {	
				if (!e) e = window.event;
				if (e.pageX || e.pageY) {
					posx = e.pageX;
					posy = e.pageY;
				}
				else if (e.clientX || e.clientY) {
					posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
					posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
				}
				
				y_event = posy; 
				x_event = (posx + 8) 
				this_y = $(div_name).getParent().getTop();
			
				if( y_event - this_y <= 15 && y_event - this_y >= 0 ) {
					allow_wheel = false;	
					eval(scrollname + ".stopScroll();");
					eval(scrollname + ".scrollUp();");
				}
				else if ( y_event - this_y >= 105) {
					allow_wheel = false;
					eval(scrollname + ".stopScroll();");
					eval(scrollname + ".scrollDown();");
				}
				else {
					allow_wheel = true;
					eval(scrollname + ".stopScroll();");
				}
			});
		   
			div_obj.getParent().addEvent('mouseout', function () { eval(scrollname + ".stopScroll();") });
			
			
			/** This is high-level function.
			 * It must react to delta being more/less than zero.
			 */
			function handle(delta) {
				if (delta < 0) { 
				   if(window.opera) {
						eval(scrollname + ".stopScroll();");
					   eval(scrollname + ".scrollUp();");	
					}
					else {
					eval(scrollname + ".stopScroll();");
					eval(scrollname + ".scrollDown();");
					}
					return false;
				}
				else {
					if(window.opera) {
						eval(scrollname + ".stopScroll();");
					eval(scrollname + ".scrollDown();");	
					}
					else {
					eval(scrollname + ".stopScroll();");
					eval(scrollname + ".scrollUp();");
					}
					return false;
				}
			}
			
			
			/** Event handler for mouse wheel event.
			 */
			function wheel(event) {
				var delta = 0;
				if (!event) /* For IE. */
					event = window.event;
				if (event.wheelDelta) { /* IE/Opera. */
					delta = event.wheelDelta/120;
					/** In Opera 9, delta differs in sign as compared to IE.
					*/
					if (window.opera)
						delta = -delta;
				} else if (event.detail) { 
					/** Mozilla case. 
					*   In Mozilla, sign of delta is different than in IE.
					*   Also, delta is multiple of 3.
					*/
					delta = -event.detail/3;
				}
					  /** If delta is nonzero, handle it.
						* Basically, delta is now positive if wheel was scrolled up,
						* and negative, if wheel was scrolled down.
						*/
				if(delta && allow_wheel == true)
					handle(delta);
					  /** Prevent default actions caused by mouse wheel.
						* That might be ugly, but we handle scrolls somehow
						* anyway, so don't bother here..
						*/
					if (event.preventDefault)
						event.preventDefault();
				event.returnValue = false;
			}
			
			/** Initialization code. 
			 * If you use your own event management code, change it as required.
			 */
			
			if (window.addEventListener)
				/** DOMMouseScroll is for mozilla. */
				div_obj.addEventListener('DOMMouseScroll', wheel, false);
			/** IE/Opera. */
			div_obj.onmousewheel = div_obj.onmousewheel = wheel;
        }
    }

	this.stopScroll = function() {
		clearTimeout(this.timeoutID);
		//this.up_name.style.visibility = 'hidden';
		//this.dn_name.style.visibility = 'hidden';
		//this.div_obj.removeClass('no_hovers');
	}

	this.scrollUp = function() {
		if (this.div_obj) {
			// this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
			if(this.scrollCursor - this.speed>0) {
				this.scrollCursor=this.scrollCursor - this.speed; 
				/*if(allow_wheel == false)*/ this.up_name.style.visibility = 'visible';
			}
			else {
				this.scrollCursor=0; 
				/*if(allow_wheel == false)*/ this.up_name.style.visibility = 'hidden';
			}
			
			this.div_obj.scrollTop = this.scrollCursor;
			if(allow_wheel == false) this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
			
			if (this.div_obj.scrollTop == this.scrollCursor) {
				/*if(allow_wheel==false)*/ {this.dn_name.style.visibility = 'visible'; }
			}
			else {this.dn_name.style.visibility = 'hidden';}
		}
		
		//this.div_obj.addClass('no_hovers');
	}

	this.scrollDown = function() {
		if (this.div_obj) {
			this.scrollCursor += this.speed;
			this.div_obj.scrollTop = this.scrollCursor;
			
			if (this.div_obj.scrollTop == this.scrollCursor) {
				if(allow_wheel==false) { this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);  }
				this.dn_name.style.visibility = 'visible';
			}
			else {
				this.scrollCursor = this.div_obj.scrollTop; 
				/*if(allow_wheel==false) */ this.dn_name.style.visibility = 'hidden';
			}
			
			if(this.scrollCursor - this.speed>0) {
				/*if(allow_wheel == false)*/ this.up_name.style.visibility = 'visible';
			}
			else {
				/*if(allow_wheel == false)*/ this.up_name.style.visibility = 'hidden';
			}
			
			
		}

		//this.div_obj.addClass('no_hovers');
	}	

	this.resetScroll = function() {
		if (this.div_obj) {
			this.div_obj.scrollTop = 0;
			this.scrollCursor = 0;
		}
	}}

function create_scroll() {
	var main_menu_divs = $$('.links_wrapper');
	 
	var scroll_up = new Array();
	var scroll_down = new Array();
	
	//var scrollable = new Array();
	
	main_menu_divs.each( function(item, i) {
		new Element('img', {
			'class': 'scroll_up',
			'src': 'images/scroll_up.gif'
		}).injectInside(item);

		new Element('img', {
			'class': 'scroll_down',
			'src': 'images/scroll_down.gif'
		}).injectInside(item);
		
		item.getFirst().setProperty('id','scrollable' + i);
		div_scroll1[i] = new TextScroll('div_scroll1[' + i + ']','scrollable' + i);
	});}

function focus_inputs() {
	var contact_form = $('contact_form');
	if(!contact_form)
		return false;
	var contact_inputs = $$('#contact_form input.text');
	var contact_textareas = $$('#contact_form textarea');
	var contact_focus = contact_inputs.concat(contact_textareas);
	for(i=0; i<contact_focus.length; i++)
  {
	contact_focus[i].onfocus = function () {
		this.parentNode.className = 'focused';
		if(this.parentNode.getElementsByTagName('strong')[0]) {
		this.parentNode.getElementsByTagName('strong')[0].style.display = 'none';
		}
	}
	
	
	contact_focus[i].parentNode.onclick = function () {
		this.className = 'focused';
		if(this.getElementsByTagName('strong')[0]) {
		this.getElementsByTagName('strong')[0].style.display = 'none';
		}
	}	
	
	
	
	
	contact_focus[i].onblur = function () {this.parentNode.className = '';}	
	}
	
}

function fix_opera_8 () {
	if( window.opera && parseInt(opera.version())< 9) {
		document.body.style.overflow = 'hidden';
		clearcache = new Date - 1;
		$('extra1').style.display = 'none';
		$$('.links_wrapper').each( function(item) {
			item.getFirst().setStyles({
			   overflow: 'visible',
			   width: 329
			});
			item.setStyles({
				top: 0,
				padding: 0,
				height: 90,
				overflow: 'auto'
			});
		});
	}}

function facts_scroll() {
	var facts = $('facts');
	if(facts) {
		scroll_facts = new ScrollObj(6,14,395,"track_facts","up_facts","down_facts","drag_facts","masca_facts","facts",30);
		if(status!='inceput') {
		facts.setStyle('visibility','visible');
		}
	}}
	
function activate_cariere() {
	var angajari = $('angajari');
	if(!angajari) {return false;}
	var angajari_lks = $$('#angajari a');
	var cariere_form = $$('.cariere_form');
	var legend_span =  $$('span.legend');
	for(i=0; i<angajari_lks.length; i++)
	{
		angajari_lks[i].onclick = function () {
			for(x=0; x<cariere_form.length; x++)
			{
				cariere_form[x].style.position = 'absolute';
				cariere_form[x].style.left = '-5000px';
				legend_span[0].style.display = 'none';
				legend_span[1].style.display = 'none';
			}
			var this_form = $('default_form');
			this_form.style.position = 'relative';
			this_form.style.left = '0';
			legend = $(this.getAttribute('rel'));
			legend.style.display = 'block';
			
			return false;
		}
	}
	
	
	var default_form = $('default_form');
   if(default_form) {
   var default_inputs = $$('#default_form   input.text');
   var default_textareas = $$('#default_form  textarea');
   var default_focus = default_inputs.concat(default_textareas);
   for(i=0; i<default_focus.length; i++)
   {
	default_focus[i].onfocus = function () {
		this.parentNode.className = 'focused';
		if(this.parentNode.getElementsByTagName('strong')[0]) {
			this.parentNode.getElementsByTagName('strong')[0].style.display = 'none';
		}
	}
	
	default_focus[i].parentNode.onclick = function () {
		this.className = 'focused';
		if(this.getElementsByTagName('strong')[0]) {
			this.getElementsByTagName('strong')[0].style.display = 'none';
		
			
		}
	}	 
	
	default_focus[i].onblur = function () {this.parentNode.className = '';}	
	}
	}
	var employee = $('employee_form');
   if(employee) {
   var employee_inputs = $$('#employee_form   input.text');
   var employee_textareas = $$('#employee_form  textarea');
   var employee_focus = employee_inputs.concat(employee_textareas);
   for(i=0; i<employee_focus.length; i++)
   {
	employee_focus[i].onfocus = function () {
		this.parentNode.className = 'focused';
		if(this.parentNode.getElementsByTagName('strong')[0]) {
			this.parentNode.getElementsByTagName('strong')[0].style.display = 'none';
		}
	}
	
	
	employee_focus[i].onblur = function () {this.parentNode.className = '';}	
	}
	}
}	
	

function text_resize() {
	new Element('span', {'id': 'text_sample'}).setText('&nbsp;').injectInside($E('body'));}

function init() {
	var iBase = TextResizeDetector.addEventListener(onFontResize,null);}

function onFontResize(e,args) {

	facts_scroll();
	var wrapper_values = $('wrapper').getCoordinates();
	wrapper_width = wrapper_values.width;
	wrapper_height = wrapper_values.height;
	var h1_values = $('logo').getCoordinates();
	h1_width = h1_values.width;
	if(status == 'inceput') {
			h1_top = h1.getTop();
			h1_left = h1.getLeft();

			$('logo').setStyle('margin',0);
			
			if(wrapper_height < ( h1_top + h1_width) ) {
				$('logo').setStyle('top', wrapper_height - h1_width);
			}

			if(wrapper_width < ( h1_left + h1_width) ) {
				$('logo').setStyle('left', wrapper_width - h1_width);
			}
	}}

TextResizeDetector.TARGET_ELEMENT_ID = 'text_sample';
TextResizeDetector.USER_INIT_FUNC = init;

function window_dimensions () {
	
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	
	
	
	
	
	if(x<1000) {x = 1000}
	if(y<600) {y=600}
	
	
	
	
	var bg = document.getElementById('bg');
	if(x>y)
	{
		
		if(y<x * 0.6) {
		   
			
		   bg.style.width = x + 'px';	
		   if(x * 0.6<wrapper_height) {
			bg.style.height = wrapper_height + 'px';
			}
			else {
			bg.style.height = x * 0.6 + 'px';
			}
			
			
			
		 }
		else {
			
			bg.style.height = y + 'px';
			if(y * 1.66<wrapper_width) {
			bg.style.width = wrapper_width + 'px';
			}
			else {
			bg.style.width = y * 1.66+ 'px';
			}
		}
		
		
		
	}
	
	else {
		
		
		if(x< y * 1.66) {
		  if(y * 1.66<wrapper_width) {
			bg.style.width = wrapper_width + 'px';
			}
			else {
		  bg.style.width = y * 1.66 + 'px'; 
			}
		  bg.style.height = y + 'px';
		}
		
		else {
			
			bg.style.width = x + 'px';
			 if(x * 0.6<wrapper_height) {
			bg.style.height = wrapper_height + 'px';
			}
			else {
			bg.style.height = x * 0.6 + 'px';
			}
		}
		
	}


}


function news () {
var adress = window.location.href;
if(adress.indexOf('#')!=-1) {return false;}

var news_request = new Ajax('', {
		update: $('content'),
		onRequest: function () {$('content').innerHTML = ''},
		onSuccess: function () {
			otherLinks();
			externalLinks();
			facts_scroll();
			
		} 
});
news_request.url = URL + 'xmlhttp/' + language + '/news'  +'?clearcache=' + clearcache;
news_request.request();

}


addDOMLoadEvent(externalLinks);
addDOMLoadEvent(create_scroll);
addDOMLoadEvent(menu);
addDOMLoadEvent(contact);
addDOMLoadEvent(fix_opera_8);
addDOMLoadEvent(text_resize);
addDOMLoadEvent(window_dimensions);
addDOMLoadEvent(news);




var currheight;
window.onresize = function(){
	if(currheight != document.documentElement.clientHeight)
	{
		var wrapper_values = wrapper.getCoordinates();
		
		wrapper_width = wrapper_values.width;
		wrapper_height = wrapper_values.height;
		window_dimensions();
		var h1_values = $('logo').getCoordinates();
		h1_width = h1_values.width;
		if(status=='inceput') { 
		
			h1_top = h1.getTop();
			h1_left = h1.getLeft();

			$('logo').setStyle('margin',0);
			
			if(wrapper_height < ( h1_top + h1_width) ) {
				$('logo').setStyle('top', wrapper_height - h1_width);
			}

			if(wrapper_width < ( h1_left + h1_width) ) {
				$('logo').setStyle('left', wrapper_width - h1_width);
			}

			var mouse_fx = new Fx.Styles(h1, {duration: 500,transition: Fx.Transitions.Quad.easeOut});
		
			/* start logo follow mouse	 */
			$('container').addEvent('click', function(event){
				event = new Event(event);
				/* h1 = $('logo'); */

				h1_top = h1.getTop();
				h1_left =h1.getLeft();
				
				y_event = event.page.y - h1_width/2;
				x_event = event.page.x - h1_width/2; 
				
				if(y_event<0) y_event=0;
				if(x_event<0) {x_event=0;}

				if(y_event>wrapper_height-h1_width) {y_event=wrapper_height-h1_width; }
				if(x_event>wrapper_width-h1_width) {x_event=wrapper_width-h1_width; }

				if(mouse_movement&&h1_state!='on')
					mouse_fx.start({'top': [h1_top, y_event],'left': [h1_left, x_event] });

				event.stop();
			});
		}
	}
	currheight = document.documentElement.clientHeight;}


