﻿
$(function() {
	if ($.browser.msie) {

		// Submenus ein und ausklappen durchzuweisen der .hover-Klasse
		$('#navsite ul.main > li, #subnavi ul.main > li')
			.hover(
				function() {
					$(this).addClass('hover');
				},
				function() {
					$(this).removeClass('hover');
				});	

	}

	$('#imagemenu').imageMenu();
	
});


(function($) {
	$.fn.imageMenu = function( option ) {
		var oMenu = this;
		var oElem = this.children('li');
		var width = oMenu.width();
		var count = oElem.length;
		option = $.extend({
						width: 2*width/count
					},option);
		option.small = (width-option.width)/(count-1);
		
		oElem.css({
			float: 'none',
			position: 'absolute',
			width: option.width
        });
		oElem.each(function(i) {
			$(this).css({left:width/count*i, top:0});
			with ($(this).children('img')) {data('marginLeft',css('margin-left').replace(/px/,'')); }
		}); 
		oElem.hover(
			function() {
				oElem.stop();
				var n=oElem.index(this);
				$(this).children('img').stop().animate({marginLeft:0});
				oElem.each( function(i) {
					$(this).animate({left:option.small*i+(i>n?option.width-option.small:0)},{queue:false});
				});
			},
			function() {
				oElem.stop();
				oElem.each( function(i) {
					$(this).animate({left:width/count*i});
					var oImg =$(this).children('img');
					oImg.stop();
					if (oImg.css('margin-left').replace(/px/,'') != oImg.data('marginLeft'))
						oImg.animate({ marginLeft:oImg.data('marginLeft') }); 
				});
			}
		);

	}
})(jQuery);
