var items = [
[ 'Home', 'index.html' ],
[ 'Profile', 'profile.html' ],
[ 'Products', 'products.html', [
[ 'Pro Audio', 'http://www.lax-pro.com/', '_blank' ],
[ 'PA System', 'pa_system.html' ],
[ 'Stage Lighting System', 'stage.html' ],
[ 'Laser', 'laser.html' ],
] ],
[ 'Services', 'service4.html', [
[ 'Pro Audio', 'service4.html' ],
[ 'PA System', 'service3.html' ],
[ 'Stage Lighting System', 'service2.html' ],
[ 'Laser System', 'service1.html' ],
[ 'Sound Simulation & Design', 'service5.html' ],
      
      
] ],
[ 'Projects', 'project.html', [
[ 'LAX Projects', 'project.html' ],
[ 'DSPPA Projects', 'project1.html' ],
[ 'ViGO Projects', 'project2.html' ],
] ],
[ 'Customers', 'customer.html' ],
[ 'Contact Us', 'contact.html' ],
];

$(function() {
    var menu = $('#menu');
    var last = null;
    var item, submenu, subitem;
    for (i in items) {
	item = items[i];
	if(item[2]=="_blank") {
	    last = $('<span>').append( $('<a>').attr('id', 'menu_'+i).attr('href', item[1]).attr('target', item[2]).text(item[0]) );
	}else{
	    last = $('<span>').append( $('<a>').attr('id', 'menu_'+i).attr('href', item[1]).text(item[0]) );
	}
	if (item.length > 2) {
	    submenu = $('<div>').addClass('subMenu').attr('id', 'submenu_'+i).css('position', 'absolute');
	    for (j in item[2]) {
		subitem = item[2][j];
		if(subitem[2]=="_blank") {
		    submenu.append( $('<a>').addClass('menuItem').attr('href', subitem[1]).attr('target', subitem[2]).html('&bull; ' + subitem[0]).css('white-space', 'nowrap') );
		}else{
		    submenu.append( $('<a>').addClass('menuItem').attr('href', subitem[1]).html('&bull; ' + subitem[0]).css('white-space', 'nowrap') );
		}
	    }
	    last.append(submenu);
	    submenu.css('display', 'none');

	    last.mouseover(function(e) {
		var a = $(e.currentTarget).children('a');
		var id = a.attr('id');
		var n = id.substr(id.indexOf('_')+1);
		var o = a.offset();
		clearTimeout(window['menu_timeout_'+n]);
		if ($('#submenu_'+n).is(':animated')) return;
		$('#submenu_'+n).css('left', o.left + 'px').css('top', (o.top + a.height()) + 'px').slideDown();
	    }).mouseout(function(e) {
		var id = $(e.currentTarget).children('a').attr('id');
		var n = id.substr(id.indexOf('_')+1);
		clearTimeout(window['menu_timeout_'+n]);
		window['menu_timeout_'+n] = setTimeout(function() {
		    $('#submenu_'+n).fadeOut(300);
		}, 200);
	    });
	}
	menu.append(last);
	last.addClass('menuItem');
    }
    if (last) last.addClass('last');
});
