/*SCROLL*/
var t1 = null;
function initScroll(dx,dy){
	var SCH = ElmHeight('scrollContent');
	var SHH = ElmHeight('scrollHolder');
	var STH = ElmHeight('scrollThumb');
	var STRH = ElmHeight('scrollTrack')-20-STH;
	dy = STRH;
	if(SCH>SHH){
		make_Visible("scrollThumbHolder", true);
		var toScroll = SCH-SHH;
		var aThumbv = document.getElementById("scrollThumb");
		Drag.init(aThumbv, null, 0, 0, dx, dy);
		aThumbv.onDrag = function(x, y) {// x, y contains current offset coords of drag
			var percent = (-1)*((toScroll*y)/dy);
			document.getElementById('scrollContent').style.top = percent+"px";
		}
	}else{
		make_Visible("scrollThumbHolder", false);
	}
}
function ElmHeight(elmID) {
	var H = null;
	if(document.getElementById(elmID).clientHeight) {
		H = document.getElementById(elmID).clientHeight;
	}else if(document.getElementById(elmID).offsetHeight){
		H = document.getElementById(elmID).offsetHeight;
	}
	return H;
}
function make_Visible(obj, bol){
	if(bol){val="block";}else{val="none";}
	if(document.getElementById(obj).style.display){
		document.getElementById(obj).style.display = val;
		return;
	}else if(document.getElementById(obj).setAttribute){
		document.getElementById(obj).setAttribute("style","display:"+val+"");
		return;
	}	
}
var topacity = null;
function showJobDetails(root,job){
	//disableWindowScroll();
	//document.body.style.overflow = "hidden";
	make_Visible('menuHolder', false);
	make_Visible('menu_bottom_bg', false);
	make_Visible('jobDetailsHolder',true);
	displayJobDetails('<img src="'+root+'images/ajax-loader.gif" border="0" /><br/><span style="color:#FFFFFF;">T&eacute;l&eacute;chargement en cours...</span>');
	if(topacity != null){
		//topacity.stop();
	}
	
	ajaxRequest(root,job);
	var dummy = document.getElementById('jobDetailsHolderBg');
	topacity = new OpacityTween(dummy,Tween.regularEaseOut,0,80,.5);
	topacity.start();
	//alert(dummy);
}
function hideJobDetails(){
	//enableWindowScroll();
	//document.body.style.overflow = "";
	if(topacity != null){
		//topacity.stop();
	}
	make_Visible('menuHolder', true);
	make_Visible('menu_bottom_bg', true);
	var dummy = document.getElementById('jobDetailsHolderBg');
	topacity = new OpacityTween(dummy,Tween.regularEaseOut,80,0,.1);
	topacity.start();
	make_Visible('jobDetailsHolder',false);
}
function displayJobDetails(details){
	//alert(details);
	var dummy = document.getElementById('jobDetailsBg');
	dummy.innerHTML = details;
}
/************/
function getAJAX() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            return new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e) {
            return new ActiveXObject('Microsoft.XMLHTTP');
        }
    }
}
function ajaxRequest(root,job){
	var xhr = getAJAX();
    xhr.onreadystatechange = function() {
				if(xhr.readyState==4){
					displayJobDetails(xhr.responseText);
				}
    }
    xhr.open('get', root+'php/php_show_job_details.php?job='+job+'&root='+root, true);
    xhr.send('');
}

/************/
function paginationOver(el){
	el.className = "current";
}
function paginationOut(el){
	el.className = "normal";
}
function getURL(url){
	window.location.href = url;
}

function formDelay(f, update, area){
	if(update==1){
		ta = area.split(':');
		for(i=0;i<ta.length;i++){
			if(ta[i]!=""){
				WYSIWYG.updateTextArea(ta[i]);
			}
		}
	}
	myTimeout = setTimeout("formSubmit('"+f+"')",50);
}
function formSubmit(f){
	doc = document.getElementById(f);
	doc.submit();
}
/************/
var tjob = null;
var previousTop = 0;
function repositionJobDetails(){
	doc = document.getElementById('jobDetailsBg');
	if(doc){
		if(tjob!=null){tjob.stop();}
		var Axis = getScrollXY();
		var Top = Axis[1]+10;
		//doc.style.top = parseFloat(Top)+"px";
		tjob = new Tween(doc.style,'top',Tween.regularEaseOut,previousTop,Top,1,"px");
		tjob.start();
		previousTop = Top
	}
}
function repositionJobDetailsDelay(){
	myTimeout2 = setTimeout("repositionJobDetails()",500);
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

var ooTop = 0;
function disableWindowScroll(){
		if(window.onscroll){
			window.onscroll = function(){
					myTimeout3 = setTimeout("disableWindowScrollEvent()",0);
			};
		}
		if(document.body.onmousewheel){alert("");}
}
function disableWindowScrollEvent(){
		//var scrollpos = getScrollingPosition();
		//document.title = 'left=' + scrollpos[0] + ' top=' + scrollpos[1];
		//setScrollingPosition(scrollpos[1]);
		window.scroll(0,0);
}

function enableWindowScroll(){
	window.onscroll = function(){};
} 

function getScrollingPosition(){
	var position = [0, 0];
	if (typeof window.pageYOffset != 'undefined'){
		position = [window.pageXOffset,window.pageYOffset];
	}else if (typeof document.documentElement.scrollTop!= 'undefined' && document.documentElement.scrollTop > 0){
		position = [document.documentElement.scrollLeft,document.documentElement.scrollTop];
	}
	else if (typeof document.body.scrollTop != 'undefined'){
		position = [document.body.scrollLeft,document.body.scrollTop];
	}
	return position;
}
function setScrollingPosition(Y){
	if (typeof window.pageYOffset != 'undefined'){
		window.pageYOffset = Y;
	}else if (typeof document.documentElement.scrollTop!= 'undefined' && document.documentElement.scrollTop > 0){
		document.documentElement.scrollTop = Y;
	}
	else if (typeof document.body.scrollTop != 'undefined'){
		document.body.scrollTop = Y;
	}
}