/*
*	mo's browser checker
*	heavily based on the v1 library
*	mo / mircho@hotmail.com
*	please keep this note here
*/

//make a browser checker object
function cBrowser() {
	var userAgent = navigator.userAgent.toLowerCase()
	this.version = parseInt(navigator.appVersion)
	this.subVersion = parseFloat(navigator.appVersion)
	this.ns = ((userAgent.indexOf('mozilla')!=-1) && ((userAgent.indexOf('spoofer')==-1) && (userAgent.indexOf('compatible') == -1)))
	this.ns2 = (this.ns && (this.version == 2))
	this.ns3 = (this.ns && (this.version == 3))
	this.ns4b = (this.ns && (this.subVersion < 4.04))
	this.ns4 = (this.ns && (this.version == 4))
	this.ns5 = (this.ns && (this.version == 5))
	this.ie  = (userAgent.indexOf('msie') != -1)
	this.ie3 = (this.ie && (this.version == 2))
	this.ie4 = (this.ie && (this.version == 4) && (userAgent.indexOf('msie 4.')!=-1))
	this.ie5 = (this.ie && (this.version == 4) && (userAgent.indexOf('msie 5.0')!=-1))
	this.ie55 = (this.ie && (this.version == 4) && (userAgent.indexOf('msie 5.5')!=-1))
	this.ie6 = (this.ie && (this.version == 4) && (userAgent.indexOf('msie 6.0')!=-1))
	this.op = (userAgent.indexOf('opera') != -1)
	this.opv = ( parseInt( userAgent.substring( userAgent.indexOf('opera')+6 ) ) )
	this.op7 = ( this.op && this.opv >= 7 )
	this.win  = (userAgent.indexOf('win')!=-1)
	this.mac  = (userAgent.indexOf('mac')!=-1)
	this.unix = (userAgent.indexOf('x11')!=-1)
	this.name = navigator.appName
	this.dom = this.ns5 || this.ie5 || this.ie55 || this.ie6 || this.op7
}

var bw = new cBrowser()


//
// This script was created
// by Mircho Mirev
// mo /mo@momche.net/
//
//	:: feel free to use it BUT
//	:: if you want to use this code PLEASE send me a note
//	:: and please keep this disclaimer intact
//

//define the cEvent object
cDomEvent = {
	e 		: null,
	type	: '',
	button	: 0,
	key		: 0,
	x		: 0,
	y		: 0,
	pagex	: 0,
	pagey	: 0,
	target	: null,
	from	: null,
	to		: null
}

cDomEvent.init = function( e )
{
	if( bw.ie ) e = window.event
	this.e = e
	this.type = e.type
	this.button = ( bw.ns4 ) ? e.which : e.button
	this.key = ( bw.ns4 ) ? e.which : e.keyCode
	this.target = ( bw.ns ) ? e.target : e.srcElement
	this.from = ( bw.ns5 ) ? e.originalTarget : ( bw.ie ) ? e.fromElement : null
	this.to = ( bw.ns5 ) ? e.currentTarget : ( bw.ie ) ? e.toElement : null
	this.x = ( bw.ns ) ? e.layerX : e.offsetX
	this.y = ( bw.ns ) ? e.layerY : e.offsetY
	this.pageX = ( bw.ns ) ? e.pageX : e.x + document.body.scrollLeft
	this.pageY = ( bw.ns ) ? e.pageY : e.y + document.body.scrollTop
}

cDomEvent.addEvent = function( hElement, sEvent, handler, bCapture )
{
	if( hElement.addEventListener )
	{
		hElement.addEventListener( sEvent, handler, bCapture )
		return true
	}
	else if( hElement.attachEvent )
	{
		return hElement.attachEvent( 'on'+sEvent, handler )
	}
	else if( bw.ie4 || bw.ns4 )
	{
		if( bw.ns4 ) eval( 'hElement.captureEvents( Event.'+sEvent.toUpperCase()+' )' )
		eval( 'hElement.on'+sEvent+' = '+handler )
	}
	else
	{
		alert('Not implemented yet!')
	}
}

cDomEvent.removeEvent = function( hElement, sEvent, handler, bCapture )
{
	if( hElement.addEventListener )
	{
		hElement.removeEventListener( sEvent, handler, bCapture )
		return true
	}
	else if( hElement.attachEvent )
	{
		return hElement.detachEvent( 'on'+sEvent, handler )
	}
	else if( bw.ie4 || bw.ns4 )
	{
		eval( 'hElement.on'+sEvent+' = null' )
	}
	else
	{
		alert('Not implemented yet!')
	}
}


//Mouse button mapper object
function MouseButton()
{
	if( bw.ns4 )
	{
		this.left = 1
		this.middle = 2
		this.right = 3
	}
	else if( bw.ns5 )
	{
		this.left = 0
		this.middle = 1
		this.right = 2
	}
	else if( bw.ie )
	{
		this.left = 1
		this.middle = 4
		this.right = 2
	}
}

var MB = new MouseButton()



//
// This script was created
// by Mircho Mirev
// mo /mo@momche.net/
//
//	:: feel free to use it BUT
//	:: if you want to use this code PLEASE send me a note
//	:: and please keep this disclaimer intact
//

//additional info
//the activating link can have an attribute
//menu_callback
// which is a name of a function that will be called before the menu is shown
// it can test the cMoMenu.hLink var to check which is the link the Menu is activated for
// and must return an array with null or non null values
/*
 			return {	
						menuId : sID, //id of the new
						xOffset : 10, // x offset
						yOffset : null // y offset
					}
*/					

cMoMenu = {
	xOffset	:	0,
	yOffset	:	3,
	hideDelay :	800,
	nSteps : 8,
	nSpeed : 30,
	scrolling :	false
}

cMoMenu.onHideMenu = function() {}
cMoMenu.onShowMenu = function() {}

cMoMenu.showMenu = function( hLink, sMenuId )
{
	cMoMenu.hLink = hLink
	if( hLink.menuon == true )
	{
		return
	}
	else
	{
		this.hideMenu()
	}

	
	var nPosX = 0
	var nPosY = 0
	
	var sCallback = hLink.getAttribute( 'menu_callback' )
	if( sCallback != null && sCallback.toString().length > 0 )
	{
		var hRes = eval( sCallback+'()' )
		if( hRes.menuId )
		{
			sMenuId = hRes.menuId
		}
		if( hRes.xOffset )
		{
			nPosX += hRes.xOffset
		}
		if( hRes.yOffset )
		{
			nPosY += hRes.yOffset
		}
	}		
	
	hMenuInner = new getObject( sMenuId )
	bScrolling = cMoMenu.scrolling || ( hLink.getAttribute( 'menuscroll' ) == 'true' )
	if( bScrolling )
	{
		hMenuInner.hStyle.left = 0 + 'px'
		hMenuInner.hStyle.top = - hMenuInner.getHeight( ) + 'px'
	}
	else
	{
		hMenuInner.hStyle.left = 0 + 'px'
		hMenuInner.hStyle.top = 0 + 'px'
	}

	var hMenuDisplayItems = hLink.getAttribute( 'menu_displayitems' )
	if( hMenuDisplayItems != null && hMenuDisplayItems.toString().length > 0 )
	{
		sMenuDisplayItems = hMenuDisplayItems.toString()
		cMoMenu.filterItems( hMenuInner, sMenuDisplayItems )
	}	


	//find position of menu element
	//first get offset attributes
	var nOX = 0
	var nOY = 0
	var snOX = hLink.getAttribute( 'menu_xoffset' )
	var snOY = hLink.getAttribute( 'menu_yoffset' )
	if( snOX != null && snOX.toString().length > 0 )
	{
		nOX = new Number( snOX.toString() )
		nPosX += nOX
	}	
	if( snOY != null && snOY.toString().length > 0 )
	{
		nOY = new Number( snOY.toString() )
		nPosY += nOY
	}	
	
	nPosX += ( ( bw.ns4 ) ? hLink.x : getObject.getSize( 'offsetLeft', hLink ) ) + this.xOffset
	nPosY += ( ( bw.ns4 ) ? hLink.y : getObject.getSize( 'offsetTop', hLink ) ) + this.yOffset
	nPosY += ( ( bw.ns4 ) ? 0 : hLink.offsetHeight )
	
	var sT = getObject.getScrollOffset( 'Top', hLink )
	nPosY -= sT
	var sL = getObject.getScrollOffset( 'Left', hLink )
	nPosX -= sL
	
	cMoMenu.onShowMenu()
	
	var hMenu = new getObject( sMenuId+'Container' )
	hMenu.hStyle.left = nPosX + 'px'
	hMenu.hStyle.top = nPosY + 'px'
	hMenu.hStyle.width = hMenuInner.getWidth( )
	hMenu.hStyle.height = hMenuInner.getHeight( )
	hMenu.hStyle.visibility = "visible"
	hMenu.hLink = hLink
	hMenu.hLink.menuon = true

	//if it's a scrolling menu - start the scroll
	if( bScrolling && !hMenu.mover )
	{
		hMenu.mover = new mover( hMenuInner )
		hMenu.mover.glideTo( 0, 0, cMoMenu.nSteps, cMoMenu.nSpeed )
	}

	//set a special class for the mouseover - emulate :hover
	sOC = hMenu.hLink.getAttribute( 'menuoverclass' )
	if( sOC )
	{
		hMenu.hLink.className = sOC
	}
	
	//capture events
	if( bw.ns4 )
	{
		hMenu.hElement.captureEvents( Event.MOUSEOUT || Event.MOUSEOVER )
	}

	cDomEvent.addEvent( hLink, 'mouseout', cMoMenu.startHide, false )
	cDomEvent.addEvent( hLink, 'mouseover', cMoMenu.stopHide, false )
	cDomEvent.addEvent( hMenu.hElement, 'mouseover', cMoMenu.stopHide, false )
	cDomEvent.addEvent( hMenu.hElement, 'mouseout', cMoMenu.startHide, false )
	
	window.moMenu = hMenu
}

//will only display menu items from the menu_displayitems node attribute list
//which in fact is a coma separated list of ids on A tags inside the menu
cMoMenu.filterItems = function( hMenuContainer, sList )
{
	var hMenuEl = null
	var hLinks = hMenuContainer.hElement.getElementsByTagName( 'a' )
	for( var nI = 0; nI < hLinks.length; nI++ )
	{
		hMenuEl = hLinks.item( nI )
		if( hMenuEl.id && sList.indexOf( hMenuEl.id ) >=0 )
		{
			hMenuEl.style.display = 'block'
		}
		else
		{
			hMenuEl.style.display = 'none'
		}
	}
}

cMoMenu.hideMenu = function()
{
	cMoMenu.stopHide()
	hMenu = window.moMenu
	if( hMenu != null )
	{
		if( hMenu.mover )
		{
			hMenu.mover.stop()
		}
		sOC = hMenu.hLink.getAttribute( 'menuoutclass' )
		if( sOC )
		{
			hMenu.hLink.className = sOC
		}
		cDomEvent.removeEvent( hMenu.hLink, 'mouseout', cMoMenu.startHide, false )
		hMenu.hStyle.visibility = "hidden"
		hMenu.hLink.menuon = false
		window.moMenu = null
		cMoMenu.onHideMenu()
	}
}

cMoMenu.startHide = function()
{
	if( cMoMenu.hideTimeout != null ) {	return; }
	cMoMenu.hideTimeout = setTimeout( "cMoMenu.hideMenu()", cMoMenu.hideDelay )
}

cMoMenu.stopHide = function()
{
	clearTimeout( cMoMenu.hideTimeout )
	cMoMenu.hideTimeout = null
}

cMoMenu.doActivate = function( e )
{
	hLink = cMoMenu.getMenuElement( e )
	if( hLink != null )
	{
		var sMenu = hLink.getAttribute( 'menu' )
		cMoMenu.showMenu( hLink, sMenu )
	}
}

cMoMenu.install = function()
{
	cDomEvent.addEvent( document, 'mouseover', cMoMenu.doActivate, false )
}

cMoMenu.install()

//helper functions

cMoMenu.getMenuElement = function( hEvent )
{
	if( hEvent == null )
	{
		hEvent = window.event
	}
	hElement = ( hEvent.srcElement ) ? hEvent.srcElement : hEvent.originalTarget

	if( hElement == null )
	{
		return null
	}
	try
	{
		if( typeof hElement.tagName == 'undefined' ) return null
	}
	catch( hException )
	{
		return null
	}
	while( ( hElement.tagName ) && !( /(body|html)/i.test( hElement.tagName ) ) )
	{
		//opera strangely returns non null result sometimes
		sAttr = hElement.getAttribute( 'menu' )
		if( sAttr != null && sAttr.toString().length > 0 )
		{	
			return hElement
		}
		hElement = hElement.parentNode
	}
	return null 
}


//misc objects
//a simple encapsulation object

function getObject( sId )
{
	if( bw.dom )
	{
		this.hElement = document.getElementById( sId )
		this.hStyle = this.hElement.style
	}
	else if( bw.ns4 )
	{
		this.hElement = document.layers[ sId ]
		this.hStyle = this.hElement
	}
	else if( bw.ie )
	{	
		this.hElement = document.all[ sId ]
		this.hStyle = this.hElement.style
	}
	
}

getObject.prototype.getWidth = function( )
{
	return ( bw.ie4 ) ? this.hElement.pixelWidth : this.hElement.offsetWidth
}

getObject.prototype.getHeight = function( )
{
	return ( bw.ie4 ) ? this.hElement.pixelHeight : this.hElement.offsetHeight
}

getObject.prototype.getLeft = function()
{
	if( bw.ie4 ) return this.hElement.style.pixelLeft
	if( bw.ns4 || bw.dom ) 
	{
		if( this.hElement.style.left.length == 0 )
		{
			return parseInt( this.hElement.style.offsetLeft )
		}
		else
		{
			return parseInt( this.hElement.style.left )
		}
	}
}

getObject.prototype.getTop = function( )
{
	if( bw.ie4 ) return this.hElement.style.pixelTop
	if( bw.ns4 || bw.dom ) 
	{	
		if( this.hElement.style.top.length == 0 )
		{
			return parseInt( this.hElement.style.offsetTop )
		}
		else
		{
			return parseInt( this.hElement.style.top )
		}
	}
}

getObject.getSize = function( sParam, hLayer )
{
	nPos = 0
	while( hLayer != null )
	{
		nPos += eval( 'hLayer.' + sParam )
		hLayer = hLayer.offsetParent
	}
	return nPos
}

getObject.getScrollOffset = function( sParam, hLayer )
{
	nPos = 0
	while( hLayer != null && hLayer.tagName.toLowerCase() != 'body' )
	{
		nPos += eval( 'hLayer.scroll' + sParam )
		hLayer = hLayer.parentNode
	}
	return nPos
}



//
// This script was created
// by Mircho Mirev
// mo /mo@momche.net/
//
//	:: feel free to use it BUT
//	:: if you want to use this code PLEASE send me a note
//	:: and please keep this disclaimer intact
//

function point( nX, nY )
{
	this.x = nX
	this.y = nY
}

function mover( hLayer )
{
	this.name = 'mover' + (mover.nCount++)
	this.aPath = new Array()
	this.aSpeed = 0
	this.nSteps = 0
	this.nPos = 0
	this.bMoving = false
	this.hTimeout = null
	this.obj = this.name
	eval( this.obj + '=this' )

	this.setLayer( hLayer )
}
mover.nCount = 0

mover.prototype.setLayer = function( hLayer )
{
	if( hLayer != null )
	{
		this.hLayer = hLayer
	}
}


mover.prototype.moveTo = function( x, y )
{
	sPx = ( bw.ns5 || bw.ie ) ? 'px' : ''
	this.hLayer.hElement.style.left = x + sPx
	this.hLayer.hElement.style.top = y + sPx
}

mover.prototype.onStop = function()
{
}

mover.prototype.onStart = function()
{
}

mover.prototype.play = function()
{
	if( !this.bMoving ) return
	this.onStart()
	//this.hLayer.moveTo( this.aPath[this.nPos].x, this.aPath[this.nPos].y )
	this.moveTo( this.aPath[this.nPos].x, this.aPath[this.nPos].y )
	this.nPos++
	if( this.nPos < this.nSteps )
	{
		this.hTimeout = setTimeout( this.obj+'.play()', this.nSpeed )
	}
	else
	{
		this.stop()
	}
}

mover.prototype.stop = function()
{
	clearTimeout( this.hTimeout )
	this.hTimeout = null
	this.bMoving = false
	this.onStop()
}

mover.prototype.slideTo = function( nX, nY, nInc, nSpeed )
{
	if( this.bMoving )
	{
		this.stop()
	}
	var dX = nX - this.hLayer.getLeft()
	var dY = nY - this.hLayer.getTop()
	if( this.initSlide( nX, nY, dX, dY, nInc, nSpeed ) )
	{
		this.bMoving = true
		this.play()
	}
}

mover.prototype.initSlide = function( nX, nY, dX, dY, nInc, nSpeed )
{
	this.nPos = 0
	this.nSpeed = nSpeed
	var nT = Math.sqrt( Math.pow(dX,2) + Math.pow(dY,2) ) / nInc
	this.nSteps = nT
	if( this.nSteps == 0 ) return false
	deltaX = dX/nT
	deltaY = dY/nT
	
	sX = this.hLayer.getLeft()
	sY = this.hLayer.getTop()
	for( var nI=0; nI<this.nSteps-1; nI++ )
	{
		sX += deltaX
		sY += deltaY
		this.aPath[nI] = new point( sX, sY )
	}
	this.aPath[nI] = new point( nX, nY )
	return true
}


mover.prototype.glideTo = function( nX, nY, nInc, nSpeed )
{
	if( this.bMoving )
	{
		this.stop()
	}
	var dX = nX - this.hLayer.getLeft()
	var dY = nY - this.hLayer.getTop()
	if( this.initGlide( nX, nY, dX, dY, nInc, nSpeed ) )
	{
		this.bMoving = true
		this.play()
	}
}

mover.prototype.initGlide = function( nX, nY, dX, dY, nAngleInc, nSpeed )
{
	this.nPos = 0
	this.nSpeed = nSpeed
	this.nSteps = 0
	
	var nW = Math.sqrt( Math.pow(dX,2) + Math.pow(dY,2) )
	if( nW == 0 ) return false

	var nEndAngle = 90

	sX = this.hLayer.getLeft()
	sY = this.hLayer.getTop()
	
	var nI = nAngleInc
	while( nI < nEndAngle )
	{
		this.nSteps++
		nC = nW*Math.sin( nI*Math.PI/180 )
		this.aPath[this.nSteps - 1] = new point( sX+dX*(nC/nW), sY+dY*(nC/nW) )
		nI += nAngleInc
	}
	this.aPath[this.nSteps - 1] = new point( nX, nY )
	return true
}

