function crossBr_GetElID(e){
    if(document.getElementById) {
        return document.getElementById(e);
    }
    if(document.all) {
        return document.all[e];
    }
}

function init(){
	setInterval("positionSubMenu()", 10);
}

var sm_div = false;     // leftContent div
var menuStartY = 160;   // default y position of the menu div
var menuStartMargin = 0;   // default y position of the menu div
var sm_lastMargin = 0;  //  last margin
var sm_nextMargin = menuStartMargin;  // next step needs this margin
var sm_pixelshift = 0;  // number of px per shift
var sm_curShift = 0;    // current step
var sm_maxShifts = 5;   // max num of steps
var sm_moving = false;  // moving: to move or not to move
var sm_interval;        // movement interval identifier

function getPageScroll() {
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) { // all other Explorers
		yScroll = document.body.scrollTop;
	}
	return yScroll;
}

function positionSubMenu() {
	// if not moving freeze
	if (sm_moving) {
		return false;
    }
	// get submenu div id
	if(!sm_div) {
		sm_div = crossBr_GetElID('news_items_list');
    }
	// get current margin
	var pageScroll=getPageScroll();
	var new_sm_nextMargin = pageScroll+menuStartMargin;
    
    // Pas als scroll groter is dan 160 moet ie gaan scrollen, anders... is ie 0
	// if margin is done -> exit
	if (sm_nextMargin == new_sm_nextMargin) { 
	   return false; 
    }
    if(pageScroll > menuStartY) {
    
    	// get new margin from the difference
	   sm_nextMargin = new_sm_nextMargin - menuStartY + menuStartMargin;
    	var marginDif = sm_nextMargin - sm_lastMargin;
	   sm_pixelshift = Math.floor(marginDif / 10);

    	// change number of px depending on difference.
        if (sm_pixelshift > 0 && sm_pixelshift < 1) {
            sm_pixelshift = 1;
    		sm_maxShifts = marginDif;
        } else if (sm_pixelshift < 0 && sm_pixelshift > -1) {
            sm_pixelshift = -1;
            sm_maxShifts = marginDif;
	   } else {
            sm_maxShifts = 5;
    	}
	   // moving is true, so change margin
	   sm_moving = true;
	   sm_interval = window.setInterval("changeMargin()", 10);
	   
	} else {
		sm_div.style.marginTop = 0;
	}
}

function changeMargin() {
	// add to margin
	sm_curShift++;

	// change the margin
	var le_margin = (sm_lastMargin + (sm_curShift * sm_pixelshift));
	sm_div.style.marginTop = (le_margin < 0 ? 0 : le_margin) + 'px';

	// reset at last step
	if (sm_curShift == sm_maxShifts) {
		sm_moving = false;
		sm_div.style.marginTop = sm_nextMargin + 'px';
		sm_curShift = 0;
		sm_lastMargin = sm_nextMargin;
		window.clearInterval(sm_interval);
	}
}
function addLoadEvent(func) {		var oldonload = window.onload;	if (typeof window.onload != 'function'){    	window.onload = func;	} else {		window.onload = function() {		  oldonload();		  func();		}	}}addLoadEvent(init);	
