
var immo = {
    
    
    // TODO: bind config.xml -> JSON
    
	lang: "en",
	
    config: {
        
        navigation: [
                     
            { title: "About us", url: "company_about.html",
                items: [
                    { title: "Products and services",   url: "company_activity.html" },
                    { title: "Certificates",            url: "company_awards.html" },
                    { title: "Milestones",              url: "company_history.html" },
                    { title: "Coverage area",           url: "company_area.html" },
                    { title: "Licenses",                url: "company_legal.html" },
                    { title: "Quality control",         url: "company_qos.html" },
                    { title: "Our headquarter",         url: "company_contacts.html" }
                ] },
                
            { title: "News", url: "news_today.php",    items: [] },
            
            { title: "Products and services", url: "products_index.html",
                items: [
                    { title: "Portals",              url: "products_portals.html" },
                    { title: "Interactive projets",  url: "products_interactive.html" },
                    { title: "Mobile marketing",     url: "products_marketing.html" },
                    { title: "Content",              url: "products_content.html" }
                ] },
            
            { title: "High tech solutions", url: "tech_index.html",
                items: [
                    { title: "Our aggregation opportunities", url: "tech_aggregation.html" },
                    { title: "Platform solutions",            url: "tech_platforms.html" }
                ] },
                
            { title: "Partnership", url: "partners_index.html",
                items: [
                    { title: "Account list", url: "partners_list.html" }
                ] }
        ]
        
    },
    
    get: function(id) { return (immo.cache[id] ? immo.cache[id] : (immo.cache[id] = document.getElementById(id))); }, cache: {},
    
    MenuItem: {
            
        expanded: [],
            
        Create: function(n, selected) {
            var html;
            var p = new Image();
            var count = immo.config.navigation[n-1].items.length;
            var expanded = ((typeof selected) !== "undefined");

            html  = '<div id="item_{N}" class="item" title="'+immo.config.navigation[n-1].title+'" >';
            html += '<table cellspacing="0" cellpadding="0" border="0"><tr>';
//            html += '<td {RO}><a href="{A}"><img src="../img/menu/{LANG}/{N}.number.gif" class="number"/></a></td>';
            html += '<td {RO}><a href="{A}"><img src="../img/menu/empty.number.gif"/></a></td>';
            html += '<td><a href="{A}"><img id="{N}.title" src="../img/menu/{LANG}/{N}.title'+((selected===0) ? "a" : "")+'.gif" class="title" {RO}/></a>';
            p.src = '../img/menu/'+immo.lang+'/'+n+'.titlea.gif';  // Image preloading...
            
            if (count) {
            
                // Preview
                if (!expanded) {
                    html += '<div id="{N}.preview" class="preview">';
                    html += '<img src="../img/menu/{LANG}/{N}.preview.gif" {RO}/>';
                    html += '</div>';
                }
                
                // SubItems
                html += '<div id="{N}.subitems" class="subitems">';
                html += '<table cellspacing="0" cellpadding="0" border="0">';                
                for(var i=1; i<=count; i++) {
                    var item = immo.config.navigation[n-1].items[i-1];
                    var s = expanded && (selected==i);
                    if ((typeof item.disabled) == "undefined") {
                        html += '<tr>';
                        if (expanded) html += '<td width="10"><img src="../img/menu/'+(s ? 'select' : 'empty')+'.gif" /></td>';
                        html += '<td><a href="'+item.url+'" title="'+item.title+'"><img id="{N}.'+i+'" src="../img/menu/{LANG}/{N}.'+i+(s ? "a" : "")+'.gif"';
                        html += 'onmouseover="immo.MenuItem.onSubMouse({N}, '+i+', 1)" onmouseout="immo.MenuItem.onSubMouse({N},'+i+', 0)"/></a></td></tr>';
                        if (!s) p.src = '../img/menu/'+immo.lang+'/'+n+'.'+i+'a.gif';  // Image preloading...
                    }
                }                
                
                html += '</table></div>';
                
            }                        
            html += '</td></tr></table></div>';
            html = html.split('{RO}').join('onmouseover="immo.MenuItem.onMouse({N}, 1)" onmouseout="immo.MenuItem.onMouse({N}, 0)"');
            html = html.split('{N}').join(n);
			html = html.split('{LANG}').join(immo.lang);
            html = html.split('{A}').join(immo.config.navigation[n-1].url);
            
            immo.MenuItem.expanded[n] = [];
            immo.MenuItem.expanded[n].subCount = count;
            immo.MenuItem.expanded[n].expanded = expanded;
            immo.MenuItem.expanded[n][selected] = -1;
            
            document.write(html);

        },
        
        update: function(n) {
            if (immo.MenuItem.expanded[n].expanded) return;
            var s = immo.MenuItem.expanded[n];
            var v = 0;
            for(var i=0;i<s.length;i++) v = (v || s[i]);
            if (s.subCount) {
                immo.get(n+".preview").style.display  = (v ? "none" : "block");
                immo.get(n+".subitems").style.display = (v ? "block" : "none");
            }
        },
        
        onMouse: function(n, rollover) {
            if (immo.MenuItem.expanded[n][0]<0) return;
            immo.get(n+".title").src = "../img/menu/"+immo.lang+"/"+n+".title"+(rollover ? "a" : "")+".gif";
            immo.MenuItem.expanded[n][0] = rollover;
            immo.MenuItem.update(n);
        },
        
        onSubMouse: function(n, m, rollover) {
            if (immo.MenuItem.expanded[n][m]<0) return;
            document.getElementById(n+"."+m).src = "../img/menu/"+immo.lang+"/"+n+"."+m+(rollover ? "a" : "")+".gif";
            immo.MenuItem.expanded[n][m] = rollover;
            immo.MenuItem.update(n);
        }
        

    }
    
};


