$(document).ready(function() {
	
	var url = window.location.href.split("/").pop();
	
	//$('#logo').rotate(180);
	
	var runing = false;
	$('.itemTitle').click(function() {
		if(runing == false) {
			runing = true;
			var tab = $(this);
			$('.itemPage').fadeOut('slow');
			$('.itemTitle').removeClass('active');
			$('#'+tab.find('span').attr('class')).fadeIn(1000);
			$('#menuSelector').animate({
				top: eval(tab.attr('id').split('position-')[1] * 36 + 14) +'px'
			}, 1000, function() {
				tab.addClass('active');
				runing = false;
			});
		}
	});
	
/************************************************************************/
/**    MENU    **********************************************************/
/************************************************************************/	

	
/************************************************************************/
/**    ACCUEIL    *******************************************************/
/************************************************************************/
	 
	var flashvars = {};
	flashvars.cssSource = "/idoine/app/webroot/js/swfobject/piecemaker.css";
	flashvars.xmlSource = "/idoine/app/webroot/js/swfobject/piecemaker.xml";
  
	var params = {};
	params.play = "true";
	params.menu = "false";
	params.scale = "showall";
	params.wmode = "transparent";
	params.allowfullscreen = "true";
	params.allowscriptaccess = "always";
	params.allownetworking = "all";
  
	swfobject.embedSWF('/idoine/app/webroot/js/swfobject/piecemaker.swf', 'piecemaker', '900', '380', '10', null, flashvars, params, null);
	
/************************************************************************/
/**    PROJECTS    ******************************************************/
/************************************************************************/
	$("a[rel=colorbox1]").colorbox({photo:true,width:'670',maxWidth:'90%',maxHeight:'90%'});
	$("a[rel=colorbox2]").colorbox({photo:true,width:'670',maxWidth:'90%',maxHeight:'90%'});
	$("a[rel=colorbox3]").colorbox({photo:true,width:'670',maxWidth:'90%',maxHeight:'90%'});
	$("a[rel=colorbox4]").colorbox({photo:true,width:'670',maxWidth:'90%',maxHeight:'90%'});
	$("a[rel=colorbox5]").colorbox({photo:true,width:'670',maxWidth:'90%',maxHeight:'90%'});
	
/************************************************************************/
/**    REFERENCES    ****************************************************/
/************************************************************************/
	var runing = false;
	
	$('#rightNavClient, .nextClient').live("click", function() {
		if(runing == false && $('.currentClient.last').size() == 0) {
			runing = true;
			$('#clientSlideItems').animate({
				left: '-=275px'
			}, 600, function() {
				runing = false;
			});
			$('.currentClient').animate({
				marginTop: '+=33px',
				height : '-=30px',
				width : '-=50px',
				borderTopWidth : '1px',
				borderBottomWidth : '1px'
			}, 600, function() {
				$(this).removeClass('currentClient');
				$('.client').removeClass('previousClient');
				$(this).addClass('previousClient');
			});
			$('.nextClient').animate({
				marginTop: '-=33px',
				height : '+=30px',
				width : '+=50px'
			}, 600, function() {
				$(this).removeClass('nextClient');
				$(this).addClass('currentClient');
				$(this).parent().next().find('.client').addClass('nextClient');
			});
			var newId = $('.nextClient').attr('title');
			$('.descriptionBox:not(#'+newId+')').animate({
				opacity: '0'
			}, 600, function() {
			});
			$('#'+newId).animate({
				opacity: '1'
			}, 600, function() {
			});
		}
	});
	
	$('#leftNavClient, .previousClient').live("click", function() {
		if(runing == false && $('.currentClient.first').size() == 0) {
			runing = true;
			$('#clientSlideItems').animate({
				left: '+=275px'
			}, 600, function() {
				runing = false;
			});
			$('.currentClient').animate({
				marginTop: '+=33px',
				height : '-=30px',
				width : '-=50px',
				borderTopWidth : '1px',
				borderBottomWidth : '1px'
			}, 600, function() {
				$(this).removeClass('currentClient');
				$('.client').removeClass('nextClient');
				$(this).addClass('nextClient');
			});
			$('.previousClient').animate({
				marginTop: '-=33px',
				height : '+=30px',
				width : '+=50px',
				borderTopWidth : '2px',
				borderBottomWidth : '2px'
			}, 600, function() {
				$(this).removeClass('previousClient');
				$(this).addClass('currentClient');
				$(this).parent().prev().find('.client').addClass('previousClient');
			});
			var newId = $('.previousClient').attr('title');
			$('.descriptionBox:not(#'+newId+')').animate({
				opacity: '0'
			}, 600, function() {
			});
			$('#'+newId).animate({
				opacity: '1'
			}, 600, function() {
			});
		}
	});
});
