// JavaScript Document


var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}


	function nq_scrollbar(id_curseur_scrollbar, id_fond_scrollbar, id_conteneur_html)
{
    var Dom = YAHOO.util.Dom;
	
	if(Dom.get(id_conteneur_html).scrollHeight <= parseInt(Dom.getStyle(id_conteneur_html, 'height'), 10) )
	{
		Dom.setStyle(id_fond_scrollbar, 'display', 'none');
		Dom.setStyle(id_fond_scrollbar, 'visibility', 'hidden');		
		return;
	}

    var Event = YAHOO.util.Event;
	var dd1;

    YAHOO.example.DDRegion = function(id, sGroup, config) {
        this.cont = config.cont;
		this.cont_html = config.cont_html;
		this.ev = null;
		this.myAnim = new YAHOO.util.Scroll(this.cont_html, { scroll: { to: [0, 0] } }, 0, YAHOO.util.Easing.easeNone);
        YAHOO.example.DDRegion.superclass.constructor.apply(this, arguments);
    };

    YAHOO.extend(YAHOO.example.DDRegion, YAHOO.util.DD, {
        cont: null,
        init: function() {
            //Call the parent's init method
            YAHOO.example.DDRegion.superclass.init.apply(this, arguments);
            this.initConstraints();

            Event.on(window, 'resize', function() {
                this.initConstraints();
            }, this, true);
        },
		

		onDrag: function(e) {
			Event.stopPropagation(this.ev);
			if(!this.myAnim.isAnimated())
			{
				//Get the top, right, bottom and left positions
				var region = Dom.getRegion(this.cont);
	
				//Get the element we are working on
				var el = this.getEl();
	
				//Get the xy position of it
				var xy = Dom.getXY(el);
	
				//Get the width and height
				var height = parseInt(Dom.getStyle(el, 'height'), 10);
	
				//Set top to y minus top
				var top = xy[1] - region.top;
		
				var percent = top / (region.bottom - region.top - height) ;
				//document.title = percent ;
				var height_html = Dom.get(this.cont_html).scrollHeight - parseInt(Dom.getStyle(this.cont_html, 'height'), 10);

				this.myAnim = new YAHOO.util.Scroll(this.cont_html, { scroll: { to: [0, height_html*percent] } }, 0, YAHOO.util.Easing.easeNone);
				this.myAnim.animate();
			}
		},
		
		goTo: function(e) {
			if(Event.getTarget(e).id == this.cont && !this.myAnim.isAnimated())
			{
				//Get the top, right, bottom and left positions
				var region = Dom.getRegion(this.cont);
	
				//Get the xy position of it
				var xy = Event.getXY(e);
			
				var el = this.getEl();				
				
				var height_cont = parseInt(Dom.getStyle(this.cont, 'height'), 10);
				var height_curs = parseInt(Dom.getStyle(el, 'height'), 10);
				var mouse_pos_page = xy[1] - region.top;

				var pos_cur;
				var percent;
				if(mouse_pos_page < height_curs/2){
					pos_cur = 0;
					percent = 0;
				}
				else if(mouse_pos_page > height_cont - height_curs/2 ){
					pos_cur = height_cont - height_curs;
					percent = 1;
				}
				else{
					pos_cur = mouse_pos_page - height_curs/2;
					percent = mouse_pos_page / (region.bottom - region.top) ;
				}
				
				Dom.setY(el, region.top + pos_cur);				
			
				var height_html = Dom.get(this.cont_html).scrollHeight - parseInt(Dom.getStyle(this.cont_html, 'height'), 10);
				
				this.myAnim = new YAHOO.util.Scroll(this.cont_html, { scroll: { to: [0, height_html*percent] } }, 0.3, YAHOO.util.Easing.easeOut);
				this.myAnim.animate();
			}
		},
		
        initConstraints: function() {
            //Get the top, right, bottom and left positions
            var region = Dom.getRegion(this.cont);

            //Get the element we are working on
            var el = this.getEl();
			

			this.ev = YAHOO.util.Event.addListener(this.cont, "click", this.goTo, this, true); 

            //Get the xy position of it
            var xy = Dom.getXY(el);

            //Get the width and height
            var width = parseInt(Dom.getStyle(el, 'width'), 10);
            var height = parseInt(Dom.getStyle(el, 'height'), 10);

            //Set left to x minus left
            var left = xy[0] - region.left;

            //Set right to right minus x minus width
            var right = region.right - xy[0] - width;


            //Set top to y minus top
            var top = xy[1] - region.top;

            //Set bottom to bottom minus y minus height
            var bottom = region.bottom - xy[1] - height;
			
            //Set the constraints based on the above calculations
            this.setXConstraint(left, right);
            this.setYConstraint(top, bottom);
        }
    });
;
	dd1 = new YAHOO.example.DDRegion(id_curseur_scrollbar, '', { cont: id_fond_scrollbar, cont_html:id_conteneur_html });
}



