function Toggle (id) {
    var display = document.getElementById(id).style.display
    if (display == "none" || display == '') {
        document.getElementById(id).style.display = "block"
    }
    else {
        document.getElementById(id).style.display = "none"
    }
}

function addFile(count, parent, prefix) {
        var parent = document.getElementById(parent);
        document.getElementById(count).value++;
        var newFile = document.createElement('input');

        newFile.id = prefix + "1_" +parseInt(document.getElementById(count).value);
        newFile.name = prefix + "1_" +parseInt(document.getElementById(count).value);
        newFile.type = "file";

        var newFile2 = document.createElement('input');

        newFile2.id = prefix + "2_" +parseInt(document.getElementById(count).value);
        newFile2.name = prefix + "2_" +parseInt(document.getElementById(count).value);
        newFile2.type = "file";

        var newFile3 = document.createElement('input');

        newFile3.id = prefix + "3_" +parseInt(document.getElementById(count).value);
        newFile3.name = prefix + "3_" +parseInt(document.getElementById(count).value);
        newFile3.type = "file";

        parent.appendChild(newFile);
        parent.appendChild(newFile2);
        parent.appendChild(newFile3);
}

/********* JQUERY *********/
/* Petit hack pour permettre à IE de comprendre les setInterval avec plusieurs paramètres */
/*@cc_on
(function(f){
 window.setTimeout =f(window.setTimeout);
 window.setInterval =f(window.setInterval);
})(function(f){return function(c,t){var a=[].slice.call(arguments,2);return f(function(){c.apply(this,a)},t)}});
@*/
this.popup_rollover_popinfo = function () {
	/* CONFIG */
		xOffset = 90;
		yOffset = 15;
	/* END CONFIG */
	jQuery(".popinfo").click(function(){return false}); //On empeche le clic
	jQuery(".popinfo").hover(function(e){
		console.log("hover");
		var HTML = '<img src="'+this.href+'" alt=""/>';
		jQuery("body").append("<div id='popup_rollover_img'>"+ HTML +"</div>");
		jQuery("#popup_rollover_img")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		jQuery("#popup_rollover_img").remove();
    });
	jQuery(".popinfo").mousemove(function(e){
		jQuery("#popup_rollover_img")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
}
this.scrollCategories = function () {
	var scroll;
    jQuery('#scrolldown').hover(function() {
        scroll = setInterval(scrollFnct, 25, '.categories', '.cat-conteneur', 'down');
    }, function() {
        clearInterval(scroll);
    }
    );
    jQuery('#scrollup').hover(function() {
        scroll = setInterval(scrollFnct, 25, '.categories', '.cat-conteneur', 'up');
    }, function() {
        clearInterval(scroll);
    }
    );
}
jQuery(document).ready(
function () {
	popup_rollover_popinfo();
	scrollCategories();
}
);
function scrollFnct (element, conteneur, direction) {
    if (direction == 'up') {
        var nextTop = parseInt(jQuery(element).css('top')) + parseInt(1);
        if (nextTop <= 0) {
            jQuery(element).css('top', nextTop);
        }
    }
    else {
        var nextTop2 = parseInt(jQuery(element).css('top')) - parseInt(1);
        var maxTop = parseInt(jQuery(element).height()) + nextTop2;
        if (parseInt(jQuery(conteneur).height()) < maxTop) {
            jQuery(element).css('top', nextTop2);
        }
    }    
}
function moveUp (element,x) {
  var y = getRealValue(jQuery(element).css('top'));
  var nextY = parseInt(y) + parseInt(x);
  if (nextY <= 0) {
      jQuery(element).animate({
        top: "+="+x+"px"
      }, 500 );
  }
}
function moveDown (element, x) {
  var h = jQuery(element).height();
  var nextY = -(parseInt(getRealValue(jQuery(element).css('top'))) - parseInt(x)) ;
  if (h > nextY && nextY > 0) {
      jQuery(element).animate({
        top: "-="+x+"px"
      }, 500 );
  }
  else {
      var maxtop = parseInt(h) - parseInt(x);
      jQuery(element).animate({        
        top: "-"+maxtop+"px"
      }, 500 );
  }
}
function moveLeft (element,x) {
  var w = jQuery(element).width();
  var nextY = -(parseInt(getRealValue(jQuery(element).css('left'))) + parseInt(x)) ;
  //console.log(w +'<'+ nextY+' '+getRealValue(jQuery(element).css('left')));
  if (w > nextY && nextY >= 0) {
      jQuery(element).animate({
        left: "+="+x+"px"
      }, 500 );
  }
}
function moveRight (element,x) {
  var y = getRealValue(jQuery(element).css('left'));
  var nextY = parseInt(x) - parseInt(y);
  //console.log(nextY +'>'+ 0 +' '+y+' '+jQuery(element).width());
  if (nextY > 0 && nextY <= jQuery(element).width()) {
      jQuery(element).animate({
        left: "-="+x+"px"
      }, 500 );
  }
}
function getRealValue (px) {
    var reg = /([0-9\-]+)px/;
    px.match(reg);
    return RegExp.$1;
}

function add_scroll(id) {
    if (id == null) {
        id = '#scroll-content';
    }
    jQuery(id).jScrollPane({scrollbarWidth:9});
}
/******** //JQUERY ********/
