// Kelvin Owers - Feb 2006                                          //
// functions to modify layout for wide windows                     //
// code CSS to work with 800*600 windows without horiz scrollbars //
// then use these functions to alter margins for wider displays  //
// this could easily be extended to control div width by class  //

// Orange variable page margins // default values are in orange_shared.css //
function setPageMargin() {
    var marginLeftforTiny = 20;
    var marginTopforTiny  = 20;//This can be reduced to help fold margin issues if needed//
    var needsReDraw = (isMac && (isSafari||isFox));
    if (needsReDraw) {toggleDisplay('off', 'container')};
    setMargins('variable_margin', marginLeftforTiny, marginTopforTiny, 800);
    if (needsReDraw) {toggleDisplay('on', 'container')};
} // setPageMargin


// Set margins to given values for all divs with given class //
function setMargins(modifyClass, newMarginLeft, newMarginTop, wideWidth) {
    if (getWindowWidth() < wideWidth) {
      var listofDivs = getDivsbyClass(modifyClass);
      for (i=0; i < listofDivs.length; i++){
        setLeftMargin(listofDivs[0].id, newMarginLeft);
        setTopMargin (listofDivs[0].id, newMarginTop);
      }
    }
} //setLeftMargins

// Set left margin to be given value for div with given Id //
function setLeftMargin(modifyId, newMargin) {
    var theStyle = getStyleObject(modifyId);
    theStyle.marginLeft = newMargin + "px";
} //setLeftMargin

// Set top margin to be given value for div with given Id //
function setTopMargin(modifyId, newMargin) {
    var theStyle = getStyleObject(modifyId);
    theStyle.marginTop = newMargin + "px";
} //setTopMargin

function getWindowWidth() {
    var adjustWidth = 0;
    if (isIE) {adjustWidth = 7};
    if (isWindows && isFox) {adjustWidth = -12};
    if (isMac && isFox) {adjustWidth = -5};
    if (isSafari) {adjustWidth = -7};
    if (typeof( window.innerWidth ) == 'number' ) {
      // W3C and others
      return (window.innerWidth + adjustWidth );
    } else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      // IE 6 in 'standards compliant mode'
      return (document.documentElement.clientWidth + adjustWidth) ;
    } else if (document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      // IE 4
      return (document.body.clientWidth + adjustWidth);
    } else { return 750;}
} // getWindowWidth

function getStyleObject(objectId) {
    if (document.getElementById && document.getElementById(objectId)) {
      // W3C
      return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
      // IE 4
      return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
      // NN 4 note: this won't find nested layers
      return document.layers[objectId];
    } else { return false;}
} // getStyleObject

function getDivsbyClass(className){
    var allDivs = document.getElementsByTagName('div');
    var matchedDivs=new Array();
    var nummatchedDivs=0;
    var rootLength=allDivs.length;
    for (i=0; i < rootLength; i++){if (allDivs[i].className==className) matchedDivs[nummatchedDivs++]=allDivs[i]};
    return matchedDivs;
} // getDivsbyClass

function toggleDisplay(toggleDisplay, toggleId) {
    var theStyle = getStyleObject(toggleId);
    if (toggleDisplay=='off'){theStyle.display = 'none';
    } else {theStyle.display = 'block';}
} // toggleDisplay
