function mainStartup()
{
	closeSearch();
  check_Viewport();
  old_viewport_width=0;
};

var ie = false;

/****************************************************************
 Quirksmode DHTML micro API (Version B) [modified] *************/

function getObj(name)
{
 if(document.getElementById)
 {
	 if(document.getElementById(name))
	 {
		 this.obj = document.getElementById(name);
		 this.style = document.getElementById(name).style;
	 }
 }
 else if (document.all)
 {
	 if(document.all[name])
	 {
		 this.obj = document.all[name];
		 this.style = document.all[name].style;
	 }
 }
 else if (document.layers)
 {
	 if(document.layers[name])
	 {
		 this.obj = getObjNN4(document,name);
		 this.style = this.obj;
	 }
 }
};

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
};

/****************************************************************
 Menu Functions ************************************************/
function openMenu(obj)
{
	var subMenu = new getObj(obj);
	if(subMenu.obj && subMenu.style.display!='block')
	{
		subMenu.style.display='block';
	}
};

function closeMenu(obj)
{
	var subMenu = new getObj(obj);
	if(subMenu.obj && subMenu.style.display!='none')
	{
		subMenu.style.display='none';
	}
};

/****************************************************************
 General Functions *********************************************/
function updateSpan(el_span, newJSSpanText)
{
	var spanObj = new getObj(el_span);
	if(spanObj.obj)
	{
    spanObj.obj.innerHTML=newJSSpanText;
	}
};


/****************************************************************
 Search Functions **********************************************/
 
var searchBlur=false;

function closeSearch()
{
		closeMenu('search');
};

var search_hold;

function holdSearch()
{
	search_hold=true;
};

function hideSearch()
{
	var searchObj = new getObj('search');
	if(searchObj.obj)
	{
		search_hold=false;
		var closeSearch_timer = setTimeout('if(!search_hold){closeSearch()}',1000);
	}
};

function showSearch()
{
	var searchObj = new getObj('search');
	if(searchObj.obj && searchObj.style.display!='block')
	{
		openMenu('search');
		searchObj = new getObj('searchText');
		if(searchObj.obj)
		{
			searchObj.obj.focus();
			searchObj.obj.select();
		}
	}
};


/****************************************************************
 viewport ******************************************************/
 
var viewport_width;
//var viewport_height;
var check_Viewport_timer;

function cancel_Viewport_timer()
{
  check_Viewport_timer = clearTimeout()
};

function get_Viewport()
{
  if (window.innerWidth)
  {
    //(mozilla/netscape/opera/IE7)
    viewport_width = window.innerWidth;
    //viewport_height = window.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientWidth != 0)
  {
    // IE6 in standards compliant mode
    viewport_width = document.documentElement.clientWidth;
    //viewport_height = document.documentElement.clientHeight;
  }
  else if (document.body)
  {
    // older versions of IE
    viewport_width = document.body.clientWidth
    //viewport_height = document.body.clientHeight;
  }
};

function check_Viewport()
{
  get_Viewport();
  set_Image();
  check_Viewport_timer = setTimeout('check_Viewport()',10);
};

/****************************************
 set_Image() is on a timer *************/
var old_viewport_width;
var runonce;
var runtwice;
var old_em;

function set_Image()
{
  /***************************************/
  // get the current font-size
  var el_emMeasure = new getObj('emMeasure');
  var em = 15;
  var maxWidth;
  if(el_emMeasure.obj){ em = el_emMeasure.obj.offsetLeft; }
  /***************************************/
  
  if((viewport_width!=old_viewport_width)||(em!=old_em)||(runonce||runtwice))
  {
    old_viewport_width=viewport_width;
    old_em = em;
		
		runonce=true;
		
		if(runtwice){
		//alert("resizing twice...");
		runonce=false
		runtwice=false;
		}
		if(runonce){
		//alert("resizing once...");
		runonce=false
		runtwice=true;
		}

    /***************************************/
    // get the current footer height
    var el_contentContainer = new getObj('contentContainer');
    var el_footerContainer = new getObj('footerContainer');
    var el_footerHeight;
    // and adjust contentContainer padding-bottom accordingly
    if(el_contentContainer.obj && el_footerContainer.obj){ el_footerHeight=el_footerContainer.obj.offsetHeight; el_contentContainer.style.paddingBottom=el_footerHeight+'px'; }
    /***************************************/

    /***************************************/
    // get the required elements
    var el_pageContainer = new getObj('pageContainer');
    var el_side = new getObj('side');
    
    var el_left = new getObj('left');
    var el_right = new getObj('right');
    
    /***************************************/
    // get the required elements
    var rightMargin = 130;
    

    // if the viewport is too small:
    if(viewport_width<=989 || em > 36)
    {
    // the left side and right side are stacked
    
      // quote_title is adjusted
      var el_quote_title = new getObj('quote_of_the_day_title');
      if(el_quote_title.obj){ el_quote_title.style.marginLeft=10+'px'; }

      // determine maximum page width
      maxWidth=((viewport_width-480)/3)+480; // 1/3 the remaining width between the difference of the viewport width and the minimum width (480)
      maxWidth=Math.max(maxWidth, (em*30)) // or wider if the font is large
      maxWidth=Math.min(maxWidth, 976) // but not wider than 976
      var fullWidth=(maxWidth-140).toFixed(0);
      
      // set left and right width and margin-right
      if(el_left.obj){ el_left.style.width=fullWidth+'px'; el_left.style.marginRight=140+'px'; }
      if(el_right.obj){ el_right.style.width=fullWidth+'px'; el_right.style.marginRight=140+'px'; }
    
      // adjust margin-right for class="rightMargin1on" &  class="rightMargin2on"
      var divs = getElementsByClassName('rightMargin1on')
      for(i=0; i <divs.length;i++)
      {
        divs[i].className = 'rightMargin1off';
      }
      divs = getElementsByClassName('rightMargin2on')
      for(i=0; i <divs.length;i++)
      {
        divs[i].className = 'rightMargin2off';
      }
      rightMargin=2*em;

    }
    
    // otherwise the viewport is big enough:
    else
    {
    // the left side and right side are in 2 columns
    
      // quote_title is adjusted (back to normal)
      var el_quote_title = new getObj('quote_of_the_day_title');
      if(el_quote_title.obj){ el_quote_title.style.marginLeft=-22+'px'; }
      
      // determine maximum page width
      maxWidth=Math.max(970, (em*60)); // 960 or wider if the font is large
      maxWidth=Math.min(maxWidth,viewport_width-20); // but not too wide
      var halfWidth=((maxWidth-11)/2).toFixed(0); // get the width of the sides (left & right);
      
      // set left and right width and margin-right
      if(el_left.obj){ el_left.style.width=halfWidth+'px'; el_left.style.marginRight=10+'px'; }
      if(el_right.obj){ el_right.style.width=halfWidth+'px'; el_right.style.marginRight=0; }
    
      // adjust margin-right for class="rightMargin1off" &  class="rightMargin2off"
      var divs = getElementsByClassName('rightMargin1off')
      for(i=0; i <divs.length;i++)
      {
        divs[i].className = 'rightMargin1on';
      }
      divs = getElementsByClassName('rightMargin2off')
      for(i=0; i <divs.length;i++)
      {
        divs[i].className = 'rightMargin2on';
      }
      rightMargin=130;
      
    }
    
    // set maximum page width
    if(el_pageContainer.obj){ el_pageContainer.style.maxWidth=maxWidth+'px'; }
    // and adjust the fixed side(flower) max-width accordingly
    if(el_side.obj)
    {
    if(ie)
      { if(zoom!=100)
        { el_side.style.maxWidth=100+'%'; }
      else
        { el_side.style.maxWidth=maxWidth+'px'; }
      }
    else
      { el_side.style.maxWidth=maxWidth+'px'; }
    }


    // get the table-cell elements in the content
    if (document.getElementsByTagName && el_left.obj && el_right.obj){ var el_leftCells = getElementsByClassName('cell','left'); var el_rightCells = getElementsByClassName('cell','right');}
    else return;

    // if the table-cell content is too wide, stack the cells, otherwise, display as a table
    if(el_leftCells && el_rightCells && el_left.obj && (el_left.obj.offsetWidth < (em*27)))
    {
      for (var i=0;i<el_leftCells.length;i++)
      {
        el_leftCells[i].style.width=(el_leftCells[i].parentNode.offsetWidth)-(em*2+50).toFixed(0)+'px';
      }
      for (var i=0;i<el_rightCells.length;i++)
      {
        el_rightCells[i].style.width=(el_rightCells[i].parentNode.offsetWidth)-(rightMargin)-(em).toFixed(0)+'px';
      }
    }
    else
    { 
      for (var i=0;i<el_leftCells.length;i++)
      {
        el_leftCells[i].style.width=(el_leftCells[i].parentNode.offsetWidth/2)-(em*2+20).toFixed(0)+'px';
      }
      for (var i=0;i<el_rightCells.length;i++)
      { 
        el_rightCells[i].style.width=((el_rightCells[i].parentNode.offsetWidth-rightMargin)/2)-(em).toFixed(0)+'px';
      }
    }
  }
};

function getElementsByClassName(v_className, startFrom) 
{
  if(document.getElementById && document.getElementsByTagName)
  {
    if (startFrom===undefined) { 	var el_array = document.getElementsByTagName("*"); }
    else { var el_array = document.getElementById(startFrom).getElementsByTagName("*"); }
    var retvalue = new Array();
    var a;
    var b;

    for (a=0,b=0;a<el_array.length;a++) 
    {
      var c = " " + el_array[a].className + " ";
      if (c.indexOf(" " + v_className + " ") != -1) retvalue[b++] = el_array[a];
    }
    return retvalue;
	}
	else 	return false;
}