// JavaScript Document	
	var wWidth = 0, wHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    wWidth = window.innerWidth;
    wHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    wWidth = document.documentElement.clientWidth;
    wHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    wWidth = document.body.clientWidth;
    wHeight = document.body.clientHeight;
  }
var browser=navigator.appName;
function returnFalse() { return false; };

$(document).ready(function(){
	var nbItemsPreFooter = $('#infoColumns').text();
	var nbItemsFooter = $('#infoColumnsFooter').text();
	nbItemsFooter ++;
	$('#smallImages').columnize({columns:5});
	$('#targetImages').columnize({columns:4});	
	$('#footerInverseColor').columnize({columns:4});
	$('#targetPreFooter').columnize({columns:nbItemsPreFooter});			
	
			

	

// -+-+-+-+-+- PURPLE SQUARE -> MINI GALLERY 	
	$('.bigOne').stop().hide();
	$('#targetImages p img').click(function(){
		$(this).next('.bigOne').stop().show('slow');
	});
	$('#targetImages p img').mouseout(function(){		
		$('.bigOne').stop().hide('slow');
	});			

	
// +-+-+-+-+-+-+-+- TOP IMAGE 	
	var currentTopImage = $('#topImage01');
	var direction = 'next';
	var timer = setInterval (function () {
		
		
		if ((currentTopImage.next('.topImageToFade').attr('class') == undefined) || ((direction == 'previous') && (currentTopImage.prev('.topImageToFade').attr('class') != undefined)))
		{
			
			currentTopImage = currentTopImage.prev('.topImageToFade'); 
			currentTopImage.show(function(){currentTopImage.fadeTo('slow', 1);});
			direction = 'previous';
		}
		else
		{
			currentTopImage.fadeTo('slow', 0, function(){$(this).hide();});
			currentTopImage = currentTopImage.next('.topImageToFade');
			direction = 'next'; 
			
		}				
		
	}, 3000 ); 


// +-+-+-+-+-+- LIST PAGE

			$('.textItem').hide();
			$('#item1').slideDown('slow');
			$('#items h3').click(function() {

				if ($(this).next('.textItem:visible').length != 0)
				{
					$(this).next('.textItem').stop().slideUp('slow');
				}			
				else 
				{
					//$('.textItem').slideUp('slow');
					$(this).next('.textItem').stop().slideDown('slow');
				}
			});
			
// +-+-+-+-+-+-+-+-+-+- GALLERY 

	$('#gallery').fadeTo('fast',0.85);
	var countImages = $('.smallGallery').length;
	$('.smallGallery').click(function(){
		var id = $(this).attr('id');
		id = id.substring(5,14);
		var monObjet = "undef";
		$('#gallery').show(function(monObjet){
			imageWidth =  $('#'+id).width();
			imageHeight = $('#'+id).height();
			if ((wWidth / wHeight) < 1.5)
			{
				
				if((imageWidth / imageHeight) > 1.5)
				{
					
					var oldWidth = imageWidth;
					var newWidth = 75 * wWidth / 100;
					var newHeight = imageHeight * newWidth/oldWidth;
					
				}
				else {
					var oldHeight = imageHeight;
					var newHeight = 75 * wHeight / 100;
					var newWidth = imageWidth * newHeight/oldHeight;	
				}
			}
			else {
				if((imageWidth / imageHeight) > 1.5)
				{
					var oldWidth = imageWidth;
					var newWidth = 65 * wWidth / 100;
					var newHeight = imageHeight * newWidth/oldWidth;
				}
				else {
					var oldHeight = imageHeight;
					var newHeight = 75 * wHeight / 100;
					var newWidth = imageWidth * newHeight/oldHeight;	
				}
			}
			var cssObj = {
				'width': newWidth,
				'height': newHeight,
				'margin-left': -newWidth / 2,
				'margin-top': -newHeight / 2
			};
			$('#'+id).css(cssObj);				
			$('#closeGallery').show();
			$('#'+id).show();
			monObjet = $('#'+id);
		});
		
		var booleen = true;	
		var nextImage = false; 
		var prevImage = false;
		// *-*-*-*-*-* FUNCTION NEXT -*-*-*-*-*-* 
		$('#next').click(function(){
			nextImage = true;
			if (booleen)
			{
				var monObjet = $('#'+id);
				booleen = false;
				idee = id.substring(7,9);
				//parseFloat(idee);
			}
			else if (prevImage) {
				idee--;
				if (idee < 10)
				{
					var monObjet = $('#gallery0'+idee);
				}
				else {	
					var monObjet = $('#gallery'+idee);
				}
				prevImage = false;
			}
			else {
				idee++;
				if (idee < 10)
				{
					var monObjet = $('#gallery0'+idee);
				}
				else {	
					var monObjet = $('#gallery'+idee);
				}			
			}
			
			/* VERIFICATION LAST ACHIEVE */
			if (idee < countImages)
			{
				
				if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)||browser=="Microsoft Internet Explorer")
				{
					monObjet.fadeOut('fast');
				}
				else {
					monObjet.hide();
				}	
				var monObjet = monObjet.next('#galleryContent img');
			
				imageWidth =  monObjet.width();
				imageHeight = monObjet.height();
				if ((wWidth / wHeight) < 1.5)
				{
					
					if((imageWidth / imageHeight) > 1.5)
					{
						var oldWidth = imageWidth;
						var newWidth = 75 * wWidth / 100;
						var newHeight = imageHeight * newWidth/oldWidth;
					}
					else {
						var oldHeight = imageHeight;
						var newHeight = 75 * wHeight / 100;
						var newWidth = imageWidth * newHeight/oldHeight;	
					}
				}
				else {
					if((imageWidth / imageHeight) > 1.5)
					{
						var oldWidth = imageWidth;
						var newWidth = 65 * wWidth / 100;
						var newHeight = imageHeight * newWidth/oldWidth;
					}
					else {
						var oldHeight = imageHeight;
						var newHeight = 75 * wHeight / 100;
						var newWidth = imageWidth * newHeight/oldHeight;	
					}
				}
				
				var cssObj = {
					'width': newWidth,
					'height': newHeight,
					'margin-left': -newWidth / 2,
					'margin-top': -newHeight / 2
				};
				monObjet.css(cssObj);
				if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)||browser=="Microsoft Internet Explorer")
				{
					monObjet.fadeIn('slow');
				}
				else {
					monObjet.show();
				}
			
			}
			return false;
		});	


		// *-*-*-*-*-* FUNCTION PREVIOUS -*-*-*-*-*-* 
		
		$('#prev').click(function(){
			prevImage = true;
			if (booleen)
			{
				var monObjet = $('#'+id);
				booleen = false;
				idee = id.substring(7,9);
				//parseFloat(idee);
			}
			else if (nextImage) {
				idee++;
				if (idee < 10)
				{
					var monObjet = $('#gallery0'+idee);
				}
				else {	
					var monObjet = $('#gallery'+idee);
				}
				nextImage = false;
			}
			else {
				idee--;
				if (idee < 10)
				{
					var monObjet = $('#gallery0'+idee);
				}
				else {	
					var monObjet = $('#gallery'+idee);
				}		
			}
			
			/* VERIFICATION FIRST ACHIEVE */
			if (idee > 1)
			{

				if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)||browser=="Microsoft Internet Explorer")
				{
					monObjet.fadeOut('fast');
				}
				else {
					monObjet.hide();
				}				
				var monObjet = monObjet.prev('#galleryContent img');
				
				imageWidth =  monObjet.width();
				imageHeight = monObjet.height();
				if ((wWidth / wHeight) < 1.5)
				{
					
					if((imageWidth / imageHeight) > 1.5)
					{
						var oldWidth = imageWidth;
						var newWidth = 75 * wWidth / 100;
						var newHeight = imageHeight * newWidth/oldWidth;
					}
					else {
						var oldHeight = imageHeight;
						var newHeight = 75 * wHeight / 100;
						var newWidth = imageWidth * newHeight/oldHeight;	
					}
				}
				else {
					if((imageWidth / imageHeight) > 1.5)
					{
						var oldWidth = imageWidth;
						var newWidth = 65 * wWidth / 100;
						var newHeight = imageHeight * newWidth/oldWidth;
					}
					else {
						var oldHeight = imageHeight;
						var newHeight = 75 * wHeight / 100;
						var newWidth = imageWidth * newHeight/oldHeight;	
					}
				}
				var cssObj = {
					'width': newWidth,
					'height': newHeight,
					'margin-left': -newWidth / 2,
					'margin-top': -newHeight / 2
				};
				monObjet.css(cssObj);
				if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)||browser=="Microsoft Internet Explorer")
				{
					monObjet.fadeIn('slow');
				}
				else {
					monObjet.show();
				}	
			}
			return false;
		});	



	});
	
	$('#closeGallery a#close').click(function(){ $('#gallery').hide();$('#galleryContent img').hide();$('#closeGallery').hide(); });
	$('#smallImages img').mouseover(function(){$(this).stop().fadeTo('slow',0.8)});
	$('#smallImages img').mouseout(function(){$(this).stop().fadeTo('slow',1)});
	
	$('.eventsPromoBox').mouseover(function(){$(this).stop().fadeTo('slow',0.8)});
	$('.eventsPromoBox').mouseout(function(){$(this).stop().fadeTo('slow',1)});
	
	
	
	/* -++-+-+-+-+-+-+- CONTACT FORM +-+-+-++-+-+- */
	
	$('#submit .button').bind('click', returnFalse);
	var firstName = false;
	var lastName = false;
	var emailFrom = false;
	
	$('#txtFirstName').blur(function(){
		if ($('#txtFirstName').val() == '')
		{
			$('#alertFirstName').append('<p class="red">* Your first name is requested</p>');
			firstName = false;
		}
		else {
			$('#alertFirstName').append('<p class="green">* Field first name completed</p>');	
			firstName = true;
		}		

		if (emailFrom && lastName && firstName)
		{
			$('#submit .button').unbind('click', returnFalse);
		}		
	});

	$('#txtLastName').blur(function(){
		if ($('#txtLastName').val() == '')
		{
			$('#alertLastName').append('<p class="red">* Your last name is requested</p>');	
			lastName = false;
		}
		else {
			$('#alertLastName').append('<p class="green">* Field last name completed</p>');	
			lastName = true;
		}		

		if (emailFrom && lastName && firstName)
		{
			$('#submit .button').unbind('click', returnFalse);
		}	
	});

	var filter=/^.+@.+\..{2,3}$/;
	$('#txtEmailFrom').blur(function(){
		if ($('#txtEmailFrom').val() == '')
		{
			$('#alertEmailFrom').append('<p class="red">* The field email is requested</p>');	
			emailFrom = false;
		}
		else if (filter.test($('#txtEmailFrom').val())) {
			$('#alertEmailFrom').append('<p class="green">* Field email is completed</p>');	
			emailFrom = true;
		}
		else {
			$('#alertEmailFrom').append('<p class="orange">* Please enter a valid email address</p>');	
			emailFrom = false;
		}		
		
		if (emailFrom && lastName && firstName)
		{
			$('#submit .button').unbind('click', returnFalse);
		
		}	
	});


	$('#txtEmailFrom').focus(function(){
		$('#alertEmailFrom').empty();	
	});	
	
	$('#txtFirstName').focus(function(){
		$('#alertFirstName').empty();	
	});		

	$('#txtLastName').focus(function(){
		$('#alertLastName').empty();	
	});	
	
	$('#submit .button').click(function(){
	  if (emailFrom && lastName && firstName)
	  {
	 	$('#submit .button').unbind('click', returnFalse);
	  }
	 
	});	
	
	
	/* +-+-+-++-+- VIDEO GALLERY +-+-+-+--+ */
	
	if($('#videoGallery').attr('id') != undefined)
	{
		var infoPageName = $('#infoPageName').text();
		$('#containerVideoGallery').load(infoPageName+'Videos.html #labels', function(){
				$('#watchTheVideo').load(infoPageName+'Videos.html #video01');
				$('.smallVideoGallery').click(function(){						   
						var id = $(this).attr('id');
						id = id.substring(17,19);
						$('#watchTheVideo').load('videos.html #video'+id);	
						return false;					   
				});
				var moveContainer = 0;
				var countVideos = -($('.smallVideoGallery').length)*132;
				$('#nextVideo').click(function(){					
											   
					
					if (moveContainer > (countVideos + 1050))
					{
						moveContainer = moveContainer - 380;
						$('#containerVideoGallery').animate({marginLeft: moveContainer+'px'}, 'slow');
					}
					return false;
					
				});
				
				$('#prevVideo').click(function(){					
											 
					if (moveContainer < 0)
					{
						moveContainer = moveContainer + 380;
						$('#containerVideoGallery').animate({marginLeft: moveContainer+'px'}, 'slow');
					}
					
					return false;
				});		
		});
	}
	
	
	/* +-+ +-+--+-+-+-+ CHANGE BACKGROUND COLOR +-+-+-+-+-+ */
	var infoColour = $('#infoColour').text();
	$('.descriptioninfo').css('background', 'url(/medias//footer/'+infoColour+'Top.jpg) no-repeat');
	$('.descriptioninfo').css('background', 'url(/medias//footer/'+infoColour+'.jpg) repeat-x');




	var infoColour2 = $('#infoColour2').text();
	$('.bannerbottom').css('background', 'url(/medias//footer/'+infoColour2+'Top.jpg) no-repeat');
	$('.bannerbottom').css('background', 'url(/medias//footer/'+infoColour2+'.jpg) repeat-x');	
	

	
});
