var puces = new Class({
    initialize: function(){
		var item = $$(".puces-content")[0];
		if(item)
		{
			var a = item.getStyle('height').toInt();
			var b = item.getFirst().getStyle('height').toInt();
			if(b > a)
			{
				var scroll = new Fx.Scroll(item, {
					wait: false,
					duration: 800,
					transition: Fx.Transitions.Quad.easeInOut
				});
				var p = new Element("p", {
					"class":"puces"
				});
				for(i=0; i < (b/a); i++)
				{
					var anchor = new Element("a");
					anchor.setProperty("rel",i);
					anchor.addEvent("click", function(event){
						event = new Event(event).stop();
						var y = this.getProperty("rel").toInt()*a;
						scroll.scrollTo(0, y);
						$ES(".puces a", item.getParent()).each(function(item, index){
							item.removeClass("current");
						});
						this.addClass("current");
					});
					if(i==0) anchor.addClass("current");
					anchor.setText(i+1);
					anchor.injectInside(p);
				}
				p.injectInside(item.getParent());
			}
		}
    }
});
var load_method = (window.ie ? 'load' : 'domready'); // ie fix
window.addEvent(load_method,function(){
	var p = new puces();
	if($chk($("homepage")))
	{
		$$("#homepage .latest-news .entry").each(function(item, index){
			item.addEvent("mouseover", function(){
				this.addClass("hover");
			});
			item.addEvent("mouseout", function(){
				this.removeClass("hover");
			});
		});
	}
	if($chk($("medias")) && $$("#medias .videos a").length > 0)
	{
		// Recuperation du lien des videos
		var firstVideoHref = $$("#medias .videos a")[0].href;
		var firstVideoId =  firstVideoHref.substr(firstVideoHref.indexOf("v=",0)+2);
		
		// Insertion du flash
		var so = new SWFObject("http://www.youtube.com/v/"+firstVideoId+"&hl=en&rel=0", "mediaSWF", "425", "344", "8", "#ffffff");
		so.addParam("wmode","opaque");
		so.write("media");
		
		$$("#medias .videos a").each(function(item, index){
			item.href = "#" + item.href.substr(item.href.indexOf("v=",0));
			item.video = item.href.substr(item.href.indexOf("v=",0)+2);
			item.addEvent("click", function(){
				var id = this.video; 
				so = new SWFObject("http://www.youtube.com/v/"+id+"&hl=en&rel=0", "mediaSWF", "425", "344", "8", "#ffffff");
				so.addParam("wmode","opaque");
				so.write("media");
			});
		});
	}
});
