/*Petit commentaire pour forcer l'enregistrement en UTF8.*/
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20921062-1']);
_gaq.push(['_trackPageview']);
(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
$(function() {
	carrousel.init($('#carrousel'));
	jBox.init();
	$('#ean').focus();
	$("#jBoxSlideContent").addClass('hide');
	$("#jBoxSlideOn").removeClass('hide');
	$("#jBoxSlideOn a").click(function () {
		$("#jBoxSlideContent").slideDown(250);
		$("#jBoxSlideOn").slideUp(250);
		return false;
	});
	if($('.box_red').html() != null) {
		$("#jBoxSlideContent").slideDown(250);
		$("#jBoxSlideOn").slideUp(250);
	}
	$('#presentation_customers').hide();
	$('#presentation_customers_a').show();
	$('#presentation_customers_a').click(function() {
		$('#presentation_customers_a').hide();
		$('#presentation_customers').slideDown(1000);
		return false;
	});
	$('#presentation_finances').hide();
	$('#presentation_finances_a').show();
	$('#presentation_finances_a').click(function() {
		$('#presentation_finances_a').hide();
		$('#presentation_finances').slideDown(1000);
		return false;
	});
	$('#presentation_internet').hide();
	$('#presentation_internet_a').show();
	$('#presentation_internet_a').click(function() {
		$('#presentation_internet_a').hide();
		$('#presentation_internet').slideDown(1000);
		return false;
	});
	$('#presentation_invoices').hide();
	$('#presentation_invoices_a').show();
	$('#presentation_invoices_a').click(function() {
		$('#presentation_invoices_a').hide();
		$('#presentation_invoices').slideDown(1000);
		return false;
	});
	$('#presentation_products').hide();
	$('#presentation_products_a').show();
	$('#presentation_products_a').click(function() {
		$('#presentation_products_a').hide();
		$('#presentation_products').slideDown(1000);
		return false;
	});
	$('#presentation_statistics').hide();
	$('#presentation_statistics_a').show();
	$('#presentation_statistics_a').click(function() {
		$('#presentation_statistics_a').hide();
		$('#presentation_statistics').slideDown(1000);
		return false;
	});
});
var carrousel = {
	nbSlide : 3,
	nbCurrent : 1,
	elemCurrent : null,
	elem : null,
	timer : null,
	init: function(elem) {
		this.nbSlide = elem.find(".carrousel_slide").length;		
		elem.find('.carrousel_navigation').show();
		elem.find('.carrousel_navigation span').click(function() { carrousel.goToSlide($(this).attr('name')); });
		this.elem = elem;
		elem.find('.carrousel_slide').hide();
		elem.find('.carrousel_slide:first').show();
		this.elemCurrent = elem.find('.carrousel_slide:first');
		this.elem.find('.carrousel_navigation span:first').addClass('active');
		carrousel.play();
		elem.mouseout(carrousel.play);
		elem.mouseover(carrousel.stop);
	},
	goToSlide : function(num) {
		if(num == this.nbCurrent) {
			return false;
		}
		this.elemCurrent.fadeOut(750);
		this.elem.find('#carrousel_slide' + num).fadeIn(750);
		this.elem.find('.carrousel_navigation span').removeClass('active');
		this.elem.find('.carrousel_navigation span:eq('+(num - 1)+')').addClass('active');
		this.nbCurrent = num;
		this.elemCurrent = this.elem.find('#carrousel_slide' + num);
	},
	next : function() {
		var num = this.nbCurrent + 1;
		if(num > this.nbSlide) {
			num = 1;
		}
		this.goToSlide(num);
	},
	prev : function() {
		var num = this.nbCurrent - 1;
		if(num < 1) {
			num = this.nbSlide;
		}
		this.goToSlide(num);
	},
	play : function() {
		window.clearInterval(carrousel.timer);
		carrousel.timer = window.setInterval('carrousel.next()', 4000);
	},
	stop : function() {
		window.clearInterval(carrousel.timer);
	}
}
jBox = {
	init : function() {
		$('a[rel="jBox"]').click(function() {
			jBox.link = $(this).attr('name');
			jBox.open(jBox.link);
			return false;
		});
		$(window).resize(jBox.redim);
	},
	open : function(link) {
		jBox.link = link;
		$('body').append('<div id="jBox"><div id="jBox_aplat"></div><div id="jBox_loader"></div><div id="jBox_container"><div id="jBox_relative"><div id="jBox_close"></div><div id="jBox_contenu"></div></div></div></div>')
		$('#jBox_container').hide();
		$('#jBox_loader').hide().fadeIn();
		$('#jBox_aplat').hide().fadeTo(250, 0.7);
		jBox.img = new Image();
		jBox.img.src = jBox.link;
		jBox.timer = window.setInterval(jBox.load, 250);
		$('#jBox_close').click(jBox.close);
		$('#jBox_aplat').click(jBox.close);
	},
	load : function() {
		if(jBox.img.complete) {
			window.clearInterval(jBox.timer);
			jBox.anim();
		}
	},
	anim : function() {
		if(jBox.link.substr(-4, 4) == '.get') {
			jBox.width = jBox.windowW() - 200;
			jBox.height = jBox.windowH() - 200;
			jBox.redim();
		}
		else {
			jBox.width = jBox.img.width;
			jBox.height = jBox.img.height;
			jBox.redim();
		}
		$('#jBox_container').show();
		$('#jBox_contenu').append('<img src="'+jBox.link+'" />');
		$('#jBox_loader').fadeOut(250);
		$('#jBox_contenu img').hide();
		$('#jBox_contenu').animate({width:jBox.width}, 250).animate({height:jBox.height}, 250, function() {
		$('#jBox_close').fadeIn();
		$('#jBox_contenu img').fadeIn();
		});
	},
	redim : function() {
		$('#jBox_container').css('left', ((jBox.windowW() - jBox.width) / 2) + 'px');
		$('#jBox_container').css('top', (30 + jBox.scrollY() + (jBox.windowH() - jBox.height) / 2) + 'px');
	},
	close : function() {
		$('#jBox').fadeOut(250, function() {
			$('#jBox').remove();
		});
	},
	windowW : function(){
		if (window.innerWidth) return window.innerWidth  ;
		else{return $(window).width();}
	},
	windowH : function(){
		if (window.innerHeight) return window.innerHeight  ;
		else{return $(window).height();}
	},
	scrollY : function() {
		scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			scrOfY = window.pageYOffset;
		} else if( document.body && ( document.body.scrollTop ) ) {
			scrOfY = document.body.scrollTop;
		} else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
			scrOfY = document.documentElement.scrollTop;
		}
		return scrOfY;
	}
};
