/**
	This event shows all services popup
	It takes the footer services and clone it for header
	Will close on another click or click somewhere outer the services area
*/
window.addEvent('domready', function() {
	var link 	= $('all_serv_link');
	var popup 	= $('all_serv_popup');
	var src 	= $('all_services');
	var target 	= $('all_serv_popup_content');
	var tmpId 	= 'all_serv_hide';
	var all_serv_popup_opened = false;
	var all_serv_popup_can_close = true;
	
	var img 	= $('all_serv_img');
	var use_spec_img = false;

	var default_img_up = 'ic_collapse';
	var default_img_down = 'ic_expand';
	var default_img_down_pat = /(ic_expand\.gif)$/;
	var default_img_up_pat = /(ic_collapse\.gif)$/;
	
	function close_all_serv_popup(){
		if(all_serv_popup_opened && all_serv_popup_can_close) {
			new Fx.Style(tmpId, 'opacity', {
					duration: 500,
					transition: Fx.Transitions.Quart.easeInOut
			}).start(1,0);
		
			(function(){popup.setStyle('visibility', 'hidden');}).delay(400); //wait and execute
			
			img.src = img.src.replace(default_img_up_pat, default_img_down+'.gif');
			
			showHideFlash(true);
			
			all_serv_popup_opened = false;
		}

		all_serv_popup_can_close = true;
	}
	
	if(target!=null && src!=null){
		target.innerHTML = '<div id="' + tmpId + '">' + src.innerHTML + '</div>';
	}

	if(link!=null){
	link.addEvent('click', function(){
  
		var coord = link.getPosition(); 
  
		if(popup.getStyle('visibility') == 'hidden') {
  
			popup.setStyle('top', coord.y+20+'px');
	
			$(tmpId).setStyle('visibility', 'hidden');
			
			popup.setStyle('visibility', 'visible');
			
			new Fx.Style(tmpId, 'opacity', {
					duration: 500,
					transition: Fx.Transitions.Quart.easeInOut
			}).start(0.2,1);
			
			img.src = img.src.replace(default_img_down_pat, default_img_up+'.gif');
			
			(function(){all_serv_popup_opened=true;}).delay(500)
			
			
			showHideFlash(false);
		}
		link.blur();
	});
	document.addEvent('click', close_all_serv_popup);
	document.addEvent('keyup', close_all_serv_popup);

	popup.addEvent('click', function(){all_serv_popup_can_close = false});
	}
});


function firePopupEvent() {
	
	$('all_serv_link').fireEvent('click');
}

function toggleLangPanel() {

	var LangPanel = $('LangPanel');

	if(LangPanel) {

		var LangPanelStatus = $('LangPanelStatus');

		if(LangPanel.hasClass('hidden')) {

			var correction = {x:-18, y:-3};
			if(window.__LANGP_CORRECTION && typeof(window.__LANGP_CORRECTION)=='object') {
				correction = window.__LANGP_CORRECTION;
			}
			if(window.ie) correction.y -= 4;

			//if(window.ie) correction = {x:-18, y:-6};
			//else if(window.ie7) correction = {x:-18, y:-6};
			//else if(window.opera) correction = {x:-18, y:0};

			var LangPanelStatusCoords = LangPanelStatus.getCoordinates();
			var left = LangPanelStatusCoords.left+correction.x+10;
			var top = LangPanelStatusCoords.top+correction.y;

			LangPanel.setStyles({'position':'absolute', 'top':top, 'left':left});
			LangPanel.removeClass('hidden');
			LangPanel.addClass('visible');
			if(LangPanelStatus) {
				//LangPanelStatus.addClass('hidden');
				LangPanelStatus.setStyle('visibility', 'hidden');
			}
		}
		else {
			LangPanel.addClass('hidden');
			LangPanel.removeClass('visible');
			if(LangPanelStatus) {
				//LangPanelStatus.removeClass('hidden');
				LangPanelStatus.setStyle('visibility', 'visible');
			}
		}
	}
	return false;
}