function getIframeLayer(elementId) {
	iframeId = elementId+"IframeLayer";
	if ($('#'+iframeId).attr('id')+'' == 'undefined') {
		var iframeLayer = document.createElement("iframe");
		iframeLayer.setAttribute("id", iframeId);
		iframeLayer.setAttribute("scrolling", "no");
		iframeLayer.setAttribute("frameborder", "0");
		iframeLayer.setAttribute("style", "z-index:0; position:absolute; border:0; top:0; left:0; width:0; height:0; ");
		iframeLayer.setAttribute("src", "javascript:'<html></html>';");
		first = document.body.firstChild,
		document.body.insertBefore(iframeLayer, first);
		
	} else {
		var iframeLayer = $(iframeId);
		return iframeLayer;
	}
	return $(iframeLayer);
}

function relocateIframeLayer(elementId) {
	iframeId = '#'+elementId+"IframeLayer";
	if ($(iframeId).attr('id')+'' == 'undefined') {
		var iframeLayer = getIframeLayer(elementId);
	} else {
		var iframeLayer = $(iframeId);
	}
	$('#'+elementId).css('display', 'block');
	pos = $('#'+elementId).offset();
	width = $('#'+elementId).outerWidth();
	height = $('#'+elementId).outerHeight();
	iframeLayer.css('position', 'absolute');
	iframeLayer.css('top', pos.top);
	iframeLayer.css('left', pos.left);
	iframeLayer.css('width', width);
	iframeLayer.css('height', height);
	iframeLayer.css('z-index', 1);
}

function hideIframeLayer(elementId) {
	iframeId = '#'+elementId+"IframeLayer";
	if ($(iframeId).attr('id')+'' != 'undefined') {
		var iframeLayer = $(iframeId);
		iframeLayer.css('width', 0);
		iframeLayer.css('height', 0);
		iframeLayer.css('z-index', 0);
		document.getElementById(elementId+"IframeLayer").style.zIndex = 0;
	}
}

function preloadMenuBG(){
	var arImages = new Array();
	arImages[0] = '/img/menu_top/fiscal.jpg';
	arImages[1] = '/img/menu_top/books.jpg';
	arImages[2] = '/img/menu_top/comp_au.jpg';
	arImages[3] = '/img/menu_top/fiduciaire.jpg';
	arImages[4] = '/img/menu_top/res_hum.jpg';
	arImages[5] = '/img/menu_top/finance.jpg';
	
	var d=document; 
	if(d.images) { 
		if ( !d.preloadedImages ) d.preloadedImages=new Array();

		var i, j=d.preloadedImages.length;
		
		for(i=1; i<arImages.length; i++) {
			d.preloadedImages[j] = new Image;
			d.preloadedImages[j++].src = arImages[i];
		}
	}
}

function setHovers(pattern){
	if ($(pattern)) {
		$(pattern).each(function(){
			d = document;
			if (!d.preloadedImages) d.preloadedImages = new Array();
			ob = $('img', this);
			var i = d.preloadedImages.length;
			var source = ob.attr('src').split('_over').join('');
			var arSrc = source.split('.');
			var ext = arSrc.pop();
			var prefix = arSrc.join('');
			var overSource = prefix + '_over.' + ext;
			d.preloadedImages[i] = new Image;
			d.preloadedImages[i].src = source;
			d.preloadedImages[i + 1] = new Image;
			d.preloadedImages[i + 1].src = overSource;
			
		});
		$(pattern).mouseenter(function(){
			if ($(this).hasClass('activepoint')) 
				return;
			var curSource = $('img', this).attr('src');
			var arSrc = curSource.split('.');
			var ext = arSrc.pop();
			var prefix = arSrc.join('');
			$('img', this).attr('src', prefix + '_over.' + ext);
		});
		$(pattern).mouseleave(function(){
			if ($(this).hasClass('activepoint')) 
				return;
			$('img', this).attr('src', $('img', this).attr('src').split('_over').join(''));
		});
	}
}

function blur(){
	$(this).blur();
}

var globOpen = true;
var globSimple = false;
function ajaxPopupLoad(id, simple) {

	$('.popupBlack').show();
	$('.popupBlack').css('opacity', 0.73);
	
	var top = 230;
	
	$('.ajaxThrobber').css({left: (($(document.body).outerWidth()/2) - 16)+'px'});
	if(globSimple) {
		$('.ajaxThrobber').css( { position: 'absolute', top: top + $(window).scrollTop() } ).show();
	} else {
		$('.ajaxThrobber').css( { position: 'fixed', top: top } ).show();
	}
	$('.popup > .popupInfoContainer').load('/team_person/', { simple: simple, id: id}, function(){
		setTimeout('ajaxPopupShow()', 250);
	});

}

function ajaxPopupShow(){
	if (globOpen) {
		var top = 170;
		$('.ajaxThrobber').hide();
		$('.pupup').show(0);
		if ($('.popup').outerHeight() + top < $(window).height() && !globSimple) {
			$('.popup').css( { position: 'fixed', top: top } );
		} else {
			$('.popup').css( { position: 'absolute', top: top + $(window).scrollTop() } );
		}
		$('.popup').fadeIn(333, function(){
			resizeMask();
		});
	}
}

function ajaxPopupHide(){
	globOpen = false;
	$('.ajaxThrobber').hide();
	$('.popup').fadeOut(333);
	$('.popupBlack').fadeOut(333, function(){
		resizeMask();
	});
	$('.popup > .popupInfoContainer').html('');
	return false;
}

function resizeMask(){
	$('.popupBlack').height($(document).height());
	$('.popupBlack').width($(window).width() < $(document.body).width() ? $(document.body).width() : $(window).width());
}

var printPopupWnd;

function ajaxPopupPrint() {
	ajaxPrintData = $('.popup > .popupInfoContainer > .boxPopup > .teamPoint').html();
	printPopupWnd = window.open('/print','','fullscreen=0,width=600,height=600,target=_blank,status=0,toolbar=0,scrollbars=0,menubar=0,resizable=0,location=0,directories=0,status=0');
	window.focus();
	setTimeout('closePrintPopupWnd()', 2000);
	return false;
}

function closePrintPopupWnd() {
	if(printPopupWnd)printPopupWnd.close();
}

$(document).ready(function(){
	setHovers('.menuTop > a');
	setHovers('.menuCenter > .point > a');
	setHovers('.langs > a');
	setHovers('.footer > div > a');
	$('.stiker', this).hide();
	resizeMask();
	$(window).resize(function(){
		resizeMask();
	}); 	
	if($('.popupBlack')) $('.popupBlack').click(function(){
		ajaxPopupHide();
	});
	if($('.popup')) $('.popup').click(function(e){
		if($(e.target).hasClass('popupInfoContainer') || $(e.target).hasClass('popup')) ajaxPopupHide();
	});
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
		globSimple = true;
		$('.popup').css({position: 'absolute'});
		$('.ajaxThrobber').css({position: 'absolute'});
	}
	
	$('.team_info_link').click(function(){
		globOpen = true;
		$('.popup > .popupInfoContainer').html('');
		if ($('.popup > .popupInfoContainer')) {
			var ob = $(this);
			
			id = String(ob.attr('id')).split('id_info_link_').join('');
			ajaxPopupLoad(id, globSimple);
		}
		return false;
	});
	
	if($('.boxTeam')){
		$('.boxTeam > .block > .image').mouseenter(function(){
			$('.name', this.parentNode).stop(true, true);
			$('.stiker', this.parentNode).stop(true, true);
			$('.name', this.parentNode).fadeOut(250);
			$('.stiker', this.parentNode).fadeIn(250);
		});
		$('.boxTeam > .block > .image').mouseleave(function(){
			$('.name', this.parentNode).stop(true, true);
			$('.stiker', this.parentNode).stop(true, true);
			$('.stiker', this.parentNode).fadeOut(250);
			$('.name', this.parentNode).fadeIn(250);
		});
	}
	$('object').live('mouseover', function(){
		$(this).unbind('focus', blur);
		$(this).focus(blur);
	});
	$('a').focus(blur);
	preloadMenuBG();
});