$(document).ready(function(){
	
	var loader = $('<div class="loaderGlobal" style="text-align: center;"><img src="/skins/soluseo/loaderGlobal.gif" alt="" title=""></div>');

	/**Liens externes**/
	$('a[rel=open]').click(function () {
		window.open($(this).attr('href'));
		return false;
	});
	/****/
		
	/**Gestion des champs recherche**/
	var inputSearchValue;
	
	$('.inputSearch').focus(function() {
		inputSearchValue = $(this).val();
		$(this).val('');
	});

	$('.inputSearch').blur(function() {
		if ($(this).val() == '') $(this).val(inputSearchValue);
	});
	/****/
	
	$('.blockSelection').css('cursor','pointer');
	$('.blockSelection, .blockSelection a[rel=#popupSearch]').live('click',function() {
		$('#popupSearch').show();
		smoothScroll($('.blockHeaderMenu').offset().top+80);
		return false;
	});

	/**ToolTips page des solutions**/
	if ($('.blockSolutionsLabel').size()) {
		$('.blockSolutionsLabel a').each(function() {
			var toolTip    = 'div.'+$(this).attr('id');
			//var link       = $(this);
			//var height     = link.height();
			//var offset     = link.offset();
//
			//$(toolTip).css({
				//position : 'absolute',
				//top : (offset.top+height-16),
				//left : (offset.left-2)
			//})

			$(this).menu({
				menuHeight : $(toolTip).height(),
				sLink      : $(this),
				sMenu      : $(toolTip).height(0),
				sClass	   : $(this).attr('class'),
				//sClassSel  : '-selected',
				sCloseTime : 300
			});
		});

	}
	/****/

	/**Tooltip searchMap**/
	var reg = new RegExp('(.*)([0-9][0-9]|[0-9][a-b]|[0-9][a-b])(.*)','g');
	$('.jsTip').hover(function(e) {
		var dpt     = $(this).attr('href').replace(reg,'$2');
		var toolTip = $('#departement-'+dpt);

		var leftP = e.clientX-(toolTip.width()/2);
		if(isIE){
			var topP  = e.clientY-toolTip.height()-2+document.documentElement.scrollTop;
		}else{
			var topP  = e.clientY-toolTip.height()-2+window.scrollY;
		}

		toolTip.css({
			top: topP,
			left: leftP
		});
		toolTip.show();
	},function() {
		var dpt     = $(this).attr('href').replace(reg,'$2');
		var toolTip = $('#departement-'+dpt);
	
		toolTip.hide();
	});

	//Menu solutions
	var menuSolution;
	$('ul.mainMenu li.item-1 a').attr('id','itemMenuSolutions');
	$('ul.mainMenu li.item-1 a').each(function(){
		menuSolutions = $(this).menu({
			menuHeight : $('div.underMenuSolutions').height(),
			sLink      : $(this),
			sMenu      : $('div.underMenuSolutions').height(0),
			input      : $('input.inputSearch'),
			lagLeft    : 8,
			lagTop     : 0
		});
	});
	
	//$('ul.mainMenu li').each(function(){
		//var liEl = $(this);
		//var aEl = liEl.find('a');
		//var ulEl = liEl.find('ul');
		//ulEl.css('display','none');
		//liEl.hover(function(){
			//ulEl.css('display','block');
			//liEl.addClass('hover');
		//},function(){
			//ulEl.css('display','none');
			//liEl.removeClass('hover');
		//});
	//});
	//$('.inputSearch').each(function(){
		//$(this).hover(function(){
			//$('#mainMenu li').each(function(){
				//$(this).find('ul').css('display','none');
				//$(this).removeClass('hover');
			//});
		//});
	//});

	//Menu sideBar solutions
	$('ul.menuSolutions li a').click(function () {
		var underMenu = $('ul.menuSolutions li ul');
		var parentUl  = $(this).closest('ul');

		if (parentUl.hasClass('menuSolutions') && !$(this).hasClass('activ')) {
			underMenu.each(function () {
				var link = $(this).closest('li').children('a');
	
				var reg   = new RegExp('\/(.*)\.html','gi');
				var href  = link.attr('href').replace(reg,'$1');
				var match = window.location.href.match(href);
		
			});

		}
	});

	$('ul.menuSolutions li a').each(function(){
		var parentLi        = $(this).closest('li');
		var parentUl        = $(this).closest('ul');
		var underMenu       = parentLi.children('ul');

		var reg   = new RegExp('\/(.*)\.html','gi');
		var href  = $(this).attr('href').replace(reg,'$1');
		var match = window.location.href.match(href);

		if (parentUl.hasClass('menuSolutions') && !match) {
			underMenu.hide();
		} else if (parentUl.hasClass('menuSolutions') && match) {
			$(this).addClass('activ');
		}
	});

	/**Construction de la popup**/
	constructPopupSearch();

	$('a[href=#zoommaplist]').click(function () {
		var map      = $('#map');
		var blockMap = $('div.blockMap');
		var shopMap  = $('#shopMap');
		var time     = 500;

		var center   = gShopMap.getCenter();
		var size	 = gShopMap.getSize();
	
		if (map.css('display') == 'none') {
			$(this).html($(this).html().replace('Afficher','Masquer'));
			map.height(0);
			map.stop().animate({
				height: 364
			},time);
			gShopMap.checkResize();
			gShopMap.setCenter(center);
		} else {
			map.stop().animate({
				height: 0
			},time,function () {
				map.css('display','none');
			});
			$(this).html($(this).html().replace('Masquer','Afficher'));
		}
	});

	if ($('#blockGlobal #blockCenter .blockSlides').length) {
		var slideSlide = new $.fn.slide({
			container : $('.blockSlides .blockSolution-1 .blockContent'),
			slider    : $('div.blockSlides .blockSolution-1 .blockContent div:first'),
			slides    : $('div.blockSlides .blockSolution-1 .blockContent div.slide'),
			links     : $('div.blockSlides .blockNav,div.blockMenuNav ul.menuSolutions li'),
			effect    : 'slide',
			containerStopHover : $('.blockSlides .blockSolution-1'),
			delay     : 5000
		});
	
		var slideFade = new $.fn.slide({
			container : $('.blockSlides .blockSolution-1 #slideImg'),
			slider    : $('div.blockSlides .blockSolution-1 #slideImg div:first'),
			slides    : $('div.blockSlides .blockSolution-1 #slideImg div:first div'),
			links     : $('div.blockSlides .blockNav,div.blockMenuNav ul.menuSolutions li'),
			effect    : 'fade',
			containerStopHover : $('.blockSlides .blockSolution-1'),
			delay     : 5000,
			noactiv   : true
		});
	}

	var slidePartner = new $.fn.slide({
		slides : $('div.blockPartners div div.logoPartners'),
		effect : 'fade',
		delay  : '5000'
	});

	$('.btnVideo').fancybox({
		'padding' : 10, 
		'width' : 560,
		'height' : 340,
		'centerOnScroll' : true,
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'type' : 'swf',
		'overlayOpacity' : 0.6,
		'overlayColor' : '#000000',
		'backcolor': '#83B817'
	});

	$('.btnVideoRugby').fancybox({
		'padding' : 10, 
		'width' : 578,
		'height' : 358,
		'centerOnScroll' : true,
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'type' : 'iframe',
		'overlayOpacity' : 0.6,
		'overlayColor' : '#000000'
	});

	/**
	 *  Popup Splash
	 */
	//window.setTimeout(function() {$('#popupSplash[class=showPopup]').show()},1000);
	//$('#popupSplash a.btnClose,#popupSplash a[rel=btnClose],#popupSplash #popupOverlay').click(function () {
		//$('#popupSplash').hide();
//
		//return false;
	//});

	$(' a.imgOperationRugby').unbind('click').click(function(){
		$('#popupPromo').show();
		return false;
	});
	window.setTimeout(function() {$('#popupPromo[class=showPopup]').show()},1000);
	$('#popupPromo a.btnClose,#popupPromo a[rel=#close],#popupPromo #popupPromoOverlay').click(function () {
		$('#popupPromo').hide();
		return false;
	});

});

