/**
 *
 * Copyright 2011, ericFreelance
 *
 */
 
var $name  		= 'EfAgiWebConseil';
var $version 	= '1.0';

function ef_InitEfContactForm($options)
{	
	// options
	if ( $options )
	{
		if ( $options['form'] ) 
		{
			$form = $options['form'];
		}
	}
	
	$tw = window.innerWidth;
	if ($tw > 685)
	{	
		// hide the form
		$($form).hide().addClass('hide');
		
		// show the form
		$('#loadContact').click( function () {
		
			if ($($form).hasClass('hide'))
			{
				$($form).show('slow', function () {
					$($form).removeClass('hide');
				});
			} else {
				$($form).hide('slow', function () {
					$($form).addClass('hide');
				});
			}
		});
	} else {
		// hide the form
		$($form).hide();
		
		// show the form
		$('#loadContact').click( function () {
			$($form).show();
		});
	}
};

function ef_InitEfMenu($options)
{	
	$n = '';

	$('div').removeClass('nojs');
	
	// options
	if ( $options )
	{
		if ($options['nav']) 
		{
			$nav = $options['nav'];
			$nav_link = $options['nav']+' a.menuSlide';
		}
	}
	
	// @media
	$tw = window.innerWidth;
	
	if ($tw <= 685)
	{
		$('img').removeAttr('width').removeAttr('height');
		$tel = $('#contactTel a').attr('rel');
		$('#contactTel a').attr('href', 'tel:'+$tel);
	}
	/*
	$(window).resize(function() {
		$tw = window.innerWidth;
		$($nav+' li').css({top: '0'});
		if ($tw > 685)
		{
			$($nav+', .showContent, #news,  #content').show();
			$('.box685').hide();
			
			if ($n != '' )
			{
				if ($($nav+' .menu_'+$n).hasClass('active'))
				{
					for (i=1;i<=$n;i++)
					{
						$($nav+' .menu_'+i).animate({ 
							top: '-200px'
						}, 500);
					}
					for (i=$n+1;i<=$($nav_link).length;i++)
					{
						$($nav+' .menu_'+i).animate({ 
							top: '0'
						}, 500 );
					}
				}
			}
			
		} else {
			$('.showMenu, #news, #content').hide();
			$('.showContent').show();
			$('img').removeAttr('width').removeAttr('height');
		}
	});*/
	
	$('.showContent a').click( function() {
		$('#news, #content, .showNav').show();
		$($nav+', .showContent').hide();
	});
	
	$('.showNav a').click( function() {
		$('#news, #content, .showNav').hide();
		$($nav+', .showContent').show();
	});
	
	// remove first link home
	$($nav+' li.home').remove();
	
	// position nav
	$l = 960 - (50*$($nav+' a').length);
	$('#ef_navSlider').css('left',$l);
	
	// items img
	$($nav+' img').css({'position':'absolute', 'z-index':'0'});
	$($nav+' img.active').css('z-index','1');
	for (i=0;i<$($nav+' img').length;i++)
	{		
		$($nav+' img:eq('+i+')').addClass('img_'+(i));
	}
	
	// items menu
	for (i=0;i<$($nav+' a').length;i++)
	{		
		$url = $($nav+' li:eq('+i+') a').attr('href');
		$($nav+' li:eq('+i+')').addClass('menu_'+(i+1));
		$($nav+' li:eq('+i+'), '+$nav+' li:eq('+i+') a').addClass('menuSlide');
		$($nav+' li:eq('+i+') .textSlide').append('<div class="menuLink"><a href="'+$url+'">En savoir plus</a></div>');
	}

	// tooltip
	$($nav+' .textSlide').css('display','block');	
	
	// action
	$($nav_link).click( function () {
	
		$n = $($nav_link).index(this);
		$n = $n+1;
		
		if ($tw > 685)
		{		
			if ($($nav+' .menu_'+$n).hasClass('active'))
			{
				$($nav+' li').removeClass('active');
				for (i=1;i<=$($nav_link).length;i++)
				{
					$($nav+' .menu_'+i).animate({ 
						top: '0'
					}, 500 );
				}
				
				$($nav+' .img_0').css({'z-index':'2', 'opacity':'0'});
				$($nav+' .img_0').animate({ 
						opacity: '1'
				}, 500, function() {
					$($nav+' img.active').css({'z-index':'0'}).removeClass('active');
					$($nav+' .img_0').css({'z-index':'1'}).addClass('active');
				});			
				
			} else {
				$($nav+' li').removeClass('active');
						
				for (i=1;i<=$n;i++)
				{
					$($nav+' .menu_'+i).animate({ 
						top: '-200px'
					}, 500, function() {					
							$($nav+' .menu_'+$n).addClass('active');						
					});
				}
				for (i=$n+1;i<=$($nav_link).length;i++)
				{
					$($nav+' .menu_'+i).animate({ 
						top: '0'
					}, 500 );
				}
				
				$($nav+' .img_'+$n).css({'z-index':'2', 'opacity':'0'});
				$($nav+' .img_'+$n).animate({ 
						opacity: '1'
				}, 500, function() {
					$($nav+' img.active').css({'z-index':'0'}).removeClass('active');
					$($nav+' .img_'+$n).css({'z-index':'1'}).addClass('active');
				});
			}
			
			return false;
		}
	});
};


$(function(){
	ef_InitEfContactForm({'form':'#ef_contactForm form'});
		
	if ($.browser.msie)
	{
		if($.browser.version != '8.0' && $.browser.version != '7.0')
			ef_InitEfMenu({'nav':'#zoneNav'});
	} else {
		ef_InitEfMenu({'nav':'#zoneNav'});
	}
	
	
});
