Array.prototype.in_array = function(valeur) {
  for (var i in this) { if (this[i] === valeur) return i; }
  return -1;
}
var currentitem = 0;
var currentoffset = 0;
var maxoffset = 0;
var totalitems = 0;
var totalwidth = 0;
var itemwidth = 0
var scrollitems = [];

$(document).ready(function() {
  var path = location.pathname;
	var basepath;
	basepath = path.substr(0, path.lastIndexOf('.'));
	if (path.indexOf('-') > -1) {
		basepath = path.substr(0, path.lastIndexOf('-'));
	}
	while (basepath.lastIndexOf('/') > 1) {
		basepath = basepath.substr(0, basepath.lastIndexOf('/'));
	}
	$('#menu ul li[class!="language"] a').each(function() {
		href = $(this).attr('href');
		if (href.indexOf('.') > -1) {
			basehref = href.substr(0, href.lastIndexOf('.'));
			if (basehref.indexOf('-') > -1) {
				basehref = basehref.substr(0, basehref.lastIndexOf('-'));
			}
			if (basehref == basepath) {
				$(this).parent('li').addClass('active');
			}
		}
	});
	$('#submenu a').each(function() {
		href = $(this).attr('href');
		href = href.substr(0, href.lastIndexOf('.'));
    if (path.substr(0, href.length) == href) {
		  $(this).parent('li').addClass('active');
		}
	});
   var site = String(document.location)
       .replace(/^(https?:\/\/[^:\/]+).*$/, "$1")
       .replace(/^((site)?(file:\/\/.+\/))[^\/]+$/, "$3")
       .replace(/(\\.)/g, "\\$1");
   $("a", this).filter(function (i) {
       var href = $(this).attr("href");
       if (href == null)
           return false;
       return (
              href.match(RegExp("^("+site+"|(https?:)?/[^/])")) == null
           && href.match(RegExp("^(https?|ftp)://.+")) != null
       );
   }).each(function () {
    $(this).click(function() {
      window.open($(this).attr('href'));
	   return false;
 	});
  });
  if ($('div#scrollbar').length) {
    var id = 1;

	 $('div#scrolling td div').each(function() {
	   $(this).attr('id', 'item-'+id++);
		totalwidth+=$(this).outerWidth();
	 });
	 totalitems = id-1;
	 currentitem = 0;
	 itemwidth = Math.round(totalwidth / totalitems);
	 $('div#scrolling, div#scrolling table').css({'width': (itemwidth * totalitems)+'px'});
	 maxoffset = $('div#scrollpane').width()-$('div#scrolling').width();
	 $('div#scrollbar a.prev,div#scrollbar a.next').click(function() {
      if (maxoffset < 0) {
			switch($(this).attr('class')) {
			  case 'prev': if (currentitem > 0) currentitem--;  break;
			  case 'next': if (currentitem < totalitems - 1) currentitem++;  break;
			}
			currentoffset = (-currentitem*itemwidth);
		   if (maxoffset - currentoffset > 0) {
			  currentoffset = maxoffset;
			  currentitem--;
			} 
			$('div#scrolling').animate({marginLeft:currentoffset+'px'}, 400);
	  }
  	   return false;
   });
  }
});

function scrolltoid(id) {
  if ($('div#scrolling').width() > $('div#scrollpane').width() && $("div#scrolling td#"+id).length) {
    $("div#scrolling td").each(function() {
	   if ($(this).attr("id") == id) {
		  return false;
		}
	  currentitem++;
	 });
    if (currentitem > 0) {
		currentoffset = (-currentitem*itemwidth);
		$('div#scrolling').animate({marginLeft:currentoffset+'px'}, 400);
	 }
  }
}
