﻿//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//																	  //
// Javascript functions for Tilix.net								  //
// Copyright 2010 - Tilix											  //
//																	  //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

var currentPage = 1;

function prevPage() {

	changePage(currentPage-1);

}

function nextPage() {
	
	changePage(currentPage+1);
	
}

function changePage(n) {
	
	currentPage = n;
	
	for (i = 0; i < 12; i++) {
		$('.frame-mini:eq('+i+')').fadeOut(100);
	}
	
	$('.arrowLeft').fadeOut(100);
	$('.arrowRight').fadeOut(100);
	
	setTimeout(function() {
		$.ajax({
			type: 'POST',
			data: 'p='+currentPage,
			url: 'libs/realisations.php',
			error: function() {
			   	alert("Erreur de récupération");
			},
			success: function(r) {
				  		
				eval("var jsonreturn="+r); 
				if (jsonreturn.error) {
					alert("Erreur de récupération");
					currentPage--;
				} else {					
					for (i = 0; i < jsonreturn.length; i++) {
						$('.frame-mini:eq('+i+') a').attr('id', 'id'+jsonreturn[i].id);
						$('.frame-mini:eq('+i+') img').attr('src','http://www.tilix.net/pixostudio.fr/'+jsonreturn[i].thumb)	
												 	.attr('alt',jsonreturn[i].label)
													.attr('title',jsonreturn[i].label)
						$('.frame-mini:eq('+i+')').fadeIn(200);
					}
					
					if (jsonreturn.length == 12) {
						$('.arrowRight').fadeIn(100);
					}
					if (currentPage > 1) {
						$('.arrowLeft').fadeIn(100);
					}
				}
				
			}
		});
	}, 110);
}

//============================================================
//Start	
$(function() {
	
	if ( $('.val') ) {
		$('.val:eq(0)').animate({ width: '80%' }, 1600);
		$('.val:eq(1)').animate({ width: '70%' }, 1400);
		$('.val:eq(2)').animate({ width: '80%' }, 1600);
		
		$('.val:eq(3)').animate({ width: '50%' }, 800);
		$('.val:eq(4)').animate({ width: '65%' }, 1300);
		$('.val:eq(5)').animate({ width: '40%' }, 1000);
		
		
		$('.val:eq(6)').animate({ width: '80%' }, 1600);
		$('.val:eq(7)').animate({ width: '40%' }, 800);
		$('.val:eq(8)').animate({ width: '62%' }, 1240);
		
		$('.val:eq(9)').animate({ width: '80%' }, 1600);
		$('.val:eq(10)').animate({ width: '55%' }, 1100);
		$('.val:eq(11)').animate({ width: '40%' }, 800);
		
		
		$('.val:eq(12)').animate({ width: '85%' }, 1700);
		$('.val:eq(13)').animate({ width: '90%' }, 1800);
		$('.val:eq(14)').animate({ width: '50%' }, 1000);
		$('.val:eq(15)').animate({ width: '25%' }, 500);
		$('.val:eq(16)').animate({ width: '60%' }, 1200);
		
		$('.val:eq(17)').animate({ width: '65%' }, 1300);
		$('.val:eq(18)').animate({ width: '15%' }, 300);
		$('.val:eq(19)').animate({ width: '75%' }, 1500);
		$('.val:eq(20)').animate({ width: '60%' }, 1200);
		$('.val:eq(21)').animate({ width: '45%' }, 900);

		
		$('.val:eq(22)').animate({ width: '55%' }, 1100);
		$('.val:eq(23)').animate({ width: '30%' }, 600);
		
	}
	
	if ($('.ref')) {
		$('.ref .frame a').lightBox();
	}
	
	$('.changeRef').click(function() { 
	
		$('h3 #title').hide();
		$('.frame').hide();
		$('#description').hide();
		$('.realisations').hide();
		$('.loader.up').show();
		$('#url').hide();
		
		$.ajax({
			type: 'POST',
			data: 'id='+$(this).attr('id'),
			url: 'libs/realisations.php',
			error: function() {
			   	alert("Erreur de récupération");
			},
			success: function(r) {
				  		
				eval("var jsonreturn="+r); 
				if (jsonreturn.error) {
					alert("Erreur de récupération");
				} else {
			   		$('#title').text(jsonreturn.label);	
					$('.frame a').attr('href','http://www.tilix.net/pixostudio.fr/'+jsonreturn.picture);	
					$('#picture').attr('src','http://www.tilix.net/pixostudio.fr/'+jsonreturn.thumb)	
								 .attr('alt',jsonreturn.label)
								 .attr('title',jsonreturn.label);
					$('#description').html(jsonreturn.description + ' <br />');
					$('#realisations').html(jsonreturn.realizations);
					if (jsonreturn.url) {
						var urlShow;
						if (jsonreturn.url.length > 30) { 
							urlShow = jsonreturn.url.substr(0,25) + "[...]" + jsonreturn.url.substr(jsonreturn.url.length-4, 4);
						} else {
							urlShow = jsonreturn.url;
						}
						$('#url').html('<a href=" '+ jsonreturn.url + '" target="_blank"> ' + urlShow + '</a>');	
					}		
					else {
						$('#url').html('');	
					}    	
				}
				
				$('.loader').hide();
				$('h3 #title').fadeIn(500);
				$('.frame').show(500);
				setTimeout(function() {
					$('#description').fadeIn(500);
					$('#url').show('slide', 500);
					setTimeout(function() {
						$('.realisations').show('slide', 500);
					} ,500);
				}, 500)
				
			}
		});
	});
		
	$('.arrowLeft').click(function() { 
		prevPage();
	});
	$('.arrowRight').click(function() { 
		nextPage();
	});
		
	
	
	$('#contactForm').submit(function(){
			
		$.ajax({
			type: $(this).attr('method'),
			data: $(this).serialize(),
			url: $(this).attr('action'),
			error: function() {
			   	alert("Erreur d'envoi du formulaire");
			},
			success: function(r) {
				  		
				eval("var jsonreturn="+r); 
				if (jsonreturn.error == "true")
				{
					$('#nothing').addClass('error');
					$('#nothing').text("Tous les champs n'ont pas été remplis correctement.");	
					$('#nothing').show('blind', 'slow');
					setTimeout("$('#nothing').hide('blind', 'slow');",3000);			    	
				}
				else
				{
					$('#nothing').addClass('ok');
					$('#nothing').html("<div class='msgbox success'>Votre message &agrave; bien été envoyé.</div>");
					$('#nothing').show('blind', 'slow');
					setTimeout("$('#nothing').hide('blind', 'slow');",3000);
				}
			}
		});
		return false;
	});	
	
});


