﻿function GoogleSearchInputKeyPressed(btnId) 
{
    if (window.event.keyCode != 13) return;

    var btn = document.getElementById(btnId);
    if (btn == null) return;
    btn.fireEvent('onclick');
    window.event.returnValue = false;
}

function ToggleItem(item, display, background)
{
	try
	{
		if (typeof(item) == "string") 
			item = document.getElementById(item) ;
			
		if (typeof(item) == "undefined" || item == null)
			return ;
		
		item.style.display = display ;				

		while(item != null && item.tagName != "BODY" && item.tagName != "LI")
		{
			item = item.parentNode ;
		}
		if (item.tagName == "LI")
			item.style.backgroundImage = "url(../images/list-link-" + background + ".gif)" ;
	}
	catch (e)
	{
		alert(e) ;
	}
}

function ShowItem(top, item)
{
	if (typeof(top) == "string") 
		top = document.getElementById(top) ;
	if (typeof(top) == "undedined" || top == null)
		return ;
		
	if (top.CurrentItem != item)
	{
		ToggleItem(top.CurrentItem, "none", "closed") ;					
		top.CurrentItem = item ;				
		ToggleItem(item, "", "opened") ;
	}
}

function ToggleCollapser(h2)
{
	var div = h2.nextSibling ;
	
	if (div.style.display == "")
	{
		h2.className = "CollapserH" ;
		div.style.display = "none" ;
	}
	else
	{
		h2.className = "CollapserV" ;
		div.style.display = "" ;
	}
}

// For the Home Page

var features ;
var index ;
var timeout ;

function ShowNextItem(offset)
{
	if (timeout != null)
		clearTimeout(timeout) ;
		
	var current = features[index] ;

	index = (index + offset) ;
	
	if (index < 0)
		index = features.length-1 ;
	else if (index >= features.length)
		index = 0;
		
	var next = features[index] ;
	
	current.style.display = "none" ;
	next.style.display = "block" ;
	
	if (timeout != null)
		timeout = window.setTimeout("ShowNextItem(1)", 5000) ; // every 5 secondes
}

function PauseItems(stop, play)
{
	stop = document.getElementById(stop) ;
	play = document.getElementById(play) ;
	
	if (timeout == null)
	{
		play.style.display = "none" ;
		stop.style.display = "" ;
		timeout = window.setTimeout("ShowNextItem(1)", 5000) ; // every 5 secondes
	}
	else
	{
		play.style.display = "" ;
		stop.style.display = "none" ;
		clearTimeout(timeout);
		timeout = null ;
	}
}

window.onload = function(e) 
{
    features   = document.getElementsByName("feature-area-home");
    controller = document.getElementById("featureController") ;
    
    if (features == null || features.length == 0)
		return;

    if (features.length > 1) 
    {
        index = features.length - 1;
        timeout = window.setTimeout("ShowNextItem(1)", 1);
        if (controller != null)
			controller.style.display = "block" ;		
    }       
}
