function mycarousel_initCallback(carousel){
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(document).ready(function() {
	$('a#demande_partenaire').animate({height: "50"});
	$('a#demande_partenaire').click(function(){
		$(this).toggleClass('tabu');
		$('div#form_partenaire').toggle();
		$('div#les_donnees').toggle();
		$('div.pagination').toggle();
		$('div.pub').toggleClass('marge');
	});
	$('div#form_partenaire').hide();
	$('a#menu_9').addClass('soirees_select');
	$('div.fragment').each($.blocpagination);
	$(".pagination a.lien_pagination").append('<img class="shadow" src="http://www.southindiescrew.com/squelettes/2010/images/icons-shadow.png" width="81" height="27" alt="" />');
	$("span.on").append('<img class="shadow" src="http://www.southindiescrew.com/squelettes/2010/images/icons-shadow.png" width="81" height="27" alt="" />');
	$(".pagination a.lien_pagination span").hover(function() {
		var ey = this;
	    $(ey).stop().animate({ marginTop: "-14px" }, 250, function() {
	    	$(ey).animate({ marginTop: "-10px" }, 250);
	    });
	    $(ey).parent('a').find("img.shadow").stop().animate({ width: "65", height: "20px", marginLeft: "8px" }, 250);
	},function(){
		var ey = this;
	    $(ey).stop().animate({ marginTop: "4px" }, 250, function() {
	    	$(ey).animate({ marginTop: "0px" }, 250);
	    });
	    $(ey).parent('a').find("img.shadow").stop().animate({ width: "81", height: "27px", marginLeft: "0"}, 250);
	});

    jQuery('#mycarousel').jcarousel({
        auto: 5,  
		scroll: 2,
		wrap: 'last',

        initCallback: mycarousel_initCallback
    });
});

$.addFade = function() {
	$('div#form_partenaire').hide();

	$(".pagination a.lien_pagination").append('<img class="shadow" src="http://www.southindiescrew.com/squelettes/2010/images/icons-shadow.png" width="81" height="27" alt="" />');
	$("span.on").append('<img class="shadow" src="http://www.southindiescrew.com/squelettes/2010/images/icons-shadow.png" width="81" height="27" alt="" />');
	$(".pagination a.lien_pagination span").hover(function() {
		var ey = this;
	    $(ey).stop().animate({ marginTop: "-14px" }, 250, function() {
	    	$(ey).animate({ marginTop: "-10px" }, 250);
	    });
	    $(ey).parent('a').find("img.shadow").stop().animate({ width: "65", height: "20px", marginLeft: "8px" }, 250);
	},function(){
		var ey = this;
	    $(ey).stop().animate({ marginTop: "4px" }, 250, function() {
	    	$(ey).animate({ marginTop: "0px" }, 250);
	    });
	    $(ey).parent('a').find("img.shadow").stop().animate({ width: "81", height: "27px", marginLeft: "0"}, 250);
	});
}

$.blocpagination = function() {
		var blocfrag = this;
		$('.pagination',this).each(function(){
			var divpagi=this;
			$('a.lien_pagination',this).each(function(){
				var url = this.href.split('#');
				url[0] += (url[0].indexOf("?")>0 ? '&':'?')+'var_fragment='+blocfrag.id;
				$(this).click(function(){
					var placeholder=$('.searching_placeholder',blocfrag);
					if (placeholder.length) placeholder.prepend('');
					else $('div#annuaire_fond ').empty().append('<div id="load">Chargement Des Liens En Cours, veuillez patienter quelques instants.</div>');
					$(blocfrag).load(url[0],null,function(){
						$.addFade.apply(blocfrag);
						window.location.hash = url[1];
						$.blocpagination.apply(blocfrag);
					});
					
					return false;
				});
			});
		});
};
