function prepareMenu() {
	$("table.mainMenu > tbody > tr > td > a").addClass("root");

	$("table.mainMenu > tbody > tr > td > div, table.mainMenu li:has(ul)").each(function() {
		var m = $(this);
		m.css({"position" : "relative"});
		m.find("a:first").addClass("submenu");
		m.hover(
			function() {
				m.addClass("hover");
				m.find("a:first").fadeIn("fast");
				m.find("ul:first").fadeIn("fast");
			},
			function() {
				m.removeClass("hover")
				m.find("ul:first").fadeOut("fast");
			}
		);
	});
}

$("div.slider").cycle({
	fx: 'fade',
	speed: 1000, 
	timeout: 5000,
	pause:  1,
	pager:  "#sliderNav",
	next: "div.slider img",
});

$(document).ready(function(){

$("div.link > a").each(function(i){
	if($(this).next().html() != null) {
		$(this).css("font-weight", "bold")
		$(this).poshytip({
			content: $(this).next().html(),
			className: "tip-darkgray",
			alignTo: 'target',
			alignX: 'right',
			alignY: 'center',
			offsetX: 5
		})
	}
});

var mainNews = $("div.mainNews a").each(function(i){
	this.tip = $("<div class='mainNewsTip' />").append($(this).clone());
	var a = $(this);
	a.fadeTo(300, 0.5)

	if(this.tip.html() != null) {
		a.poshytip({
			content: this.tip,
			className: "tip-darkgray",
			alignTo: 'target',
			alignX: 'left',
			alignY: 'bottom',
			offsetX: -143,
			offsetY: -95,
			fade: true,
			slide: false,
			showTimeout: 50,
			hideTimeout: 50
		})
	}
});


$("#sliderNav").fadeOut("slow")
var sl = $("div.slider");
sl.tipContent = new Array();
sl.imgMouseIn = false;
sl.navMouseIn = false;

sl.mouseenter(
function(){
	window.clearTimeout(sl.delay);
	sl.imgMouseIn = true;
	if (sl.navMouseIn)
		sl.navMouseIn = false;
	else {
		$("#sliderNav").fadeIn("slow");
		sl.cycle.random = 0;
	}
}).mouseleave(
function(){
	sl.delay = window.setTimeout(
	function(){
		if (!sl.navMouseIn)	 {
			sl.imgMouseIn = false;
			$("#sliderNav").fadeOut("slow");
			sl.cycle("resume");
		}
	}, 100)
})

$("#sliderNav").mouseenter(
function(){
	sl.navMouseIn = true;
	sl.cycle("pause");
}).mouseleave(
function(){
	sl.navMouseIn = false;
})

$("#sliderNav > a").each(function(i){
	sl.tipContent[i] = $("<div class='sliderNavTip' />").append($("div.sliderItem:eq(" + i + ")").html());
	$(this).poshytip({
		content: sl.tipContent[i],
		className: "tip-darkgray",
		alignTo: 'target',
		alignX: 'center',
		alignY: 'bottom',
		offsetX: 0,
		offsetY: 10,
		slide: false,
		showTimeout: 100,
		hideTimeout: 100,
	});
	this.$tip.mouseenter(
	function(){
		sl.navMouseIn = true;
		sl.cycle("pause");
	}).mouseleave(
	function(){
		sl.delay = window.setTimeout(
		function(){
			if (sl.navMouseIn)	 {
				sl.imgMouseIn = false;
				sl.navMouseIn = false;
				$("#sliderNav").fadeOut("slow");
				sl.cycle("resume");
			}
		}, 100)
	})
});

var textboxes = $(":text, :password, input[type=file]");
textboxes.addClass("text");
$(".text, textarea, select").hover(
	function(){$(this).addClass("textHover");}, 
	function(){$(this).removeClass("textHover");}
);
$(".text, textarea, select").bind("focus blur", function(){$(this).toggleClass("textFocus")});
$("input[type=checkbox]").addClass("checkbox");
$("select > option[value='']").css("color", "#AAA");

$(":button, input[type=submit]").addClass("button").hover(
	function () {
		if ($(this).hasClass("small"))
			$(this).addClass("buttonSmallHover");
		else
			$(this).addClass("buttonHover");
	}, 
	function () {
		if ($(this).hasClass("small"))
			$(this).removeClass("buttonSmallHover");
		else
			$(this).removeClass("buttonHover");
	}
);

$("div.newsList p.more > a").append("&nbsp;&rarr;")


/* Clean up */
$("div.content font").each(function(){
	$(this).replaceWith($(this).html());
})
$("div.content span[style]").each(function(){
	var a = $(this);
	if (a.attr("style").indexOf("font-family") != -1) {
		$(this).replaceWith($(this).html());
	}
})

$("#mapLocation").fancybox({
	"width" : "75%",
	"height"	 : "75%",
	"type" : "iframe",
	helpers: {
		title : {
			type : 'inside'
		},
		overlay : {
			speedIn : 500,
			opacity : 0.5
		}
	}
});
$("a.thickbox").fancybox({
	"titlePosition" : "inside",
	helpers: {
		title : {
			type : 'inside'
		},
		overlay : {
			speedIn : 500,
			opacity : 0.5
		}
	}
});
$("a[rel=gal_pic]").fancybox({
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	"titlePosition" : "inside",
	helpers: {
		title : {
			type : 'inside'
		},
		overlay : {
			speedIn : 500,
			opacity : 0.5
		}
	},
	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
});

})

