$(function(){
	var callAjax = function(){
		$(".ajax").removeClass('actif');
		$(this).addClass('actif');
		var href = $(this).attr("href");
		var id_article = href.match(/id_article=[\d+-?]+/);
		$.ajax({
			url: "",
			data: "page=ajax_album&"+id_article,
			async: false,
			success: function (html){
				$("#album").html(html);
			}
		});
		return false;
	}
	$(".ajax").bind("click", callAjax);
	
	var callAjaxMedia = function(){
		if ($(this).find("img.player")){
			var couleur=(($(this).hasClass("rouge"))?"rouge":"bleu");
			if($(this).find("img.player").hasClass("play")){
				$(this).find("img.player").removeClass("play");
				$(this).find("img.player").attr("src", "squelettes/images/play-"+couleur+".gif");
				$("#media").empty();
				$("#media").hide();
				return false;
			}
			else {
				var couleurPlay = (($("img.play").parent().hasClass("rouge"))?"rouge":"bleu");
				$("img.play").attr("src", "squelettes/images/play-"+couleurPlay+".gif");
				$("img.player").removeClass("play");
				$(this).find("img.player").addClass("play");
				$(this).find("img.player").attr("src", "squelettes/images/stop-"+couleur+".gif");
				$("#media").show();
			}
		}
		$(".ajaxmedia").parent().removeClass('actif');
		$(this).parent().addClass('actif');
		var href = $(this).attr("href");
		var id_document = href.match(/id_document=[\d+-?]+/);
		$.ajax({
			url: "",
			data: "page=ajax_media&"+id_document,
			dataType: "html",
			async: false,
			success: function (html){
				$("#media").html(html);	
			}
		});
		return false;
	}
	$(".ajaxmedia").bind("click", callAjaxMedia);
	
	var scrollup = function(){
		var scroll = $(this).parent().find(".scroll");
		var div = scroll.find(".scrolldiv");
		div.stop(true, true);
		var height = scroll.innerHeight();
		var innerheight = div.outerHeight(true);
		var top = parseInt(div.css("top"));
		if (height - top >= innerheight){ 
			div.animate({top:"-=50px"},300).animate({top:"+=50px"},300);
		}
		else
			div.animate({top:"-="+(height-20)+"px"},500);
	};
	
	var scrolldown = function(){
		var scroll = $(this).parent().find(".scroll");
		var div = scroll.find(".scrolldiv");
		div.stop(true, true);
		var height = scroll.outerHeight();
		var top = parseInt(div.css("top"));
		if (top >= 0)
			div.animate({top:"+=50px"},300).animate({top :"-=50px"},300);
		else
			div.animate({top:"+="+(height-20)+"px"},500);
	};
	
	$(".scrollup").bind("click", scrollup);
	$(".scrolldown").bind("click", scrolldown);
			
});

function createMP3Player(player, container, mp3, compteur){
    if (swfobject.hasFlashPlayerVersion("6.0.0")) {
      var fn = function() {
      	var color = ((compteur%2==0)?'bf3d3d':'64587a');
        var att = { data:player, width:"20", height:"20",
    				id: container,
      				name: container,
      				style: "vertical-align: middle;" };
        var par = { flashvars:"song_url="+mp3+"&b_bgcolor=dace9a&b_fgcolor=dace9a&b_colors="+color+","+color+","+color+",000000",
        			allowscriptaccess: "always",
      				quality: "high",
      				wmode: "transparent",
      				bgcolor: "#dace9a"};
        var id = container;
        var myObject = swfobject.createSWF(att, par, id);
      };
      swfobject.addDomLoadEvent(fn);
    }
};

function createFLVPlayer(player, container, flv, extension, autostart){
    if (swfobject.hasFlashPlayerVersion("6.0.0")) {
      var fn = function() {
      	
        var att = { data:player, width:"423", height:"317",
    				id: "movie",
      				name: "movie" };
  		var par;
  		if (extension == 'flv'){
        	par = { flashvars:"file="+flv+"&usefullscreen=false&javascriptid=movie&enablejs=true&autostart="+autostart+"&controlbar=over",
        			allowscriptaccess: "always" };
		} else {
			par = { flashvars:"file="+flv+"&usefullscreen=false&javascriptid=movie&enablejs=true&autostart=true&icons=false&controlbar=none",
        			allowscriptaccess: "always" };
		}
        var id = container;
        var myObject = swfobject.createSWF(att, par, id);
      };
      swfobject.addDomLoadEvent(fn);
    }
};
      
function showMois(id){
	$(function(){
		$("#"+id).show();
	});
};
    
function hideMois(id){
	$(function(){
		$("#"+id).hide();
	});
};
