(function($) {

	$.fn.slider = function(options) {
		var o = $.extend({
			prev: null,
			next: null,
			width: 180,
			paddings: 10,
			speed: 300,
			scroll: 1
		}, options);

		return this.each(function() {
        	var s = $(this), ul = s.find('UL'), li = s.find('LI'),
	        	f = 0, c = li.length, w, v, t = null,
  	        	p = $(o.prev).click(function() { slide(-o.scroll); return!1; }),
    	        n = $(o.next).click(function() { slide(o.scroll); return!1; });

			$(window).bind('resize.ls', function() {
				clearTimeout(t);
				t = setTimeout(function() {
					w = s.width();
					v = Math.floor(w/o.width);
					w = Math.floor(w/v);
					ul.css('width', (c*w) + 'px');
					li.css('width', (w-o.paddings) + 'px');
					enable();
				}, 10);
			}).triggerHandler('resize');

			function slide(d) {
				f += d;
				f = f < 0 ? 0 : f;
				f = f + v < c ? f : c - v;
				ul.animate({ left: -f*w }, o.speed);
				enable();
			}

			function enable() {
				f == 0 ? p.hide() : p.show();
				f + v >= c ? n.hide() : n.show();
			}

        });
    }

	$(function() {
		var overtimer = null, speed = 400;
		var sub = $('#submenu').hover(function() {
			clearTimeout(overtimer);
		}, function() {
			sub_close();
		});
		var menu = $('#menu A:has(EM)').hover(function() {
			sub_reset();
			var p = menu.offset();
			sub.css({ top: p.top + 36, left: p.left, width: menu.width()}).slideDown(speed);
		}, function() {
			overtimer = setTimeout(function() {
				sub_close();
			}, 100);
		});
		function sub_reset() {
			clearTimeout(overtimer);
			sub.stop().css('height', 'auto');
		}
	    function sub_close() {
   			overtimer = setTimeout(function() {
		    	sub.slideUp(speed, function() {
	            	sub_reset();
    			});
			}, 100);
	    }

		$('.ajaxtabs A').click(function() {
            var a = jQuery(this), li = a.parent();
            if (!li.hasClass('active')) {
              	var lis = li.parent().children('LI');
               	lis.filter(':last').attr('class', 'cr ie');
	           	lis.filter(':first').attr('class', 'cl ie');
	           	lis.not(':first').not(':last').filter('.ie').attr('class', 'lr ie');
	           	$('#' + lis.filter('.active').removeClass('active').find('A').attr('id') + '-content').animate({ opacity: 'hide' }, 250);
                setTimeout(function() {
	              	li = li.addClass('active').prev();
	              	li.attr('class', (li.hasClass('cl') ? 'cl' : 'rl') + '-active ie');
	   	          	li = li.next().next();
           	        if (!-[1,] && jQuery.browser.version < 7) li = li.next().next();
	              	li.attr('class', (li.hasClass('cr') ? 'cr' : 'lr') + '-active ie');
	        	}, 100);
	        }
//			return !1;
		});

	});

})(jQuery);

