$(function() {
	$('a[rel=contenu_ppbox\[galerie\]]').prettyPhoto();
	//zebre('.tableau_zebre','zebre_vert'); //@#$ IE
	/* Facelift
	FLIR.init({path: URL_CHARTE_COMMUN + 'composant/facelift/'});
	$('h2').each( function() { FLIR.replace(this, new FLIRStyle({ cFont:'wanta' , mode:'wrap' })); });
	*/

	// GEOLOC V3
	if( $('div.jsGeolocalisation').size()) {
		$insertScript( URL_CHARTE_COMMUN + 'composant/geolocalisation/geolocalisation_f.js');

		if( typeof google == 'undefined') {
			$insertScript( 'http://maps.google.com/maps/api/js?sensor=false&language=' + LANGUE_META_SITE + '&callback=geolocv3_init');
		} else {
			return geolocv3_init();
		}
	}

	vote();

	// Commentaire
	$('a.commentaire_repondre').live('click', function() {
		var oCont = $( this.href.replace(/.*?_(.*_\d+)$/, '#commentaire_contenu_$1')),
			sVal = oCont.val();

		oCont.val( sVal + ( sVal ? '\n' : '') + '@' + $(this).attr('title') + ' : ').focus();
		return false;
	});
	$('a.jsCommentaireSup').live('click', function() {
		if( test_ident()) {
			var oCont = $(this).closest('li');
			oCont.empty().contenuAjax({
				url: this.href + '_ajax',
				place: null,
				loadclass: 'ajaxloading_medium',
				success_callback: function(data) {
					if( data == 'erreur') {
						alert( constante('ajaxError'));
					} else {
						oCont.remove();
					}
				}
			});
		}
		return false;
	});

	// Favoris
	$('a.jsFavori').click( function() {
		if( test_ident()) {
			var oLien = this, oConteneur = $(this).parent();

			oConteneur.empty().css({'padding-left':24}).contenuAjax({
				url: oLien.href + '_ajax',
				timeout: 150000,
				place: null,
				success_callback: function( data) {
					if( data == 'erreur') {
						alert( constante('ajaxError'));
					} else {
						$('#favori_encart').html( data);
						oConteneur.css({'padding-left':''}).text( _lg('En favoris'));
					}
				}
			});
		}
		return false;
	});

	// Textarea
	$('textarea.jsAutoGrow').autogrow();
});

/*** FAVORIS ***/
function ajax_favori_supprimer( oLien) {
	if( test_ident()) {
		$('#favori_encart').empty().contenuAjax({
			url: oLien.href + '_ajax',
			loadclass: 'ajaxloading_medium'
		});
	}
}

/*** COMMENTAIRE ***/
function commentaire_submit( form, bIdent) {
	bIdent = bIdent ? test_ident() : true;
	if( bIdent) {
		$.ajax({
			url: $(form).attr('action') + '_ajax',
			type: 'post',
			data: $(form).serialize(),
			dataType: 'xml',
			error: function(event, request, settings) {
				alert( constante('ajaxError'));
			},
			success: function(xml) {
				if( $(xml).size()) { // moyen à revoir
					var sIdBloc = form.id.replace('frmCommentaire', '#commentaire_bloc');
					$(xml).find('Commentaire > com').each( function() {
						if( ! $(sIdBloc + ':has(ul)').size()) {
							$(sIdBloc).append('<ul>');
						}
						$(sIdBloc + ' > ul').append( $(this).text());
					}).end().find('form').each( function() {
						$(sIdBloc.replace('_bloc', '-poster')).html( $(this).text());
					});
				} else {
					alert( constante('ajaxError'));
				}
			},
			complete: function() {
				disableForm.hide();
			}
		});
	}
}

/*** VOTE ***/
// util si ajax par ex pour éviter de dupliquer les events : sSelecteur = #id
function vote( sSelecteur) {
	sSelecteur = $defined( sSelecteur) ? sSelecteur + ' ' : '';
	$(sSelecteur + 'form input:radio.star').rating({
		focus: function(value, link){
			if( ! this.disabled) {
				var tip = $('#help_' + this.id.replace(/(_\d+)$/, ''));
				tip[0].data = tip[0].data || tip.html();
				tip.html(link.title || value);
			}
		},
		blur: function(value, link){
			if( ! this.disabled) {
				var tip = $('#help_' + this.id.replace(/(_\d+)$/, ''));
				tip.html(tip[0].data || '');
			}
		},
		required: true,
		callback: function(value, link) {
			var jqForm = $(this.form),
				sData = jqForm.serialize();

			if( $(jqForm).find('input:hidden[name=type]').val() != '1' ? test_ident() : true) {
				$(this).rating('disable');
				$.ajax({
					url: jqForm.attr('action') + '_ajax',
					type: 'post',
					data: sData,
					timeout: 10000,
					error: function( event, request, settings) { alert( constante( 'ajaxError'));},
					beforeSend: function() {
						$(jqForm).find('span.vote_help').empty().addClass('ajaxloading_small ajax_star_rating');
					},
					success: function( data) {
						jqForm.replaceWith( data);
						vote_resultat();
					},
					complete: function() {
						$(jqForm).find('span.vote_help').removeClass('ajaxloading_small ajax_star_rating');
					}
				});
			}
		}
	});

	$('.jsVoteBooleen input:radio, .jsVoteBooleen input:submit').hide();
	$('.jsVoteBooleen label').click(function(){
		if( test_ident()) {
			$id($(this).attr('for')).checked = true;
			var jqForm = $(this).parent('div').parent('form');
				sData = jqForm.serialize();
			$(this).parent('div').parent('form').parent('div').empty().width(32).contenuAjax({
				url: jqForm.attr('action') + '_ajax',
				type: 'post',
				data: sData,
				place: 'replaceWith'
			});
		}
		return false;
	});

	$('a.jsVoteRsSubmit').live('click', function() {
		if( test_ident()) {
			$(this).parent('div').empty().width(32).contenuAjax({
				url: $(this).attr('href') + '_ajax',
				place: 'replaceWith',
				loadclass: 'ajaxloading_small'
			});
		}
		return false;
	});

	vote_resultat( sSelecteur);
}

function vote_resultat( sSelecteur) {
	sSelecteur = $defined( sSelecteur) ? sSelecteur + ' ' : '';
	$(sSelecteur + 'div.vote_rating').each( function() {
		if( ! $(this).data('rating')) {
			$(this).hover( function() {
				$(this).children('span.vote_help:first').hide().next('span.vote_help').show();
			}, function() {
				$(this).children('span.vote_help:first').show().next('span.vote_help').hide();
			}).data('rating', true);
		}
	});
}

/*
* jQuery Tools 1.2.3 - The missing UI library for the Web
*
* [tabs, tabs.slideshow, scrollable, scrollable.autoscroll, scrollable.navigator]
*
* NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
*
* http://flowplayer.org/tools/
*
* File generated: Sat Jun 12 11:58:14 GMT 2010
*/
(function(c){function p(e,b,a){var d=this,l=e.add(this),h=e.find(a.tabs),i=b.jquery?b:e.children(b),j;h.length||(h=e.children());i.length||(i=e.parent().find(b));i.length||(i=c(b));c.extend(this,{click:function(f,g){var k=h.eq(f);if(typeof f=="string"&&f.replace("#","")){k=h.filter("[href*="+f.replace("#","")+"]");f=Math.max(h.index(k),0)}if(a.rotate){var n=h.length-1;if(f<0)return d.click(n,g);if(f>n)return d.click(0,g)}if(!k.length){if(j>=0)return d;f=a.initialIndex;k=h.eq(f)}if(f===j)return d;
g=g||c.Event();g.type="onBeforeClick";l.trigger(g,[f]);if(!g.isDefaultPrevented()){o[a.effect].call(d,f,function(){g.type="onClick";l.trigger(g,[f])});j=f;h.removeClass(a.current);k.addClass(a.current);return d}},getConf:function(){return a},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return d.click(j+1)},prev:function(){return d.click(j-1)},destroy:function(){h.unbind(a.event).removeClass(a.current);
i.find("a[href^=#]").unbind("click.T");return d}});c.each("onBeforeClick,onClick".split(","),function(f,g){c.isFunction(a[g])&&c(d).bind(g,a[g]);d[g]=function(k){c(d).bind(g,k);return d}});if(a.history&&c.fn.history){c.tools.history.init(h);a.event="history"}h.each(function(f){c(this).bind(a.event,function(g){d.click(f,g);return g.preventDefault()})});i.find("a[href^=#]").bind("click.T",function(f){d.click(c(this).attr("href"),f)});if(location.hash)d.click(location.hash);else if(a.initialIndex===
0||a.initialIndex>0)d.click(a.initialIndex)}c.tools=c.tools||{version:"1.2.3"};c.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:false,history:false},addEffect:function(e,b){o[e]=b}};var o={"default":function(e,b){this.getPanes().hide().eq(e).show();b.call()},fade:function(e,b){var a=this.getConf(),d=a.fadeOutSpeed,l=this.getPanes();d?l.fadeOut(d):l.hide();l.eq(e).fadeIn(a.fadeInSpeed,b)},slide:function(e,b){this.getPanes().slideUp(200);
this.getPanes().eq(e).slideDown(400,b)},ajax:function(e,b){this.getPanes().eq(0).load(this.getTabs().eq(e).attr("href"),b)}},m;c.tools.tabs.addEffect("horizontal",function(e,b){m||(m=this.getPanes().eq(0).width());this.getCurrentPane().animate({width:0},function(){c(this).hide()});this.getPanes().eq(e).animate({width:m},function(){c(this).show();b.call()})});c.fn.tabs=function(e,b){var a=this.data("tabs");if(a){a.destroy();this.removeData("tabs")}if(c.isFunction(b))b={onBeforeClick:b};b=c.extend({},
c.tools.tabs.conf,b);this.each(function(){a=new p(c(this),e,b);c(this).data("tabs",a)});return b.api?a:this}})(jQuery);
(function(d){function r(g,a){function p(f){var e=d(f);return e.length<2?e:g.parent().find(f)}var c=this,j=g.add(this),b=g.data("tabs"),h,l,m,n=false,o=p(a.next).click(function(){b.next()}),k=p(a.prev).click(function(){b.prev()});d.extend(c,{getTabs:function(){return b},getConf:function(){return a},play:function(){if(!h){var f=d.Event("onBeforePlay");j.trigger(f);if(f.isDefaultPrevented())return c;n=false;h=setInterval(b.next,a.interval);j.trigger("onPlay");b.next()}},pause:function(){if(!h)return c;
var f=d.Event("onBeforePause");j.trigger(f);if(f.isDefaultPrevented())return c;h=clearInterval(h);m=clearInterval(m);j.trigger("onPause")},stop:function(){c.pause();n=true}});d.each("onBeforePlay,onPlay,onBeforePause,onPause".split(","),function(f,e){d.isFunction(a[e])&&c.bind(e,a[e]);c[e]=function(s){return c.bind(e,s)}});if(a.autopause){var t=b.getTabs().add(o).add(k).add(b.getPanes());t.hover(function(){c.pause();l=clearInterval(l)},function(){n||(l=setTimeout(c.play,a.interval))})}if(a.autoplay)m=
setTimeout(c.play,a.interval);else c.stop();a.clickable&&b.getPanes().click(function(){b.next()});if(!b.getConf().rotate){var i=a.disabledClass;b.getIndex()||k.addClass(i);b.onBeforeClick(function(f,e){if(e){k.removeClass(i);e==b.getTabs().length-1?o.addClass(i):o.removeClass(i)}else k.addClass(i)})}}var q;q=d.tools.tabs.slideshow={conf:{next:".forward",prev:".backward",disabledClass:"disabled",autoplay:false,autopause:true,interval:3E3,clickable:true,api:false}};d.fn.slideshow=function(g){var a=
this.data("slideshow");if(a)return a;g=d.extend({},q.conf,g);this.each(function(){a=new r(d(this),g);d(this).data("slideshow",a)});return g.api?a:this}})(jQuery);
(function(e){function n(f,c){var a=e(c);return a.length<2?a:f.parent().find(c)}function t(f,c){var a=this,l=f.add(a),g=f.children(),k=0,m=c.vertical;j||(j=a);if(g.length>1)g=e(c.items,f);e.extend(a,{getConf:function(){return c},getIndex:function(){return k},getSize:function(){return a.getItems().size()},getNaviButtons:function(){return o.add(p)},getRoot:function(){return f},getItemWrap:function(){return g},getItems:function(){return g.children(c.item).not("."+c.clonedClass)},move:function(b,d){return a.seekTo(k+
b,d)},next:function(b){return a.move(1,b)},prev:function(b){return a.move(-1,b)},begin:function(b){return a.seekTo(0,b)},end:function(b){return a.seekTo(a.getSize()-1,b)},focus:function(){return j=a},addItem:function(b){b=e(b);if(c.circular){e(".cloned:last").before(b);e(".cloned:first").replaceWith(b.clone().addClass(c.clonedClass))}else g.append(b);l.trigger("onAddItem",[b]);return a},seekTo:function(b,d,h){if(c.circular&&b===0&&k==-1&&d!==0)return a;if(!c.circular&&b<0||b>a.getSize()||b<-1)return a;
var i=b;if(b.jquery)b=a.getItems().index(b);else i=a.getItems().eq(b);var q=e.Event("onBeforeSeek");if(!h){l.trigger(q,[b,d]);if(q.isDefaultPrevented()||!i.length)return a}i=m?{top:-i.position().top}:{left:-i.position().left};k=b;j=a;if(d===undefined)d=c.speed;g.animate(i,d,c.easing,h||function(){l.trigger("onSeek",[b])});return a}});e.each(["onBeforeSeek","onSeek","onAddItem"],function(b,d){e.isFunction(c[d])&&e(a).bind(d,c[d]);a[d]=function(h){e(a).bind(d,h);return a}});if(c.circular){var r=a.getItems().slice(-1).clone().prependTo(g),
s=a.getItems().eq(1).clone().appendTo(g);r.add(s).addClass(c.clonedClass);a.onBeforeSeek(function(b,d,h){if(!b.isDefaultPrevented())if(d==-1){a.seekTo(r,h,function(){a.end(0)});return b.preventDefault()}else d==a.getSize()&&a.seekTo(s,h,function(){a.begin(0)})});a.seekTo(0,0)}var o=n(f,c.prev).click(function(){a.prev()}),p=n(f,c.next).click(function(){a.next()});!c.circular&&a.getSize()>1&&a.onBeforeSeek(function(b,d){setTimeout(function(){if(!b.isDefaultPrevented()){o.toggleClass(c.disabledClass,
d<=0);p.toggleClass(c.disabledClass,d>=a.getSize()-1)}},1)});c.mousewheel&&e.fn.mousewheel&&f.mousewheel(function(b,d){if(c.mousewheel){a.move(d<0?1:-1,c.wheelSpeed||50);return false}});c.keyboard&&e(document).bind("keydown.scrollable",function(b){if(!(!c.keyboard||b.altKey||b.ctrlKey||e(b.target).is(":input")))if(!(c.keyboard!="static"&&j!=a)){var d=b.keyCode;if(m&&(d==38||d==40)){a.move(d==38?-1:1);return b.preventDefault()}if(!m&&(d==37||d==39)){a.move(d==37?-1:1);return b.preventDefault()}}});
e(a).trigger("onBeforeSeek",[c.initialIndex])}e.tools=e.tools||{version:"1.2.3"};e.tools.scrollable={conf:{activeClass:"active",circular:false,clonedClass:"cloned",disabledClass:"disabled",easing:"swing",initialIndex:0,item:null,items:".items",keyboard:true,mousewheel:false,next:".next",prev:".prev",speed:400,vertical:false,wheelSpeed:0}};var j;e.fn.scrollable=function(f){var c=this.data("scrollable");if(c)return c;f=e.extend({},e.tools.scrollable.conf,f);this.each(function(){c=new t(e(this),f);e(this).data("scrollable",
c)});return f.api?c:this}})(jQuery);
(function(c){var g=c.tools.scrollable;g.autoscroll={conf:{autoplay:true,interval:3E3,autopause:true}};c.fn.autoscroll=function(d){if(typeof d=="number")d={interval:d};var b=c.extend({},g.autoscroll.conf,d),h;this.each(function(){var a=c(this).data("scrollable");if(a)h=a;var e,i,f=true;a.play=function(){if(!e){f=false;e=setInterval(function(){a.next()},b.interval);a.next()}};a.pause=function(){e=clearInterval(e)};a.stop=function(){a.pause();f=true};b.autopause&&a.getRoot().add(a.getNaviButtons()).hover(function(){a.pause();
clearInterval(i)},function(){f||(i=setTimeout(a.play,b.interval))});b.autoplay&&setTimeout(a.play,b.interval)});return b.api?h:this}})(jQuery);
(function(d){function p(c,g){var h=d(g);return h.length<2?h:c.parent().find(g)}var m=d.tools.scrollable;m.navigator={conf:{navi:".navi",naviItem:null,activeClass:"active",indexed:false,idPrefix:null,history:false}};d.fn.navigator=function(c){if(typeof c=="string")c={navi:c};c=d.extend({},m.navigator.conf,c);var g;this.each(function(){function h(a,b,i){e.seekTo(b);if(j){if(location.hash)location.hash=a.attr("href").replace("#","")}else return i.preventDefault()}function f(){return k.find(c.naviItem||
"> *")}function n(a){var b=d("<"+(c.naviItem||"a")+"/>").click(function(i){h(d(this),a,i)}).attr("href","#"+a);a===0&&b.addClass(l);c.indexed&&b.text(a+1);c.idPrefix&&b.attr("id",c.idPrefix+a);return b.appendTo(k)}function o(a,b){a=f().eq(b.replace("#",""));a.length||(a=f().filter("[href="+b+"]"));a.click()}var e=d(this).data("scrollable"),k=p(e.getRoot(),c.navi),q=e.getNaviButtons(),l=c.activeClass,j=c.history&&d.fn.history;if(e)g=e;e.getNaviButtons=function(){return q.add(k)};f().length?f().each(function(a){d(this).click(function(b){h(d(this),
a,b)})}):d.each(e.getItems(),function(a){n(a)});e.onBeforeSeek(function(a,b){setTimeout(function(){if(!a.isDefaultPrevented()){var i=f().eq(b);!a.isDefaultPrevented()&&i.length&&f().removeClass(l).eq(b).addClass(l)}},1)});e.onAddItem(function(a,b){b=n(e.getItems().index(b));j&&b.history(o)});j&&f().history(o)});return c.api?g:this}})(jQuery);
