/*
 *	@titre: layout.
 *	@description: javascript global - dream on.
 *	@auteur: neov - http://www.neov.net.
 *	@creation: 20091109.
 *	@modification: 20091218
 *	@required: jQuery 1.3.2
 *
 */
 
// path.
var path = '' ;
var toggleLogo = false;

// create element.
var dc = function(el) { return document.createElement(el); }
var ie6 = $.browser.msie && $.browser.version < 7;

// global vars
var gtime = 500;

// check langue, 'fr' par defaut.
var lang = $('html').attr('lang')? $('html').attr('lang'):'fr_FR';

// texte array.
var parcours = new Array(), limit = 3, act, nbr;
parcours['fr_FR'] = ['Précedent', 'Suivant'];
parcours['en_EN'] = ['Previous','Next'];
parcours['es_ES'] = ['Anterior','Siguiente'];
parcours['de_DE'] = ['Vorheriger','Nächste'];

function loadAutoClear(arg)
{
	$(arg).each(
		function()
		{
			$(this)
				.focus(
					function()
					{
		                if ($(this).val() == '' || $(this).val()==$(this).attr('title')) {//tmt:invalidtext
		                	$(this).val('');
		                }
					}
				)
				.blur(
					function()
					{
						if($(this).val()=='')
						{
							$(this).val($(this).attr('title'));
						}
					}
				)
		}
	);
}

$(
	function()
	{
	
		switch(lang)
		{
			 case ('fr_FR'):
			 $('#content-inner .deconnect').addClass('fren');
			 break;
			 
			 case ('en_EN'):
			 $('#content-inner .deconnect').addClass('engl');
			 break;
			 
			 case ('es_ES'):
			 $('#content-inner .deconnect').addClass('espa');
			 break;
			 
			 case ('de_DE'):
			 $('#content-inner .deconnect').addClass('allem');
			 break;
			
		};
		
		
		path = j_basepath + 'design/front/' ;
		
		
		// toggle header logo.		
		$('.toggle-logo').click(
			function()
			{
				if(!$(this).hasClass('running')) {
					var $btn = $(this);
					$(this).addClass('running');
					if($(this).hasClass('active')) {
						//ouvert
                        $(this).removeClass('active');
						$('#header-inner .logo p').animate({top: 0}, {queue:true, duration:gtime, easing:"sineEaseOut"});
                        $.ajax({
                            type:"POST",
                            url:j_basepath+'index.php',
                            data:"module=commun&action=accueilFo:logo&iCacher=0",
                            async:false,
                            success:function(resultat){                        
                            }                    
                        });						
						
					} else {
						//fermé						
                        $(this).addClass('active');
						$('#header-inner .logo p').animate({top: -220}, {queue:true, duration:gtime, easing:"sineEaseOut"});
                        $.ajax({
                            type:"POST",
                            url:j_basepath+'index.php',
                            data:"module=commun&action=accueilFo:logo&iCacher=1",
                            async:false,
                            success:function(resultat){                        
                            }                    
                        });						
					}
					
					$('#header-inner .logo').slideToggle({queue:true, duration:gtime, easing:"sineEaseOut"});
					$('#header-inner .logo p').queue(
						function()
						{
							$btn.removeClass('running');
							$(this).dequeue();
						}
					);
				}
				return false;
			}
		);
		
		if(toggleLogo) $('.toggle-logo').trigger('click');
		
		// langue
		var language = ['اختر لغة الواجهة', 'Elige tu idioma', 'Wählen Sie ihre Sprache', 'Choose your language', 'Choisir votre langue'];
		//var language = ['Elige tu idioma', 'Wählen Sie ihre Sprache', 'Choose your language', 'Choisir votre langue'];
		
		$('.choix-langue').hover(
			function()
			{
				var $tip = $(this).find('.tip');
				$(this).addClass('active-lang');
				$(this).find('.selected').hide();
				$(this).find('a').show();
				
				// rollover sur les langues
				$(this).find('a').each(
					function(index) {
						$(this).hover(
							function()
							{
								$tip
									.empty()
									.text(language[index])
									.show();
							},
							function()
							{
								$tip
									.empty()
									.hide();
							}
						);
					}
				);
			},
			function()
			{
				$(this).removeClass('active-lang');
				$(this).find('a').hide();
				$(this).find('.selected').show();
			}
		);
		
		// focus recherche.
		$('.zone-recherche .text')
			.focus(
				function()
				{
					$('.zone-recherche').addClass('focus');
				}
			)
			.blur(
				function()
				{
					$('.zone-recherche').removeClass('focus');
				}
			);
		
		// navigation.
		$('.btn-nav a').each(
			function()
			{
				$(this).hover(
					function()
					{
						$('.hover-info').show();
						$('.hover-info').text($(this).attr('title'));
						
					},
					function()
					{
						$('.hover-info').hide();
					}
				);
			}
		);
		
		// haut de page.
		$('.back-top a').click(
			function()
			{
				$.scrollTo(0,1000);

				return false; 
			}
		);
		
		// menu langue.
		$('.menu-langue li a').hover(
			function()
			{
				if ($(this).parent().hasClass('last')) {
					$(this).parent().next().addClass('hv');
				} else {
					$(this).parent().prev().addClass('hv');
				}
			},
			function()
			{
				if ($(this).parent().hasClass('last')) {
					$(this).parent().next().removeClass('hv');
				} else {
					$(this).parent().prev().removeClass('hv');
				}
			}
		);
		
		// menu footer.
		$('.menu-footer li a').hover(
			function()
			{
				$(this).parent().prev().addClass('hv');
			},
			function()
			{
				$(this).parent().prev().removeClass('hv');
			}
		);
		
		
		//newsletter
		
		$('.menu-langue li.news a').click(
			function()
			{
				$('.pop-newsletter .btn a').fadeIn({queue: false, duration: 200, easing: 'quadEaseOut'});
				$('.pop-newsletter').slideDown({queue: false, duration: gtime, easing: 'bounceEaseOut'});
				
        		$('.formNewletter-footer').show();
        		$('.spop.pop-newsletter p.titre:first').show();
                $('.merci-footer').hide();				
				
				return false;
			}
		);
		
		$('.spop .btn a').click(
			function()
			{
				$(this).fadeOut({queue: false, duration: 200, easing: 'quadEaseOut'});
				$(this).parent().parent().slideUp({queue: false, duration: gtime, easing: 'bounceEaseOut'});
				
				return false;
			}
		);
		
		// simulation target blank.
		$('.target-blank').each(
			function()
			{
				$(this).click(
					function()
					{
						window.open($(this).attr('href'));
						return false;
					}
				);
			}
		);
		
		// autoclear formulaire.
		loadAutoClear('.autoclear');
		
		// bookmark.
		$('.bookmark-delicious a').click(
            function()
            {
                window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550');
                return false;      
            }
        );
        
        /* $('.partage-fb a').click(
            function()
            {
                window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(location.href)+'&t=Lorem='+encodeURIComponent(document.title), 'facebook','toolbar=no,width=550,height=550');
                return false;      
            }
        );*/
        
        if(!ie6) {
			$('.decouv > a').hover(
				function()
				{
					$(this).find('img')
						.css({opacity: 0.7})
						.animate({opacity: 0.8}, {queue: false, duration: gtime, easing: 'sineEaseOut'});
				},
				function()
				{
					$(this).find('img').stop().css({opacity: 1})
				}
			);
		}
		
		
		// acces direct
		$('#acces-direct').click(
			function()
			{
				$('.acces-direct').slideToggle({easing: 'sineEaseOut'});
				$(this).toggleClass('active');
				return false;
			}
		);
		
		$('.acces-direct .fermer').click(
			function()
			{
				$('.acces-direct').slideUp({easing: 'sineEaseOut'});
				$('#acces-direct').removeClass('active');
				return false;
			}
		);		
		
		$('.acces-direct .popPrj').hide();
		
		$('.acces-direct .projet-content > p > a').click(
			function()
			{
				if($(this).parent().next('div').length != 0)
				{
					$('.acces-direct .projet-content').not($(this).parent().parent()).removeClass('active');
					$('.acces-direct .projet-content > div').not($(this).parent().next('div')).hide();
					$(this).parent().parent().toggleClass('active');
					$(this).parent().next('div').toggle();
					
					if($(this).find('.jScrollPaneContainer').length == 0)
					{
						$($(this).parent().next('div')).find('.inner').jScrollPane({
							showArrows:			true, 
							scrollbarWidth: 	19, 
							arrowSize: 			11, 
							scrollbarMargin:	5,
							dragWidth:			9
						});
					}
				}
				
				return false;
			}
		);
		
		$('.acces-direct .popPrj > p > a').click(
			function()
			{
				$(this).parent().parent().hide();
				return false;
			}
		);
		
		$('.main-menu .cad a')
			.live(
				'mouseover',
				function()
				{
				  $('#content-inner .deconnect').show();
				}
			)
			.live(
				'mouseout',
				function()
				{
				  $('#content-inner .deconnect').hide();
				}
			);
			
        $('.logo a').click(function(){
            $.ajax({
                type:"POST",
                url:j_basepath+'index.php',
                data:"module=commun&action=accueilFo:chargerLogoAleatoire",
                async:false,
                success:function(resultat){
                    $(".logo img").attr("src", resultat);                        
                }                    
            });
            
        });
		
	}
);