// JavaScript Document

window.onload = init; 

function init()
{	
  var maxcolheight = 0;
  var leftColumnWidth = 0;
  var rightColumnWidth = 0;
  var middleColumnWidth = 0;
  
  //alert("hallo2");
  
  maxcolheight = $('col3').getSize().size.y;
  if(maxcolheight < $('col1').getSize().size.y) maxcolheight = $('col1').getSize().size.y;
  if(maxcolheight < $('col2').getSize().size.y) maxcolheight = $('col2').getSize().size.y;
  
  // predefine page height (predefinedPageHeight variable from ts template)
  if(maxcolheight < predefinedPageHeight) maxcolheight = predefinedPageHeight;
  //alert(maxcolheight);
  
  // left column
  $('col1_content').getChildren().each(function(el, index){
      //only use div elements
      if(el.getTag() != 'a')
      {
        el.style.height = maxcolheight+'px';
        if(el.hasClass('tabs'))
        {
          el.getFirst().style.height = maxcolheight+'px';
          el.getFirst().style.display = 'block';
          //correct alignment of the image "Pima Platform"
          /*
          if(el.getFirst().getProperty('title').substring(el.getFirst().getProperty('title').length-1) == 'm')
          {
            el.getFirst().getFirst().style.margin = '0px 0 0 0';
          }
          */
          //alert(el.getFirst().getProperty('title').substring(el.getFirst().getProperty('title').length-1));
        }
        leftColumnWidth = leftColumnWidth + el.getSize().size.x;      
      }
  });
  
  // right column
  $('col2_content').getChildren().each(function(el, index){
      //only use div elements
      if(el.getTag() != 'a')
      {
        el.style.height = maxcolheight+'px';
        el.getFirst().style.height = maxcolheight+'px';
        el.getFirst().style.display = 'block';
        /*
        if(el.getFirst().getProperty('title').substring(el.getFirst().getProperty('title').length-1) == 'm')
        {
          el.getFirst().getFirst().style.margin = '0px 0 0 0';
        } 
        */
        rightColumnWidth = rightColumnWidth + el.getSize().size.x;
      }
  });
  
  $('col3_content').style.height = maxcolheight-32+'px';
   
  //leftColumnWidth = leftColumnWidth + 30;
  
  $('col1').style.width = leftColumnWidth+'px';
  $('col2').style.width = rightColumnWidth+'px';
  $('col3').style.margin = '0 '+rightColumnWidth+'px '+'0 '+leftColumnWidth+'px';
  
  // get middle column width
  middleColumnWidth = $('col3').getSize().size.x;
  
  // set page width
  $$('div.page_margins').each(function(el, index){
    if(window.ie6) 
    {
      el.style.width = leftColumnWidth+middleColumnWidth+rightColumnWidth+'px'
      // correct margins
      $('col1').style.margin = '0 -'+leftColumnWidth+'px 0 0';
      $('col2').style.margin = '0 0 0 -'+rightColumnWidth+'px';
	  
	  // remove white line
	  if(rightColumnWidth<=35) $('pimalogo').style.right = -1+'px';
    }
    else el.style.width = leftColumnWidth+middleColumnWidth+rightColumnWidth+'px';
    //alert (leftColumnWidth+middleColumnWidth+rightColumnWidth);
  });
  
  //if(window.ie6) $('col1').style.margin = '0 -3px 0 0';
  //alert (middleColumnWidth);
}

var flag = 0;
var tipIDArr = new Array();

function hideLayers(currentLayer){
    if (flag == 0) {
        $$('div.imgtooltip').each(function(el, index){
            //do not hide current element 
			if (el.getProperty('id') != currentLayer) {
                el.setStyle('display', 'none');
				//el.style.display = "none";
            }
        });
    }
}

window.addEvent('domready', function(){
	//var Tips1 = new Tips($$(".Tips1"));
    
	// check if var tipids exists
	if (typeof( window[ 'tipids' ] ) != "undefined" )
	{
		// create tooltips for every element
		tipids.each(function(el, index){
			tipIDArr[el] = new Tips($$(".Tips" + el));
		});
	}
	
	$$('a.previewimg').each(function(el, index){
        var imgid = el.getProperty('id');
        
        el.addEvent('mouseenter', function(event){
            hideLayers('tip' + imgid);
            flag = 1;
            $('tip' + imgid).style.display = "block";
			       $('tip' + imgid).setStyles({
                'opacity': '1'
            });
        });
        
        el.addEvent('mouseleave', function(event){
			       $('tip' + imgid).setStyles({
                'opacity': '0'
            });
            $('tip' + imgid).style.display = "none";            
        });
    });
    
});