;(function($){
	$.fn.slidemenu = function(op){

		var sm = $.fn.slidemenu,
		over = function() {
				var li = $(this), o = sm.op, h = parseInt(li.height());
				$('.sm-top',li).animate({height: Math.floor(h*0.65)+'px'});
                $('.sm-hover',li).fadeIn();
				$('.sm-bottom',li).animate({height: (Math.ceil(h*0.35)+o.triangleSize)+'px'});
				$('.sm-foo',li).stop(true,true).animate({opacity: 0.8});
                var $a = $('a',li);
                if (!$a.data('fontsize')) {
                    $a.data('fontsize',$a.css('fontSize'));
                }
				$a.animate({fontSize: '+='+o.fontDiff});
			},
		out = function() {
                $('.sm-top',this).animate({height: 0});
                $('.sm-hover',this).fadeOut();
				$('.sm-bottom',this).animate({height: '35%'});
				$('.sm-foo',this).stop(true,true).animate({opacity: 0.5});
				$('a',this).animate({fontSize: $('a',this).data('fontsize')});
		};


		return this.each(function() {
			var o = $.extend({},sm.defaults,op);
			sm.op = o;
			var t = $('<div></div>').attr('class','sm-top').css({
				position:'absolute',
				top:0, left:0,
				height:0,
				width:'100%',
				opacity:0.5,
				backgroundColor:o.color});
			var b = $('<div></div>').attr('class','sm-bottom')
				.css({position:'absolute', overflow: 'hidden',
							bottom:0,
							left:0,
							height:'35%',
							width:'100%'
					});
			var tri = $('<div style="height:10px;margin:0;padding:0;position:relative;"></div>');
			$('<div style="height:0; width:0; position:absolute; right:50%;"></div>')
				.css({borderRight: o.triangleSize+'px solid '+o.color,
                borderTop: o.triangleSize+'px solid transparent','opacity':0.5}).appendTo(tri);
			$('<div style="height:0; width:0; position:absolute; left: 50%;"></div>')
				.css({borderLeft: o.triangleSize+'px solid '+o.color,
                borderTop: o.triangleSize+'px solid transparent','opacity':0.5}).appendTo(tri);
			b.append(tri);
            var ho = $('<span class="sm-hover" style="display:none;"></span>');
			$('<div class="sm-foo" style="height:100%;"></div>').css({'backgroundColor':o.color,'opacity':0.5}).appendTo(b);
			$('li',this).css('position','relative').append(t.clone()).append(b.clone()).each(function() {
                var ht = $('a:first',this).attr('title');
                if (ht) {
                    ho.clone().text(ht).appendTo(this);
                }
            }).hover(function() {
				if ($(this).is(':not(.selected)')) over.call(this);
			}, function() {
				if ($(this).is(':not(.selected)')) out.call(this);
			}).click(function () {
                window.location.href = $('a:first',this).attr('href');
            }).filter('.selected').each(function() {
				over.call(this);
			});
		})
	};

	var sm = $.fn.slidemenu;
	sm.defaults = {
		color:	'#000000',
		triangleSize: 10,
		fontDiff: 3
	};

})(jQuery);

