// detect win/mac
var agent = navigator.userAgent.toLowerCase(); 
var is_mac = (agent.indexOf("mac") != -1);
var is_win = (agent.indexOf("win") != -1);
var is_ie =  (agent.indexOf("msie") != -1);


/* fill screen with window
window.onload = maxWindow;

function maxWindow()
{
window.moveTo(0,0);


if (document.all)
{
  top.window.resizeTo(screen.availWidth,screen.availHeight);
}

else if (document.layers||document.getElementById)
{
  if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
  {
    top.window.outerHeight = screen.availHeight;
    top.window.outerWidth = screen.availWidth;
  }
}
}
*/
// detect date

var d=new Date();
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//Ensure correct for language. English is "January 1, 2004"
var today = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();



// menus, Slide Menu-could go to JQuerySlideMenu
var gFlashVersion;

SlideMenu.Registry = [];
SlideMenu.aniLen = 300;
SlideMenu.hideDelay = 750;
SlideMenu.minCPUResolution = 10;

function SlideMenu(id, width, height)
{
	this.ie = document.all ? 1 : 0;
	this.ns4 = document.layers ? 1 : 0;
	this.dom = document.getElementById ? 1 : 0;

	if (this.ie || this.ns4 || this.dom)
	{
		this.id = id;
		this.dirType = "-";
		this.dim = height;
		this.hideTimer = false;
		this.aniTimer = false;
		this.open = false;
		this.over = false;
		this.startTime = 0;
		this.gRef = "SlideMenu_" + id;
		
		eval(this.gRef + "=this");
		SlideMenu.Registry[id] = this;
		
		var d = document;
		d.write('<style type="text/css">');
		d.write('#' + this.id + 'Container { visibility:hidden; ');
		d.write('left:' + 0 + 'px; ');
		d.write('top:' + 0 + 'px; ');
		d.write('overflow:hidden; }');
		d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; ');
		d.write('width:' + width + 'px; ');
		d.write('height:' + height + 'px; ');
		d.write('clip:rect(0 ' + width + 'px' + ' ' + height + 'px' + ' 0); ');
		d.write('}');
		d.write('</style>');
		
		this.load()
	}
}

SlideMenu.prototype.load = function()
{
	var d = document;
	var lyrId1 = this.id + "Container";
	var lyrId2 = this.id + "Content";
	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1];
	
	if (obj1)
	{
		var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2);
	}
	
	var temp;
	
	if (!obj1 || !obj2)
	{
		window.setTimeout(this.gRef + ".load()", 100);
	}
	else
	{
		this.container = obj1;
		this.menu = obj2;
		this.style = this.ns4 ? this.menu : this.menu.style;
		this.homePos = eval("0" + this.dirType + this.dim);
		this.outPos = 0;
		this.accelConst = (this.outPos - this.homePos) / SlideMenu.aniLen / SlideMenu.aniLen ;

		if (this.ns4)
		{
			this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		}
		
		this.menu.onmouseover = new Function("SlideMenu.showMenu('" + this.id + "')");
		this.menu.onmouseout = new Function("SlideMenu.hideMenu('" + this.id + "')");
		this.endSlide();
	}
}

SlideMenu.showMenu = function(id)
{
	var reg = SlideMenu.Registry;
	var obj = SlideMenu.Registry[id];

	if (obj.container)
	{
		obj.over = true;
		
		for (menu in reg)
		{
			if (id != menu)
			{
			    SlideMenu.hide(menu)
			}
		}

		if (obj.hideTimer)
		{
			reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer);
		}
			
		if (!obj.open && !obj.aniTimer)
		{
			reg[id].startSlide(true);
		}
	}
}

SlideMenu.hideMenu = function(id)
{
	var obj = SlideMenu.Registry[id];
	
	if (obj.container)
	{
		if (obj.hideTimer)
		{
			window.clearTimeout(obj.hideTimer);
		}
			
		obj.hideTimer = window.setTimeout("SlideMenu.hide('" + id + "')", SlideMenu.hideDelay);
	}
}

SlideMenu.hide = function(id)
{
	var obj = SlideMenu.Registry[id];
	obj.over = false;
	
	if (obj.hideTimer)
	{
		window.clearTimeout(obj.hideTimer);
	}
	
	obj.hideTimer = 0;
	
	if (obj.open && !obj.aniTimer)
	{
		obj.startSlide(false);
	}
}

SlideMenu.prototype.startSlide = function(open)
{
	this[open ? "onactivate" : "ondeactivate"]();
	this.open = open;
	
	if (open)
	{
		this.setVisibility(true);
	}
		
	this.startTime = (new Date()).getTime();
	this.aniTimer = window.setInterval(this.gRef + ".slide()", SlideMenu.minCPUResolution);
}

SlideMenu.prototype.slide = function()
{
	var elapsed = (new Date()).getTime() - this.startTime;
	
	if (elapsed > SlideMenu.aniLen)
	{
		this.endSlide();
	}
	else
	{
		var d = Math.round(Math.pow(SlideMenu.aniLen - elapsed, 2) * this.accelConst);
		
		if (this.open && this.dirType == "-")
		{
			d = -d;
		}
		else if (this.open && this.dirType == "+")
		{
			d = -d;
		}
		else if (!this.open && this.dirType == "-")
		{
			d = -this.dim + d;
		}
		else
		{
			d = this.dim + d;
		}
		
		this.moveTo(d);
	}
}

SlideMenu.prototype.endSlide = function()
{
	this.aniTimer = window.clearTimeout(this.aniTimer);
	this.moveTo(this.open ? this.outPos : this.homePos);
	
	if (!this.open)
	{
		this.setVisibility(false);
	}
	
	if ((this.open && !this.over) || (!this.open && this.over))
	{
		this.startSlide(this.over);
	}

}

SlideMenu.prototype.setVisibility = function(bShow)
{ 
	var s = this.ns4 ? this.container : this.container.style;
	s.visibility = bShow ? "visible" : "hidden";
}

SlideMenu.prototype.moveTo = function(p)
{
	this.style["top"] = this.ns4 ? p : p + "px";
}

SlideMenu.prototype.getPos = function(c)
{
	return parseInt(this.style[c]);
}

SlideMenu.prototype.onactivate = function()
{
}

SlideMenu.prototype.ondeactivate = function()
{
}

function PositionMenu(menu, item)
{
 	var newLeft = item.offsetLeft + 5 - 6;
	var newTop = item.offsetTop + 28 + 1;

	if (is_mac && is_ie)
	{
		newLeft -= 17;
		newTop -= 8;
	}
	
	for (var parent = item.offsetParent; parent != null; parent = parent.offsetParent)
	{
		newLeft = newLeft + parent.offsetLeft;
		newTop = newTop + parent.offsetTop;
	}
	
	menu.container.style ? menu.container.style.left = newLeft + "px" : menu.container.left = newLeft;
	menu.container.style ? menu.container.style.top = newTop + "px" : menu.container.top = newTop;
}
/* 
function UpdateBanner()
{
	var banner = document.getElementById("banner");
	if (banner != null)
	{
		// make sure we're not on mac with IE
		if (!is_mac || !is_ie)
		{
			var orgLeft = banner.offsetLeft;
			var orgTop = banner.offsetTop;

			for (var parent = banner.offsetParent; parent != null; parent = parent.offsetParent)
			{
				orgLeft += parent.offsetLeft;
				orgTop += parent.offsetTop;
			}

			var bannerLeft = document.getElementById("bannerleft");
			if (bannerLeft != null)
			{
				var left = orgLeft - bannerLeft.offsetWidth;
				var top = orgTop;

				bannerLeft.style ? bannerLeft.style.left = left + "px" : bannerLeft.left = left;
				bannerLeft.style ? bannerLeft.style.top = top + "px" : bannerLeft.top = top;
				bannerLeft.style ? bannerLeft.style.visibility = "visible" : bannerLeft.visibility = "visible";
			}
			
			var bannerBottom = document.getElementById("bannerbottom");
			if (bannerBottom != null)
			{
				var left = orgLeft;
				var top = orgTop + banner.offsetHeight;
				
				bannerBottom.style ? bannerBottom.style.left = left + "px" : bannerBottom.left = newLeft;
				bannerBottom.style ? bannerBottom.style.top = top + "px" : bannerBottom.top = top;
				bannerBottom.style ? bannerBottom.style.visibility = "visible" : bannerBottom.visibility = "visible";
			}
		}
		else
		{
			bannerLeft.style ? bannerLeft.style.visibility = "hidden" : bannerLeft.visibility = "hidden";
			bannerBottom.style ? bannerBottom.style.visibility = "hidden" : bannerBottom.visibility = "hidden";
		}
	}
}


*/

function ShowElement(element)
{
	if (element != null)
	{
		element.style ? element.style.visibility = "visible" : element.visibility = "visible";
		element.style ? element.style.position = "static" : element.position = "static";
	}
}

function HideElement(element)
{
	if (element != null)
	{
		element.style ? element.style.visibility = "hidden" : element.visibility = "hidden";
		element.style ? element.style.position = "absolute" : element.position = "absolute";
	}
}

/*
function ContactTypeChanged()
{
	var contactTypeSelect = document.getElementById("contactTypeSelect");
	if (contactTypeSelect != null)
	{
		var productSelect = document.getElementById("productSelect");
		var osSelect = document.getElementById("osSelect");
	
		switch (contactTypeSelect.value)
		{
			case "general":
			{
				HideElement(productSelect);
				HideElement(osSelect);
				
				break;
			}
				
			case "feedback":
			{
				ShowElement(productSelect);
				HideElement(osSelect);

				break;
			}
				
			case "feature":
			{
				ShowElement(productSelect);
				HideElement(osSelect);

				break;
			}
				
			case "product":
			{
				HideElement(productSelect);
				ShowElement(osSelect);

				break;
			}
			
			default:
			{
				HideElement(productSelect);
				HideElement(osSelect);

				break;
			}
		}
	}
}

function InitFlash()
{
	gFlashVersion = 0;

	for (var i = 10; i > 1; i--)
	{
		try
		{
			if (eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');"))
			{
				gFlashVersion = i;
				break;
			}
		}
		
		catch (e)
		{
		}
	}			
}			

function Update()
{
	UpdateBanner();
}

function Init()
{
	InitFlash();
	UpdateBanner();
}
*/
menu1 = new SlideMenu("menu1", 120, 300);
menu2 = new SlideMenu("menu2", 150, 300);
menu3 = new SlideMenu("menu3", 90, 300);
menu4 = new SlideMenu("menu4", 140, 300);
menu5 = new SlideMenu("menu5", 170, 300);
menu6 = new SlideMenu("menu6", 130, 300);
menu7 = new SlideMenu("menu7", 130, 300);
menu8 = new SlideMenu("menu8", 130, 300);

menu1.onactivate = function() { PositionMenu(menu1, document.getElementById("menuBarItem0")); }
menu2.onactivate = function() { PositionMenu(menu2, document.getElementById("menuBarItem1")); }
menu3.onactivate = function() { PositionMenu(menu3, document.getElementById("menuBarItem2")); }
menu4.onactivate = function() { PositionMenu(menu4, document.getElementById("menuBarItem3")); }
menu5.onactivate = function() { PositionMenu(menu5, document.getElementById("menuBarItem4")); }
menu6.onactivate = function() { PositionMenu(menu6, document.getElementById("menuBarItem5")); }
menu7.onactivate = function() { PositionMenu(menu7, document.getElementById("menuBarItem6")); }
menu8.onactivate = function() { PositionMenu(menu8, document.getElementById("menuBarItem7")); }


/*
function ValidateEmail()
{
    if (document.contactform.email.value == "" || document.contactform.email.value == "your email")
    {
        alert("Please enter your email address, so we can get back to you.");
        return false;
    }

    return true;
}

function ValidateContent()
{
    var text = contactform.text.value.toLowerCase();

    // check for empty form
    if (text == "")
    {
        alert("The contact form is empty.");
        return false;
    }

    // check for www.
    if (text.indexOf("www.") != -1)
    {
        alert("Please don't use links in the contact form text, such as www.something.com");
        return false;
    }

    var email = contactform.email.value;

    // check for email
    if (email == "" || email == "your email" || email.indexOf("@") == -1 || email.indexOf(".") == -1)
    {
        var result = confirm("Without your email address, we can't get back to you. Do you want to submit this form without providing your email address?");
        return result;
    }

    return true;
}

function ValidateNewsFormEmail()
{
    var email = document.newsform.email.value;

    // check for email
    if (email == "" || email == "your email" || email.indexOf("@") == -1 || email.indexOf(".") == -1)
    {
        alert("Please specify valid email address.");
        return false;
    }
    
    return true;
}

function ValidateRecommendation()
{
    // check for empty form
    if (document.contactform.text.value == "")
    {
        alert("The form is empty.");
        return false;
    }

    // check sender's emails
    if (document.contactform.sender.value == "" || document.contactform.sender.value == "your email")
    {
        alert("Sender's email is empty.");
        return false;
    }

    // check sender's emails
    if (document.contactform.recipient.value == "" || document.contactform.recipient.value == "recipient email")
    {
        alert("Recipient's email is empty.");
        return false;
    }

    return true;
}

function ValidateMifBetaForm()
{
    if (document.contactform.name.value == "")
    {
        alert("Please provide your name.");
        return false;
    }

    if (document.contactform.email.value == "")
    {
        alert("Please provide your email.");
        return false;
    }

    if (document.contactform.usage.value == "")
    {
        alert("Please provide your intended MIF Filter usage.");
        return false;
    }

    return true;
}
*/