// Copyright (C) Ofer Faigon 2005
is_MSIE = (navigator.appVersion.toLowerCase().indexOf('msie') != -1)

function is_point_in_circle(elem, x, y) {
	var w2 = elem.offsetWidth / 2
	var h2 = elem.offsetHeight / 2
	var dx = w2 - x
	var dy = h2 - y
	return (dx * dx + dy * dy <= w2 * h2)
}

// menu button hover/out handlers
function bh(imgnode) {
	chgimg(imgnode.id, 'h')
	mdrop(parseInt(imgnode.id.substring(imgnode.id.length-1))) // no need for click
}
function bo(imgnode) {
	chgimg(imgnode.id, 'n')
}

// circle (bubble) hover/out handlers
var now_in_crcl = null
function ch(imgnode, ee) {
	imgnode.onmousemove = crclmove
	imgnode.onmousemove(ee)
}
function co(imgnode) {
	imgnode.style.cursor = 'default'
	var btnid = 'btn' + imgnode.id.substring(imgnode.id.length - 1)
	chgimg(btnid, 'n')
	now_in_crcl = null
}
function crclmove(e) {
	var imgnode = this
	if (e == null) e = event; if (typeof(e.offsetX) == 'undefined') { e.offsetX = e.layerX; e.offsetY = e.layerY; }
	var btnnum = parseInt(imgnode.id.substring(imgnode.id.length - 1))
	var btnid = 'btn' + btnnum
	var inside = is_point_in_circle(imgnode, e.offsetX, e.offsetY)
	if (inside && now_in_crcl != btnid) {
		chgimg(now_in_crcl, 'n')
		now_in_crcl = btnid
		//imgnode.style.cursor = 'pointer'
		chgimg(btnid, 'h')
		mdrop(btnnum) // no need to click
	} else if (!inside && now_in_crcl == btnid) {
		now_in_crcl = null
		//imgnode.style.cursor = 'default'
		chgimg(btnid, 'n')
	}
}
function cmdrop(menunum) {
	if (now_in_crcl != null)
		return mdrop(menunum)
}

// menu item hover/out handlers
function mh(atag) {
	var imgid = 'i' + atag.id.substring(1)
	var imgnode = document.getElementById(imgid)
	if (!imgnode) return
	imgnode.src = "g1/da-anim.gif"
}
function mo(atag) {
	var imgid = 'i' + atag.id.substring(1)
	var imgnode = document.getElementById(imgid)
	if (!imgnode) return
	imgnode.src = "g1/dblarrow.gif"
}

// News hover/out handlers
function nh(atag) {
	atag.style.border = "1px solid orange"
	mh(atag)
}
function no(atag) {
	atag.style.border = "1px solid rgb(242,242,242)"
	mo(atag)
}

// Returns rgb1 if pct=0, rgb2 if pct=100, weighted average in between.
function avg_rgb(rgb1, rgb2, pct) {
	var result = new Array()
	for (i = 0; i < rgb1.length; i++)
		result.push(Math.floor(rgb1[i] + pct * (rgb2[i] - rgb1[i]) / 100))
	return result
}

var faded_color = [242,242,242] // Text in this color is nearly invisible on our page bg
var hdr_full_color = [29,130,179] // The color we want the menu header to be in
var lnk_full_color = [89,68,134] // The color for the (unvisited) menu item links
var vst_full_color = [128,0,128] // The color for the visited menu item links
// Plug-in function for setting partial visibility of menus during the dimming/showing process
function mnu_dimmer(mnunum, pct, showing) {
	var elem = document.getElementById('dm' + mnunum)
	if (!elem)
		return
	for (var hdr = elem.firstChild; hdr && hdr.className != "mnuhdr"; hdr = hdr.nextSibling)
		;
	if (hdr) {
		var rgb = avg_rgb(faded_color, hdr_full_color, pct)
		hdr.style.color = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"
	}
	for (var guts = elem.firstChild; guts && (guts.className + "").substring(0,7) != "mnuguts"; guts = guts.nextSibling)
		;
	if (guts)
		guts.className = "mnuguts mg" + (pct + "").substring(0, (pct + "").length-1);
	if (showing && elem.style.visibility != 'visible')
		elem.style.visibility = 'visible'
	if (!showing && pct == 0)
		elem.style.visibility = 'hidden'
}
//document.tx = new trans(80, 15, 58, mnu_dimmer)
document.tx = new trans(30, 10, 58, mnu_dimmer)

// Write into the document the styles needed for dimming menus in 10% increments.
// To be called inside the page during load/parse (before the page is fully loaded,
// but after this JS file is in memory).
function docwritemnudimstyles() {
	document.write("<style type='text/css'>")
	for (var i = 0; i <= 10; i++) {
		var pct = i * 10;
		var lrgb = avg_rgb(faded_color, lnk_full_color, pct)
		var vrgb = avg_rgb(faded_color, vst_full_color, pct)
		document.write(".mg" + i + " A{color:rgb(" + lrgb[0] + "," + lrgb[1] + "," + lrgb[2] + ")}")
		document.write(".mg" + i + " A:visited{color:rgb(" + vrgb[0] + "," + vrgb[1] + "," + vrgb[2] + ")}")
	}
	document.write("</style>")
}

var currpressed = -1
function mdrop(menunum) {
	if (menunum != currpressed) {
		if (currpressed != -1)
			chgimg('bbl' + currpressed, 'n')
		if (menunum != -1)
			chgimg('bbl' + menunum, 'p')
		currpressed = menunum
	}
	document.tx.change_to(menunum)
	return false
}

halonum = 0
haloincr = 0
function l_on() {
	if (haloincr == 1)
		return
	if (haloincr == 0) {
		haloincr = 1
		setTimeout("dimmer()", 50)
	}
	haloincr = 1
}
function dimmer() {
	var haloimg = document.getElementById('halo')
	haloimg.src = "g1/halo" + halonum + "0.jpg"
	if (halonum + haloincr < 0 || halonum + haloincr > 10) {
		haloincr = 0
		return
	}
	halonum += haloincr
	setTimeout("dimmer()", 50)
}
function l_off() {
	if (haloincr == -1)
		return
	if (haloincr == 0) {
		haloincr = -1
		setTimeout("dimmer()", 50)
	}
	haloincr = -1
}


function mkpreload() {
	var names = new Array()
	i = 0
	var btnnames = ["articles", "downloads", "solutions", "expertise", "overview"]
	for (j = 0; j < btnnames.length; j++)
		names[i++] = "g1/btn-" + btnnames[j] + "-h.gif"
	for (j = 1; j <= 10; j++)
		names[i++] = "g1/halo" + j + "0.jpg"
	for (j = 1; j <= 5; j++)
		names[i++] = "g1/bbl-" + j + "p.gif"
	names[i++] = "g1/da-anim.gif"
	return names
}
prld = mkpreload()

function verth(obj) {
	obj.style.borderLeftColor = 'orange'
}
function verto(obj) {
	obj.style.borderLeftColor = 'rgb(240,240,240)'
}

// *** New code for news scroller: ***
function nwsover() {
	document.thenewsscroller.pause()
}

function nwsout() {
	document.thenewsscroller.resume()
}

function news_set_vis(elem_id, tx_percent, is_top, is_showing) {
	var elem = document.getElementById('nws' + elem_id)
	if (! elem)
		return
	h = parseInt(elem.parentNode.offsetHeight)
	if (is_top) {
		elem.style.top = Math.floor(-tx_percent * h / 100) + "px"
	} else {
		elem.style.top = Math.floor(h + -tx_percent * h / 100) + "px"
	}
	if ((tx_percent == 100 && is_top) || (tx_percent == 0 && !is_top))
		elem.style.visibility = 'hidden'
	else
		elem.style.visibility = 'visible'
}

function myinit() {
	init()
	document.thenewsscroller = new Tx3Obj(50, 8, news_set_vis)
	nxtnws()
}

var currnws = 0
var nxtnwstmr = null
function nxtnws() {
	nxtnwstmr = null
	if (! document.thenewsscroller.is_paused()) {
		currnws++
		if (currnws > 3) currnws = 1
		document.thenewsscroller.show(currnws)
	}
	nxtnwstmr = setTimeout("nxtnws()", 7000)
}
// *** end of new code ***
