  
var border_left = 0;
var border_right = 520;   
var _startPos = -1;   
var _startX = 0;			// mouse starting positions
var _startY = 0;
var _offsetX = 0;			// current element offset
var _offsetY = 0;
var _dragElement;			// needs to be passed from OnMouseDown to OnMouseMove
var _oldZIndex = 0;			// we temporarily increase the z-index during drag
//var _debug = $('debug');	// makes life easier

var scroll_scale = 0;




function InitAll()
{

border_left = 0;
border_right = 520;   
_startPos = -1;   
_startX = 0;			// mouse starting positions
_startY = 0;
_offsetX = 0;			// current element offset
_offsetY = 0;
_dragElement;			// needs to be passed from OnMouseDown to OnMouseMove
_oldZIndex = 0;			// we temporarily increase the z-index during drag

if(document.getElementById('scroll-inner'))
scroll_scale = (document.getElementById('scroll-inner').offsetWidth - 621) / border_right;


InitDragDrop();
}

function InitDragDrop()
{
	document.onmousedown = OnMouseDown;
	document.onmouseup = OnMouseUp;
}

function OnMouseDown(e)
{
	// IE is retarded and doesn't pass the event object
	if (e == null) 
		e = window.event; 
	
	// IE uses srcElement, others use target
	var target = e.target != null ? e.target : e.srcElement;
	
//	_debug.innerHTML = target.className == 'drag' ? 'draggable element clicked' : 'NON-draggable element clicked';

	// for IE, left click == 1
	// for Firefox, left click == 0
	if ((e.button == 1 && window.event != null || 
		e.button == 0) && 
		target.className == 'drag')
	{
		// grab the mouse position
		_startX = e.clientX;
		_startY = e.clientY;
		
		// grab the clicked element's position
		_offsetX = ExtractNumber(target.style.left);
		_offsetY = ExtractNumber(target.style.top);
		
		// bring the clicked element to the front while it is being dragged
		_oldZIndex = target.style.zIndex;
		target.style.zIndex = 10000;
		
		// we need to access the element in OnMouseMove
		_dragElement = target;

		// tell our code to start moving the element with the mouse
		document.onmousemove = OnMouseMove;
		
		// cancel out any text selections
		document.body.focus();
		
		// prevent text selection in IE
		document.onselectstart = function ()
            { return false; };
		
		// prevent text selection (except IE)
		
        if(_startPos ==-1)
            _startPos = _startX;  		
		
		return false;
	}
}

function ExtractNumber(value)
{
	var n = parseInt(value);
	
	return n == null || isNaN(n) ? 0 : n;
}

function OnMouseMove(e)
{
	if (e == null) 
		var e = window.event; 

    var _Xpos = _offsetX + e.clientX - _startX;
    
    if(_Xpos < border_left)
        _Xpos = border_left;
    
    if(_offsetX + e.clientX - _startX >= border_right)
        _Xpos = border_right;
    

	_dragElement.style.left = _Xpos + 'px';
	_dragElement.style.top = (_offsetY ) + 'px';

    //alert(_Xpos);

    scroll(_Xpos);
	
//	_debug.innerHTML = '(' + _dragElement.style.left + ', ' + _dragElement.style.top + ')';	
}

function OnMouseUp(e)
{
	if (_dragElement != null)
	{
		_dragElement.style.zIndex = _oldZIndex;

		document.onmousemove = null;
		document.onselectstart = null;

		_dragElement = null;
		

	}
}


function $(id)
{
	return document.getElementById(id);
}



function scroll(pos)
{
    npos = Math.round(pos * scroll_scale );
    
    document.getElementById('scroller').scrollLeft = npos;
     

}

// =====================================================================

function Logo()
{

 var logo = document.getElementById('logo');
 var menu = document.getElementById('mainTable');
 var logoemi = document.getElementById('emilogo');
 
 logoemi.style.display='none';
 
 if(logo || logoemi)
 {       
    if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	else return;    
    
    var left = frameWidth/2 + 290;
    var top =  frameHeight/2 - 260;
    var diff = frameWidth - 1016; 

    if ((diff <= 0) || (navigator.appVersion.indexOf("MSIE")>-1))
    {
    	logoemi.style.left = 790+'px';
    }
    else
    {
	logoemi.style.left = (790+(diff/2))+'px';
    }
    
    if ((frameHeight - 553)<=0)
    {
	logoemi.style.top = 15+'px';
    }
    else
    {
        logoemi.style.top = (frameHeight - 553)/2+'px'; 
    }
   
    logoemi.style.display='block';
 
    logo.style.top = top+'px';
    logo.style.left= left+'px';
    
    logo.style.display='';
    logo.style.visibility='';
    
 
 }

}
