//*** Programm of Slider ****
function initiateSlider() {
    initateSliderElements();   
    if(g_iActualColumnRightWidth!=0){
        //initiateRightSlider();
    }else{
	setIframeSrc();
	
        setSHISliderDisplayCloseRight();
        setCSSClassesForRightSlider(0);
    }
    
    if(document.getElementById(g_shiSliderRightColumnID)!=undefined){
        document.getElementById(g_shiSliderRightID).style.left = (getPosLeft(document.getElementById(g_shiSliderRightColumnID)))+"px";
        document.getElementById(g_shiSliderRightID).style.top = (getPosTop(document.getElementById(g_shiSliderRightColumnID)))+"px";
    }
    if(document.getElementById(g_shiSliderLeftColumnID)!=undefined){
        document.getElementById(g_shiSliderLeftID).style.top = (getPosTop(document.getElementById(g_shiSliderLeftColumnID)))+"px";
        document.getElementById(g_shiSliderLeftID).style.left = (getPosLeft(document.getElementById(g_shiSliderLeftColumnID)))+"px";     
    }  
}

function initiateLeftSlider() {
    var _iLeftWidth = getCookie(g_sCookieFieldNameColumnLeft);
    if((g_bMaximizeToolbar!=null)&&(g_bMaximizeToolbar==true)){
        _iLeftWidth = g_iMinColumnLeftWidth;
        document.cookie = g_sCookieFieldNameColumnLeft + "=" + g_iMinColumnLeftWidth;
    }
    if(_iLeftWidth==null) {
        _iLeftWidth = g_iActualColumnLeftWidth;
    }
    
    if(_iLeftWidth>=g_iMinColumnLeftWidth) {
        setColumnActiveSize(g_shiSliderLeftID,_iLeftWidth);
    }else{
        setColumnClose(g_shiSliderLeftID);
    }
}

function initiateRightSlider() {
    var _iRightWidth = getCookie(g_sCookieFieldNameColumnRight);
    
    if(_iRightWidth==null) {
        _iRightWidth = g_iActualColumnRightWidth;
    }
    if(_iRightWidth<=g_iCloseColumnRightWidth){
        if(typeof(elements_dazugehoert)!="undefined") {
           g_iActualColumnRightWidth=g_iMinColumnRightWidth; 
           _iRightWidth=g_iMinColumnRightWidth;
            }
        }
    if(_iRightWidth>=g_iMinColumnRightWidth) {
        setColumnActiveSize(g_shiSliderRightID,_iRightWidth);
    }else{
        setColumnClose(g_shiSliderRightID);
    }
}

function insertSlidersIntoHTML() {
    var _oSliderElementLeft = document.getElementById(g_shiSliderLeftColumnID);
    if(_oSliderElementLeft != null) {
        var _iPositionLeft = getPosLeft(_oSliderElementLeft);
        _oSliderElementLeft.innerHTML = getSliderMoveBar(_iPositionLeft,g_shiSliderLeftID,"outlookToolbarHight");
    }
    var _oSliderElementRight = document.getElementById(g_shiSliderRightColumnID);
    if(_oSliderElementRight != null) {
        var _iPositionRight = getPosLeft(_oSliderElementRight);
        _oSliderElementRight.innerHTML = getSliderMoveBar(_iPositionRight,g_shiSliderRightID,"marginalAreaHeight");
    }
}

function getSliderMoveBar(positionLeft,sliderId,cssClass){
    return "<div id=\"" + sliderId + "\" class=\"" + g_sSliderBackroundColorClass + " sliderMoveBar " + cssClass + "\" onmouseover=\"this.style.cursor='e-resize'\" onmouseup=\"dropScroller();\" onmousedown=\"getScroller(this);\"   width=\"4px\" style=\"left:" + positionLeft + ";\"  onmouseout=\"this.style.cursor='pointer'\"></div>";
}

function getMouseXY(e){
    if(!e) e = window.event;
    if(e){
        if(e.pageX || e.pageY){
            mousePositionX = e.pageX;
        }else if(e.clientX || e.clientY){
            mousePositionX = e.clientX;
        }
    }
}

function getScroller(context){
    document.onmousedown = null;
    drag_obj = context;
    drag_obj.style.zIndex = 98;
    document.onmousemove = moveScroller;
    document.onmouseup = dropScroller; 
    if(g_sDocumentWindowID!=""&& document.getElementById(g_sDocumentWindowID) != null)
        document.getElementById(g_sDocumentWindowID).style.display = "none";
}
function moveScroller(e){
    if(drag_obj)
        drag_obj.style.left = (mousePositionX - s_w).toString(10) + "px";
    getMouseXY(e);
    return false; 
}
function dropScroller(){
    if(drag_obj)
        changeDivSize(drag_obj);
    
     if(g_sDocumentWindowID!="" && document.getElementById(g_sDocumentWindowID) != null)
        document.getElementById(g_sDocumentWindowID).style.display = "inline";
    drag_obj = document.onmousemove = document.onmousedown = document.onmouseup = null
}

function changeDivSize(drag_obj) {    
    var _iDivWidth = 0;
    var _iWindowWidth = document.body.offsetWidth;
    if(_iWindowWidth==0){
        _iWindowWidth = window.innerWidth;
    }
    if(drag_obj.id == g_shiSliderRightID) {
        var _scrollerLeft = 0;
        _iDivWidth = _iWindowWidth - mousePositionX ;
		
		if(_iDivWidth<g_iMinColumnRightWidth) {
            g_iActualColumnRightWidth = g_iMinColumnRightWidth;
            scrollerLeft = _iWindowWidth - g_iActualColumnRightWidth ;
            drag_obj.style.left = scrollerLeft+"px";
            setColumnClose(drag_obj.id);
	    setIframeSrc();
            return;
        }
        
        if(_iDivWidth>g_iMaxColumnRightWidth) {
            scrollerLeft = _iWindowWidth - g_iMaxColumnRightWidth;
            drag_obj.style.left = scrollerLeft+"px";
            _iDivWidth = g_iMaxColumnRightWidth;
        }
        
        scrollerLeft = _iWindowWidth - _iDivWidth ;
        drag_obj.style.left = scrollerLeft;
        document.cookie =  g_sCookieFieldNameColumnRight + "=" + _iDivWidth;
        
        g_iActualColumnRightWidth = _iDivWidth;
        setCSSClassesForRightSlider(_iDivWidth);
	setIframeSrc();
        document.getElementById(g_shiSliderRightID).style.left = (getPosLeft(document.getElementById(g_shiSliderRightColumnID)))+"px";
        document.getElementById(g_shiSliderRightID).style.top = (getPosTop(document.getElementById(g_shiSliderRightColumnID)))+"px";
        
        //var _height = getMarginalMoveBarHeight()+"";
        //if(_height.match(/^[\d]*$/))
        //    _height += "px";
        //document.getElementById(g_shiSliderRightID).style.height = _height;
    }
    
    if(drag_obj.id == g_shiSliderLeftID) {
		_iDivWidth = mousePositionX ;
		
        if(_iDivWidth<g_iMinColumnLeftWidth) {
            g_iActualColumnLeftWidth = g_iMinColumnLeftWidth;
            drag_obj.style.left = g_iActualColumnLeftWidth;
            cssRule('.outlookToolbarWidth','width',"20"+"px");
            setColumnClose(drag_obj.id);
            return;
        }
        
        if(_iDivWidth>g_iMaxColumnLeftWidth) {
            _iDivWidth = g_iMaxColumnLeftWidth;
        }
        setCSSClassesForLeftSlider(_iDivWidth);
        g_iActualColumnLeftWidth = _iDivWidth;
        drag_obj.style.left = getPosLeft(document.getElementById(g_shiSliderLeftID))+"px";
        document.getElementById(g_shiSliderLeftID).style.top = (getPosTop(document.getElementById(g_shiSliderLeftColumnID)))+"px";
        document.getElementById(g_shiSliderLeftID).style.left = (getPosLeft(document.getElementById(g_shiSliderLeftColumnID)))+"px";     
        document.cookie = g_sCookieFieldNameColumnLeft + "=" + _iDivWidth;
    }
}



function getCookie(cookieName) {
    if(!cookieName)
        return null;
    
    var cookie = document.cookie;
    if(!cookie)
        return null;
    
    var cookies = cookie.split(";");
    
    for(var i = 0; i < cookies.length; i++) {
        cookies[i] = cookies[i].replace(/^ /, "");
        if(cookies[i].length < cookieName.length + 1)
            continue;
        
        if(cookies[i].toLowerCase().substring(0,cookieName.length + 1) == (cookieName.toLowerCase() + "="))
            return cookies[i].substring(cookieName.length + 1);
    }
    
    return null;
}



function setColumnClose(sliderId) {
    
    if(sliderId == g_shiSliderLeftID) {
        if(g_bMinimizeColumnLeft=='true'){
            setCSSClassesForLeftSlider(g_iCloseColumnLeftWidth);
            setSHISliderDisplayCloseLeft()
            document.cookie = g_sCookieFieldNameColumnLeft + "=" + g_iCloseColumnLeftWidth;
            return;
       }else{
            setCSSClassesForLeftSlider(g_iMinColumnLeftWidth);
            document.cookie = g_sCookieFieldNameColumnLeft + "=" + g_iMinColumnLeftWidth;
            setColumnActiveSize(sliderId,g_iMinColumnLeftWidth);
            return;
       }
    }
    
    
    if(sliderId == g_shiSliderRightID) {
        if(g_bMinimizeColumnRight=='true'){
            setCSSClassesForRightSlider(g_iCloseColumnRightWidth);     
            setSHISliderDisplayCloseRight()
            document.cookie = g_sCookieFieldNameColumnRight + "=" + g_iCloseColumnRightWidth;
            setIframeSrc();
        }else{
            setCSSClassesForLeftSlider(g_iMinColumnRightWidth);
            document.cookie = g_sCookieFieldNameColumnRight + "=" + g_iMinColumnRightWidth;
            setColumnActiveSize(sliderId,g_iMinColumnRightWidth);
            return;
        }
    }
}

function setColumnActiveSize(sliderId,columnWidth) {
    //if(document.getElementById(sliderId)==null)
    //    return;
    if(sliderId == g_shiSliderLeftID) {
        setCSSClassesForLeftSlider(columnWidth);
        setSHISliderDisplayOpenLeft();
        document.cookie = g_sCookieFieldNameColumnLeft + "=" + columnWidth;
        
        
        // var _height = getSliderMoveBarLeftHeight()+""; // document.getElementById('sliderMoveBarLeft').offsetHeight;
        // if(_height.match(/^[\d]*$/))
        //     _height += "px";
        // document.getElementById(g_shiSliderLeftID).style.height = _height;
        
        document.getElementById(g_shiSliderLeftID).style.top = getPosTop(document.getElementById(g_shiSliderLeftColumnID))+"px";
        document.getElementById(g_shiSliderLeftID).style.left = getPosLeft(document.getElementById(g_shiSliderLeftColumnID))+"px";
        return;
    }
    
    if(sliderId == g_shiSliderRightID) {
        cssRule(".marginalMoveBar","width", "4px");
        setCSSClassesForRightSlider(columnWidth);
        setSHISliderDisplayOpenRight();
        var _left = getPosLeft(document.getElementById(g_shiSliderRightColumnID))+"";
        if(_left.match(/^[\d]*$/))
            _left += "px";

		if (document.getElementById(g_shiSliderRightID) != null) {
			document.getElementById(g_shiSliderRightID).style.left = _left;
			document.getElementById(g_shiSliderRightID).style.top = (getPosTop(document.getElementById(g_shiSliderRightColumnID)))+"px";
		}
        //var _height = getMarginalMoveBarHeight()+""; 
        //if(_height.match(/^[\d]*$/))
        //    _height += "px";
        //document.getElementById(g_shiSliderRightID).style.height = _height;
        
        document.cookie = g_sCookieFieldNameColumnRight + "=" + columnWidth;
        resizeSliders();
        setIframeSrc();
    }
}

function getSliderMoveBarLeftHeight() {
    if(document.getElementById(g_shiSliderLeftColumnID).offsetHeight)
        return document.getElementById(g_shiSliderLeftColumnID).offsetHeight;
    return self.innerHeight - 128;
}

function getMarginalMoveBarHeight() {   
    if(document.getElementById(g_shiSliderRightColumnID).offsetHeight)
        return document.getElementById(g_shiSliderRightColumnID).offsetHeight;
    
    return self.innerHeight - 128;
}

