var menu_data = ['link_service', 65, 'link_work', 48, 'link_who_we_are', 82, 'link_contact', 62, 'link_blog', 43]


$(function() {		  
	$("#nav a").hover(overHandler, outHandler);
});
 
function overHandler() {
	var id = $(this).attr('id');
	var new_width = get_menu_width(id);
	var div = $(this).children('div');
	div.stop();
	div.animate({width: new_width + 'px'}, 500);
	$(this).stop();
	$(this).animate({width: new_width + 'px'}, 500);
}

function outHandler() {
	var id = $(this).attr('id');
	if (current_hash_index > -1) {
		if (menu_data[current_hash_index * 2] == id) {
			return;
		}
	}

	var div = $(this).children('div');
	div.stop();
	div.animate({width: '0px'}, 500);
	$(this).stop();
	$(this).animate({width: '0px'}, 500);
}

function get_menu_width(id) {
	for(var i=0; i<menu_data.length; i+=2) {
		if (id == menu_data[i]) {
			return menu_data[i+1];	
		}
	}
}

function menu_update() {
	//current_hash_index
	for (i=0; i<5; i++) {
		if (i == current_hash_index) {
			overID(menu_data[i * 2]);	
		} else {
			outID(menu_data[i * 2]);	
		}
	}
}

function overID(id) {
	var t= $("#" + id);
	var id = t.attr('id');
	var new_width = get_menu_width(id);
	var div = t.children('div');
	div.stop();
	div.animate({width: new_width + 'px'}, 500);
	t.stop();
	t.animate({width: new_width + 'px'}, 500);
}
function outID(id) {
	var t = $("#" + id);

	var div = t.children('div');
	div.stop();
	div.animate({width: '0px'}, 500);
	t.stop();
	t.animate({width: '0px'}, 500);
}
