var isIE = navigator.userAgent.indexOf( 'MSIE' ) != -1 && navigator.userAgent.indexOf('Opera') == -1;
var isOpera = navigator.userAgent.indexOf('Opera') != -1;
if ( isOpera )
{
//credits: hallvors :D
if(window.Document && !window.Document.prototype.load && document.implementation && document.implementation.createLSParser){
    Document.prototype.load=function(uri){
        if(this.documentElement){this.removeChild(this.documentElement);}
        var doc=(document.implementation.createLSParser( this.async ? document.implementation.MODE_ASYNCHRONOUS:document.implementation.MODE_SYNCHRONOUS, null )).parseURI(uri);
        this.appendChild(this.importNode(doc.documentElement, true));
    }
}
}

var home=new Image();
var products=new Image();
var company=new Image();
var customers=new Image();
var partners=new Image();
var contact=new Image();


home.src="images/home-select.jpg";
products.src="images/products-select.jpg";
company.src="images/company-select.jpg";
customers.src="images/customers-select.jpg";
products.src="images/partners.jpg";
contact.src="images/contact.jpg";

function hoverNav( tdToChange ) 
{
tdToChange.style.borderRight= "solid gray 1px";
tdToChange.style.borderLeft= "solid gray 1px";
}
function leaveNav( tdToChange )
{
tdToChange.style.borderRight= "solid white 1px";
tdToChange.style.borderLeft= "solid white 1px";
}
function show(obj, idToShow )
{
 obj.style.backgroundColor = '#dedede';
 var elem = document.getElementById(idToShow);
 if ( elem != null )
 {
 		elem.style.display = 'block';
		
    var width = document.body.clientWidth;
		var height = document.body.clientHeight;
		var elemWidth = elem.clientWidth ;
		var elemHeight = elem.clientHeight;
		var elemLeft =  elem.offsetLeft ;
		var elemTop =  elem.offsetTop ;
		
		if ( width < ( elemLeft + elemWidth + (isIE ? 0 : 26) ) )
    	 elem.style.left = Math.max(0, (elemLeft - elemWidth) + (isIE ? 0 : 26));
	  else if ( !isIE )
			 elem.style.left = elemLeft + 26;
			 
		if ( height < ( elemTop + elemHeight + (isIE ? 0 : -10) ) ) 
		  	elem.style.top = Math.max(0, (elemTop - elemHeight) + (isIE ? 0 : -10)) ;
				else if ( !isIE )
				elem.style.top = Math.max(0, elemTop - 10);
 }
}

function hide( obj, idToShow )
{
 obj.style.backgroundColor = '';
 var elem = document.getElementById(idToShow);
 if ( elem != null )
 {
 		elem.style.display = 'none';
		elem.style.left = '';
		elem.style.top = '';
	}
}

function hover( img )
{
imagereplace( img, "select" );
}
function unhover( img )
{
imagereplace( img, "hover") ;
}
function imagereplace( img, action )
{
document.images[img].src = "images/"+img+"-" + action + ".jpg";
}

var id=null;
function delayedLoad( idTD ) {
				 clearLoad();
				 id = setTimeout('showSection("' + idTD + '")',500);
}
function clearLoad( ) {
				 if (id != null ) 
				 		clearTimeout(id); 
 
}
function resetStart( )

{

  var saUrl = document.URL.split('?');

  if ( saUrl.length > 1 )

   	 show( saUrl[1] );

}



function showSection( idToShow )

{

 var obj = document.getElementById( idToShow + "_td" );

 var elem = document.getElementById(idToShow);

 if ( obj != null && elem != null )

 {

    // clear siblings

		for ( var curr = elem.parentNode.firstChild; curr != null ; curr = curr.nextSibling )

		{

		 if ( curr.tagName == 'DIV' )

		 		curr.style.display = 'none';

		} 

 		elem.style.display = 'block';

		//reset sibling backgrounds 

		for ( var divs = obj.parentNode.firstChild; divs != null ; divs = divs.nextSibling )

		{

		 if ( divs.tagName == 'TD' )

				divs.style.backgroundColor = '';

		} 

		obj.style.backgroundColor = '#ededed';

 }

}
