function nrs_init(){
   
    var ultags=document.getElementById('nrs_menu').getElementsByTagName('ul');
    for (var t=0; t < ultags.length; t++)
    {
            var pNode = ultags[t].parentNode;
            pNode.theMenuUl = pNode.getElementsByTagName('ul')[0];
            pNode.theMenuA = pNode.getElementsByTagName('a')[0];
            
    	    pNode.onmouseover = function()
    	    {
    	        this.theMenuUl.style.top=(this.offsetHeight - 1)+'px';
    	        this.theMenuUl.style.visibility='visible';
    	        this.theMenuA.className = 'nrs_menuth';
    	    };
    	    
    	    pNode.onmouseout = function()
    	    {
			    this.theMenuUl.style.visibility='hidden';
			    this.theMenuA.className = '';
            };
    }

}

nrs_init();




// BLENDING/OPACITY LIBRARY

function site_opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 1000);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("site_changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("site_changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////
//change the opacity for different browsers
function site_changeOpac(opacity, id, tim) {
	var object = document.getElementById(id).style; 
	var m = opacity / 100;
	object.opacity =  m;//m == 1 ? 0.9999999 : m;
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		site_opacity(id, 0, 100, millisec);
	} else {
		site_opacity(id, 100, 0, millisec);
	}
}


function site_blendimage(divid, imageid, imagefile, millisec) {
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	site_changeOpac(0, imageid);
	window.setTimeout(function() {fn_continueBlend(imageid, imagefile, millisec);}, 100); // this fixes firefox flicker
}
function fn_continueBlend(imageid,imagefile, millisec)
{
    var scale = 1;
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //make new image
	document.getElementById(imageid).src = imagefile;
    
    
	for(i = 0; i <= 100/ scale; i++) {
		setTimeout("site_changeOpac(" + i*scale + ",'" + imageid + "')",(timer * speed));
		timer+=scale;
	}
}


function site_currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	site_opacity(id, currentOpac, opacEnd, millisec);
}

///////////////////////////////////////////////////////////////
// CUSTOMERS SHOW

   
var currentImageIndex = 0;
var custImagePrefix = "img/logos/";

function changeCustomerImage() 
{
    

    
    //window.customerImg.src = ;
    site_blendimage('customerDiv','customerImg', logosData[0] + logosData[2][currentImageIndex] + logosData[1],200);
    

    window.setTimeout(changeCustomerImage, 3000);
    site_preloadNext();
    
    currentImageIndex++;
    if (currentImageIndex > logosData[2].length - 1) {
        currentImageIndex = 0;
    }    

}

function site_preloadNext() {
    if (!window.logosData || currentImageIndex > logosData[2].length - 2) return;
    
    var from = 1;
    var to = 0;
    
    if (currentImageIndex==0)
    {
        from = 1;
        to = 1;
    }
    if (currentImageIndex==1)
    {
        from = 2;
        to = 4;
    }  
    else if (currentImageIndex==4)
    {
        from = 5;
        to = 20; 
    }
    else if (currentImageIndex==20)
    {
        from = 21;
        to = 40; 
    }
    else if (currentImageIndex==40)
    {
        from = 41;
        to = 60; 
    }
    else if (currentImageIndex==60)
    {
        from = 61;
        to = 80; 
    }
    else if (currentImageIndex==80)
    {
        from = 81;
        to = 100; 
    }
    else if (currentImageIndex==100)
    {
        from = 101;
        to = 200; 
    }
      
    
    for(var i = from; (i <= logosData[2].length - 1) && (i <= to); i++)
    {
        var img = new Image();
        img.src = logosData[0] + logosData[2][i] + logosData[1];
    }
}


function gv_rhover(row, href)
{
    if (!row.onmouseout)
    {
        row.onmouseout = function() {row.className = '';}; 
        if (href)
            row.onclick = function() {window.location = href;};
    }
    row.className = 'hover';
}
