﻿var dropdownVisible = 2;

function addProductDropdownEvents() {
    addEvents("gn-products","productDropdown");
    addEvents("gn-downloads", "downloadDropdown");
    addEvents("gn-advantages", "m_advDropdown");
    addEvents("gn-news", "m_newsDropdown");
    addEvents("gn-about", "m_aboutDropdown");
    addEvents("gn-store", "m_storeDropdown");
    
    // ... add more
}
function setDefaultViews() {
    setDefaultView("productDropdown");
    setDefaultView("downloadDropdown");
    setDefaultView("m_advDropdown");
    setDefaultView("m_newsDropdown");
    setDefaultView("m_aboutDropdown");
    setDefaultView("m_storeDropdown");

    // ... add more
}



function addEvents(item,dropdown)
{
    var t=document.getElementById(item);
	if (t != null)
	{
		if (window.addEventListener)
		{
			t.addEventListener('mouseover', handleMouseOver, true);
			t.addEventListener('mouseout', handleMouseOut, true);
		}	   
		if (window.attachEvent)
		{
			t.attachEvent('onmouseover', handleMouseOver);
			t.attachEvent('onmouseout', handleMouseOut);
		}
	}

	var t=document.getElementById(dropdown);
	if(t!=null) {
	    if(window.addEventListener) {
	        t.addEventListener('mouseover',handleMouseOver,true);
	        t.addEventListener('mouseout',handleMouseOut,true);
	    }
	    if(window.attachEvent) {
	        t.attachEvent('onmouseover',handleMouseOver);
	        t.attachEvent('onmouseout',handleMouseOut);
	    }
	}
}

function handleMouseOver(e) {
    if(e==null) e = window.event;

    var t = e.target;
    if (t==null) t = e.srcElement;
    
    t = getDropDown(t);
    if(t==null) {
        return;
    }
        
    dropdownVisible=2;
    t.style.display="block";
    hideIE6DropDowns(true);
}

function handleMouseOut(e) {
    if(e==null) e=window.event;

    var t=e.target;
    if(t==null) t=e.srcElement;

    t=getDropDown(t);
    if(t==null) return;
    
    dropdownVisible=1;
    t.style.display="none";
    hideIE6DropDowns(false);
    setTimeout(setDefaultViews,1000);
}

function getDropDown(e) {
    var t = e;
    while (t!=null && t.getAttribute("dropdownid")==null) {
        t = t.parentNode;
    }
    
    if (t!=null) {
        var id=t.getAttribute("dropdownid");
        return document.getElementById(id);
    }
    return null;
}

function changeContent(name, whichcontent){
    if(document.getElementById(name+"Default"))
	    document.getElementById(name+"Default").style.display="none";

    if(document.getElementById(name+"ProductView"))
	    if(document.getElementById(name+"ProductView").style.display="none")
		    document.getElementById(name+"ProductView").style.display="inline";

    if(document.getElementById(name+"Screenshot"))
	    if(document.getElementById(name+"Screenshot").style.display="none")
		    document.getElementById(name+"Screenshot").style.display="inline";

    	
    if (document.all||document.getElementById){
        cross_el=document.getElementById?document.getElementById(name+"_screenshots"):document.all.screenshots;
	    cross_el.innerHTML=whichcontent;
    }
}

function changeDesc(name, whichdesc){
	if (document.all||document.getElementById){
	    cross_el=document.getElementById?document.getElementById(name+"_descriptions"):document.all.descriptions;
	    cross_el.innerHTML=whichdesc;
	}	
}

function changeLogo(name, whichdesc){
	if (document.all||document.getElementById){
	    cross_el=document.getElementById?document.getElementById(name+"_logos"):document.all.descriptions;
	    cross_el.innerHTML=whichdesc;
	}
}

//IE6 hack : <select/> elements always stay on top regardless of styling
function hideIE6DropDowns( hide ) {
	if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 6") >= 0 ) {
		var spanElements = document.getElementsByTagName( "span" );
		for (var i in spanElements) {
			if ( spanElements[i].className == "productsDDHide" ) spanElements[i].style.visibility = ( hide ) ? "hidden" : "inherit";
		}
	}
}


function setDefaultView(name){
    // name = productDropdown, downloadDropdown
	if (dropdownVisible == 1)
	{
		if(document.getElementById(name+"Default"))
			document.getElementById(name+"Default").style.display="inline";
		if(document.getElementById(name+"ProductView"))
			document.getElementById(name+"ProductView").style.display="none";
		if(document.getElementById(name+"Screenshot"))
			document.getElementById(name+"Screenshot").style.display="none";				
	}
} 