var sep = '@'
var e_mail = new Array('sales', 'info', 'support', 'pete.jecker');
var domName = 'quiiq';
var domExt = 'com';

/**************************************
 * MAIN MENU
 **************************************/

function initMaps() {
   if (document.getElementById) {
      var mapIds = initMaps.arguments;    // pass string IDs of containing map elements
      var i, j, area, areas;
      for (i = 0; i < mapIds.length; i++) {
        areas = document.getElementById(mapIds[i]).getElementsByTagName("area");

        for (j = 0; j < areas.length; j++) {  // loop thru area elements
           area = areas[j];
           //area.onmousedown = imgSwap;
           area.onmouseout = imgSwap;    // set event handlers
           area.onmouseover = imgSwap;
           //area.onmouseup = imgSwap;
        }
      }
   }
}

// image swapping event handling
function imgSwap(evt) {
   evt = (evt) ? evt : event;                   // equalize event models
   var elem = (evt.target) ? evt.target : evt.srcElement;
   var imgClass = elem.parentNode.name.substr(0, elem.parentNode.name.length - 3);         // get map element name
   var coords = elem.coords.split(",");         // convert coords to clip
   var clipVal = "rect(" + coords[1] + "px " +
                           coords[2] + "px " +
                           coords[3] + "px " +
                           coords[0] + "px)";
                           
   var idx = parseInt(elem.getAttribute('idx'));
   
   var imgStyle;
   
   switch (evt.type) {
      /*case "mousedown" :
         imgStyle = document.getElementById(imgClass + "Down").style;
         imgStyle.clip = clipVal;
         imgStyle.visibility = "visible";
         break;/**/
      case "mouseout" :
         //document.getElementById(imgClass + "Hilite").style.visibility = "hidden";
         launchSubmenuTimeout();
         //document.getElementById(imgClass + "Selected").style.visibility = "hidden";
         break;
      case "mouseover" :
         //document.getElementById(imgClass + "Selected").style.visibility = "hidden";
         imgStyle = document.getElementById(imgClass + "Hilite").style;
         imgStyle.clip = clipVal;
         imgStyle.visibility = "visible";
         stopSubmenuTimeout();
         buildSubmenu(idx);
         break;
      /*case "mouseup" :
         document.getElementById(imgClass + "Down").style.visibility = "hidden";
         // guarantee click in IE
         if (elem.click) {
             elem.click();
         }
         break;/**/
   }
   evt.cancelBubble = true;
   return false;
}

function showWhereIam(menumap, idx)
{
    var areas;
    areas = document.getElementById(menumap).getElementsByTagName("area");

    var coords = areas[idx].coords.split(",");
    var clipVal = "rect(" + coords[1] + "px " +
        coords[2] + "px " +
        coords[3] + "px " +
        coords[0] + "px)";
    var imgStyle = document.getElementById('menuImgSelected').style;

    imgStyle.clip = clipVal;
     imgStyle.visibility = "visible";
}

function openSlideShow(sec)
{
    var url = '/slideshow.aspx';
    
    if(sec != null && sec == 'movies')
        url = '/slideshow.aspx?show=m';
    
    var x = (screen.availWidth - 800) / 2;
    var y = (screen.availHeight - 457) / 2;
    
    window.open(url,'ApplicationWindow','screenX=' + x + ',left=' + x + ',screenY=' + y + ',top=' + y + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,fullscreen=0,width='+ (800) +',height='+  (457) );
}

function setSitePath(p)
{
    var parts = p.split('>');
    
    var i = 0;
    var html = parts[0];
    for(i = 1; i < parts.length; i++)
    {
        if(parts[i] != '')
            html += '&nbsp;&nbsp;<img border="0" src="/images/path_separator.png" align="absmiddle" />&nbsp;&nbsp;' + parts[i];
    }
    var obj = document.getElementById('sitePath');
    
    if(obj && obj != null)
    {
        obj.innerHTML = html;
    }
}

function contactMail(idx)
{
    var url = 'mailto:';
    
    url += e_mail[idx] + sep + domName + '.' + domExt;
    
    var x = 0;
    var y = 0;
    
    window.location = url;
    
    //var openedWindow = window.open(url,'ApplicationWindow','screenX=' + x + ',left=' + x + ',screenY=' + y + ',top=' + y + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,fullscreen=0,width='+ (50) +',height='+  (50) );
}

/******************************************
 * SUB-MENU ITEMS
 ******************************************/

function SubMenuItem(txt, icon, link, notLink)
{
    this.ItemText = txt;
    this.ItemIcon = icon;
    this.ItemLink = link;
    this.NotLink = notLink;
}

var aboutSubMenu = new Array(
        new SubMenuItem(':: Company Profile', '', '/about.aspx', false),
        new SubMenuItem(':: Mission &amp; Goals', '', '/about.aspx?option=mission', false),
        new SubMenuItem(':: Leadership Team', '', '/about.aspx?option=leadership', false),
        new SubMenuItem(':: Ditribution &amp; Products', '', '/about.aspx?option=investors', false),
        new SubMenuItem(':: Job Opportunities', '', '/about.aspx?option=job', false),
        new SubMenuItem('Associations', '', '', true),
        new SubMenuItem(':: CEDT', '', '/about.aspx?option=cedt', false),
        new SubMenuItem('Initiatives', '', '', true),
        new SubMenuItem(':: Green Commitment', '', '/about.aspx?option=green', false),
        new SubMenuItem(':: QREN', '', '/about.aspx?option=qren', false),
        new SubMenuItem('Certifications', '', '', true),
        new SubMenuItem(':: Microsoft Certified Partner', '', '/about.aspx?option=mscert', false));

var productsSubMenu = new Array(
        new SubMenuItem(':: QUiiQ Automation', '', '/products.aspx', false),
        new SubMenuItem(':: QUiiQ Movies', '', '/products.aspx?option=movies', false),
        new SubMenuItem(':: QUiiQ Studio', '', '/products.aspx?option=studio', false),
        new SubMenuItem('For domotic protocols', '', '', true),
        new SubMenuItem(':: QUiiQ IDOM', '', '/products.aspx?option=idom', false),
        new SubMenuItem(':: QUiiQ Comfort', '', '/products.aspx?option=comfort', false),
        new SubMenuItem(':: QUiiQ KNX', '', '/products.aspx?option=knx', false),
        new SubMenuItem(':: QUiiQ Domintell', '', '/products.aspx?option=domintell', false),
        new SubMenuItem(':: QUiiQ CARDIO', '', '/products.aspx?option=cardio', false),
        //new SubMenuItem(':: QUiiQ VELBUS', '', '/products.aspx?option=velbus', false),
        new SubMenuItem('Hardware', '', '', true),
        new SubMenuItem(':: MAGNATE Media Centers', '', '/products.aspx?option=magnate', false),
        new SubMenuItem(':: Touch Panels', '', '/products.aspx?option=touch', false));

var solutionsSubMenu = new Array(
        new SubMenuItem(':: Residential', '', '/solutions.aspx', false),
        new SubMenuItem(':: Healthcare', '', '/solutions.aspx?option=healthcare', false),
        new SubMenuItem(':: Commercial Solutions', '', '/solutions.aspx?option=commercial', false),
        new SubMenuItem(':: Conference Rooms', '', '/solutions.aspx?option=conference', false),
        new SubMenuItem(':: Yatch', '', '/solutions.aspx?option=yatch', false),
        new SubMenuItem(':: Hotels', '', '/solutions.aspx?option=hotels', false),
        new SubMenuItem(':: Education', '', '/solutions.aspx?option=education', false),
        new SubMenuItem(':: Cultural', '', '/solutions.aspx?option=cultural', false),
        new SubMenuItem(':: Telecommunications', '', '/solutions.aspx?option=telecom', false),
        new SubMenuItem(':: Green projects', '', '/solutions.aspx?option=green', false),
        new SubMenuItem('References', '', '', true),
        new SubMenuItem(':: Vale Pis&atilde;o', '', '/solutions.aspx?option=pisao', false),
        new SubMenuItem(':: Kasa do Futuro', '', '/solutions.aspx?option=kasa', false));

/*var storeSubMenu = new Array(
        new SubMenuItem('QUiiQ MOVIES Store', '', '/movies/store.htm', false),
        new SubMenuItem('QUiiQ MAGNATE Store', '', '/movies/storehfx.htm', false),
        new SubMenuItem('Other Resellers', '', '/movies/resellers.htm', false));/**/

var salesSubMenu = new Array(
        new SubMenuItem(':: List of Dealer', '', '/sales.aspx', false),
        new SubMenuItem(':: Tech Partners', '', '/sales.aspx?option=dealers', false),
        new SubMenuItem(':: Showrooms', '', '/sales.aspx?option=partners', false),
        new SubMenuItem(':: Training', '', '/sales.aspx?option=training', false),
        new SubMenuItem(':: Become a Dealer', '', '/sales.aspx?option=becomedealer', false));

var pressSubMenu = new Array(
        new SubMenuItem(':: News &amp; Events', '', '/press.aspx', false),
        new SubMenuItem(':: Videos', '', '/press.aspx?option=videos', false),
        new SubMenuItem(':: QUiiQ Gallery', '', '/press.aspx?option=quiiq', false),
        new SubMenuItem(':: Automation Gallery', '', '/press.aspx?option=automation', false),
        new SubMenuItem(':: Movies Gallery', '', '/press.aspx?option=movies', false),
        new SubMenuItem(':: User Guides', '', '/press.aspx?option=guides', false),
        new SubMenuItem(':: Newsletter', '', '/press.aspx?option=newsletter', false));

var contactsSubMenu = new Array(
        new SubMenuItem(':: QUiiQ Contacts', '', '/contacts.aspx', false),
        new SubMenuItem(':: Customer Support', '', '/contacts.aspx?option=support', false),
        new SubMenuItem(':: Request for demo', '', '/contacts.aspx?option=demo', false)
        /*new SubMenuItem('QUiiQ Support', '', '/contacts.aspx?option=support'),
        new SubMenuItem('QUiiQ Contacts', '', '/contacts.aspx?option=quiiq'),
        new SubMenuItem('KNX Competence Center', '', '/contacts.aspx?option=knx')/**/);
        
var subMenus = new Array(null, aboutSubMenu, productsSubMenu, solutionsSubMenu, salesSubMenu, pressSubMenu, contactsSubMenu);

var subMenuTimer;
var subMenu;

function buildDDSubmenu(idx)
{
    var submenuObj = document.getElementById('submenu');
    
    var arr = subMenus[idx];
    
    if(arr != null)
    {
        var html = '<div onmouseover="stopSubmenuTimeout()" onmouseout="launchSubmenuTimeout()" style="width:auto;height:25px;margin-left:5px;"><nobr>';
        
        var i;
        for(i = 0; i < arr.length; i++)
        {
            if(i > 0)
            {
                html += '<a class="LinkWhite" style="line-height:30px;margin:0 10px 0 10px;">|</a>';
            }
            
            html += '<a class="LinkWhite" href="' + arr[i].ItemLink  +'" style="line-height:25px;">';
            if(arr[i].ItemIcon != '')
                html += '<img src="' + arr[i].ItemIcon + '" border="0" align="absmiddle" style="margin-right:10px;" />';
            html += arr[i].ItemText;
            html += '</a>';
        }
        html += '</nobr></div>';
        
        submenuObj.innerHTML = html;
    }
    else
    {
        submenuObj.innerHTML = '';
    }
}

function buildSubmenu(idx)
{
    var submenuObj = document.getElementById('submenu');
    
    var arr = subMenus[idx];
    
    var areas = document.getElementById('menuImgMap').getElementsByTagName("area");

    var coords = areas[idx].coords.split(",");
    var left = parseInt(coords[0], 10) - 1;
    
    if(arr != null)
    {
        var html = '<div onmouseover="stopSubmenuTimeout()" onmouseout="launchSubmenuTimeout()" style="position:absolute;top:-8px;left:' + left + ';z-index:9000;width:auto;height:auto;text-align:left;">';
        html += '<div style="background-color:#6694a5;background-image:url(/images/menu_tr_corner.gif);padding-top:5px;background-position:top right;background-repeat:no-repeat;border-left:solid 1px #001219;">';
        html += '<div style="background-color:#6694a5;background-image:url(/images/menu_right_border.gif);padding-bottom:4px;background-position:right;background-repeat:repeat-y;">';
        
        var i;
        for(i = 0; i < arr.length; i++)
        {
            if(i > 0)
            {
                html += '<br />';
            }
            
            if(!arr[i].NotLink)
            {
                html += '<nobr><a class="MenuLinkWhite" href="' + arr[i].ItemLink  +'" style="line-height:18px;display:block;padding:2px 13px 2px 10px;">';
                if(arr[i].ItemIcon != '')
                    html += '<img src="' + arr[i].ItemIcon + '" border="0" align="absmiddle" style="margin-right:10px;" />';
                html += arr[i].ItemText;
                html += '</a></nobr>';
            }
            else
            {
                html += '<nobr><a class="MenuLinkWhite" style="line-height:18px;display:block;padding:2px 13px 2px 10px;font-weight:bold;">';
                html += arr[i].ItemText;
                html += '</a></nobr>';
            }
        }
        html += '</div>';
        html += '</div>';
        
        //bottom border
        html += '<div style="right:0px;left:0px;text-align:center;">';
        html += '<div style="position:absolute;left:0;width:4;height:4px;background-image:url(/images/menu_bl_corner.gif);background-position:top left;background-repeat:no-repeat;"></div>';
        html += '<div style="position:absolute;margin:auto;left:4;right:3;background-image:url(/images/menu_bottom_border.gif);"><img src="/images/1x1.gif" align="absmiddle" height="4px" width="100%" /></div>';
        html += '<div style="position:absolute;right:0;width:4;height:4px;background-image:url(/images/menu_br_corner.gif);background-position:top right;background-repeat:no-repeat;"></div>';
        html += '</div>';
        
        
        html += '</div>';
        
        submenuObj.innerHTML = html;
    }
    else
    {
        submenuObj.innerHTML = '';
    }
}

function launchSubmenuTimeout()
{
    if(subMenuTimer != null)
    {
        clearTimeout(subMenuTimer);
        subMenuTimer = null;
    }
    
    subMenuTimer = setTimeout('hideSubmenu()', 500);
}

function stopSubmenuTimeout()
{
    if(subMenuTimer != null)
    {
        clearTimeout(subMenuTimer);
        subMenuTimer = null;
    }
}

function hideSubmenu()
{
    var submenuObj = document.getElementById('submenu');
    submenuObj.innerHTML = '';
    //document.getElementById("menuImgSelected").style.visibility = "visible";
    document.getElementById("menuImgHilite").style.visibility = "hidden";
}