jQuery(function($) {
	$("#header").slideshow({
		elems: "> div.slide",
		nums: "> ul.n",
		speed: "slow",
		interval: 5000
	})

	if ($.browser.msie && parseInt($.browser.version) <= 6) {
		$("#main-menu li.lvl1").hoverClass("lvl1-hover")
		$("#main-menu li.lvl1-parent").hoverClass("lvl1-parent-hover")
		$("#content table").attr("cellspacing", "0")
		$("#content div.content-rt div.box ul.menu li:first-child").addClass("first-child")
		$("#content table th:first-child, #content table td:first-child").addClass("first-child")
	}
	$("#content table th:last-child, #content table td:last-child").addClass("last-child")
	
	$("div.content-rt form.contact").submit(function () {
		var f = $(this)
		$('<span class="loader"></span>').prependTo(f)
		$.post(f.attr("action"), f.serialize(), function (resp) {
			f.find("span.loader").remove()
			f.find("div.status").html(resp).show("slow")
		})
		return false
	})
	$("div.content-rt form.contact textarea").focus(function () {
		if ($(this).height() < 100) {
			$(this).animate({ height: 130 }, "slow")
		}
	})
});

(function($) {
	$.fn.hoverClass = function (className) {
		return this.each(function () {
			$(this).hover(
				function () { $(this).addClass(className) },
				function () { $(this).removeClass(className) }
			);
		})
	}
})(jQuery);

(function($) {
	$.fn.slideshow = function (opt) {
		return this.each(function () {
			var interval = null
			var $this = $(this);
			var elems = $this.find(opt.elems);
			var nums = $this.find(opt.nums);

			if (elems.length < 2) return;
			elems.hide().css({ position: "absolute", top: 0, left: 0 }).addClass("slide")
			     .eq(0).show().addClass("current");
			nums.find("li:first a").addClass("current");

			function switchTo(elem) {
				elems.filter(".current").fadeOut(opt.speed);
				elems.removeClass("current")
				elem.addClass("current").fadeIn(opt.speed);
				nums.find("li a")
					.removeClass("current")
					.filter(function() {
						return $(this).attr("href") == "#" + elem.attr("id")
					})
					.addClass("current")
			}
			function next() {
				var e = elems.filter(".current");
				if (e.next().is(".slide"))
					switchTo(e.next());
				else
					switchTo(elems.filter(":first"));
			}
			function prev() {
				var e = elems.filter(":visible");
				if (e.prev().is(".slide"))
					switchTo(e.prev());
				else
					switchTo(elems.filter(":last"));
			}
			nums.find("li a").click(function() {
				if (interval) clearInterval(interval)
				switchTo($($(this).attr("href")))
				return false
			});
			$this.find("> a.next").show().click(function () {
				if (interval) clearInterval(interval)
				next();
				return false
			});
			$this.find("> a.prev").show().click(function () {
				if (interval) clearInterval(interval)
				prev();
				return false
			});
			interval = setInterval(next, opt.interval)
		})
	}
})(jQuery);

