var btn_path_base = "/images";

$(document).ready(function(){
	$('.submenuitem').wrapInner('<div class="submenu_mid"></div>');
	$('.submenu_mid').before('<div class="submenu_left"></div>');
	$('.submenu_mid').after('<div class="submenu_right"></div>');
	$('.submenu_mid a').wrap('<div class="submenu_itembox"></div>');
	$('.submenu_mid .submenu_itembox:first-child').css("background-position", "-2px 24px");

	$('.menuitem').each(
		function() {
			$('.submenuitem').each(function() { if($.browser.msie) $(this).hide(); else $(this).fadeOut('fast');});
			var tpos = $(this).offset();
			var strpos = $('#menustrip').offset();
			strpos = parseInt(tpos.left - strpos.left) + $(this).width()/2 - 60;
			var sm_id = $(this).attr('id');
			var smhnd = $('#'+sm_id+'_submenu');
			smhnd.css('left', strpos+'px');
		}
	);

	$('a[href*="-' + this_page_id + '"]').css('color', '#000');
	if($.browser.msie) 
		$('a[href*="' + this_page_id + '"]').parent('.submenu_itembox').parent('.submenu_mid').parent('.submenuitem').show();
	else
		$('a[href*="' + this_page_id + '"]').parent('.submenu_itembox').parent('.submenu_mid').parent('.submenuitem').fadeIn('fast');
	
	$('.menuicon').each(function() {
		var btnimgurl = btn_path_base + '/' + $(this).attr('id') + '.png';
		var btnimgurl_over = btn_path_base + '/' + $(this).attr('id') + 'a.png';
		$(this).attr('src', btnimgurl);
		jQuery("<img>").attr("src", btnimgurl_over);
		$(this).hover(
			function(){
				if($.browser.msie) {
					$(this).attr('src', btnimgurl_over);
				} else {
					$(this).fadeTo("fast", 0.7, function() {$(this).attr('src', btnimgurl_over);} );
					$(this).fadeTo("fast", 1.0);
				}
			}, 
			function(){
				if($.browser.msie) {
					$(this).attr('src', btnimgurl);
				} else {
					$(this).fadeTo("fast", 0.7, function() {$(this).attr('src', btnimgurl);} );
					$(this).fadeTo("fast", 1.0);
				}
			}
		);
	});

	$('.menuitem').hover(
		function() {
			$('.submenuitem').each(function() { if($.browser.msie) $(this).hide(); else $(this).fadeOut('fast');});
			$(this).next('img').css("border", "1px solid black");
			var tpos = $(this).offset();
			var strpos = $('#menustrip').offset();
			strpos = parseInt(tpos.left - strpos.left) + $(this).width()/2 - 60;
			var sm_id = $(this).attr('id');
			var smhnd = $('#'+sm_id+'_submenu');
			smhnd.css('left', strpos+'px');
			if($.browser.msie) smhnd.show(); else smhnd.fadeIn('fast');
			//alert(tos.left);
		},
		function() {}
	);

	$('#navmenu').hover(
		function() {},
		function() {
			$('.submenuitem').each(function() { if($.browser.msie) $(this).hide(); else $(this).fadeOut('fast');});
			if($.browser.msie) 
				$('a[href*="' + this_page_id + '"]').parent('.submenu_itembox').parent('.submenu_mid').parent('.submenuitem').show();
			else
				$('a[href*="' + this_page_id + '"]').parent('.submenu_itembox').parent('.submenu_mid').parent('.submenuitem').fadeIn('fast');
		}
	);
});
