$(document).ready(function() {
	$('.mainNavigation ul li').hover(function () {
		var $this = $(this);
		var $class = $this.find('a').attr('class');
		var $selectedClass = $class.split(' ')[0] + '-selected-hover';
		$this.addClass('sfhover').find('a').filter(':not(.' + $selectedClass + ')').addClass('selected ' + $selectedClass);
	}, function () {
		var $this = $(this);
		var $class = $this.find('a').attr('class');
		$this.removeClass('sfhover').find('a').removeClass($class.match(/[a-zA-Z0-9]+\-selected-hover/));
	});

	$('.directions li.road').click(function() {
		var $this = $(this);
		if ($this.find('a').attr('class') == 'selected') {
			$this.find('ul').hide();
			$this.find('a').removeClass("selected");
		} else {
			$this.find('ul').show();
			$this.find('a').addClass("selected");
		}
		return false;
	});

	$('ul.events li').hover(function() {
		$(this).css({"cursor" : "pointer", "color" : "#999999"}).find('.arrow').addClass('hover');
	}, function(){
		$(this).css({"cursor" : "normal" , "color" : "#666666"}).find('.arrow').removeClass('hover');
	});

	var museumMapHeights = {};
	var origAnchorHeight = 0;

	$(".maplist ul li a span.nodisplay").each(function() {
		var key = $(this).parents("li").attr("class").match(/map-l\d+/);
		museumMapHeights[key] = $(this).height() + 10;
		origAnchorHeight = $(this).parent().height();
	});

	$(".maplist ul li a span.nodisplay").css({ visibility: "visible"});

	$('.maplist ul li a').click(function() {

		var mapId = $(this).parent("li").attr("class").match(/map-l\d+/);

		if ($(this).attr("class") == "selected") {
			var origHeight = origAnchorHeight + "px";
			$(this).removeClass("selected").animate({ backgroundPosition: "0px 0px", height: origHeight }, 500);
			$(this).children("span[class*=map-l]").animate({ marginTop: "0px" }, {queue:false, duration:500});
		} else {
			var totalHeight = (origAnchorHeight + museumMapHeights[mapId]) + "px";
			var spanButtonHeight = museumMapHeights[mapId] + "px";

			$(this).addClass("selected").animate({ height: totalHeight }, {queue:false, duration:500});
			$(this).children("span[class*=map-l]").animate({ marginTop: spanButtonHeight }, {queue:false, duration:500});
		}

		return false;
	});

	$('.maplist ul li:last a').click();

	if ($('#news li').length > 1) {
		$("#news").newsticker().css('visibility', 'visible');
	} else {
		$('#news').css('visibility', 'visible');
	}

	$('.translate select').sSelect({ddMaxHeight: '165px'}).change(function(e) {
		if($(this).val() != "none") {
			$('#translate').submit();
		}
	});

	var $creditspopup = $('.credits-popup');
	$creditspopup.find("a.ex").click(function() {
		$creditspopup.removeClass('show');
		return false;
	});

	$("a.credits").click(function() {
		$creditspopup.toggleClass('show');
		return false;
	});

	$('.selected-works a.work').hover(function() {
		$(this).prepend('<div class="work-hover"></div>');
	},function() {
		$('.work-hover').hide().remove();
	});

	$('.featured-thumbs a.work').hover(function() {
		$(this).prepend('<div class="work-hover"></div>');
	},function() {
		$('.work-hover').hide().remove();
	});

	$('a.work').lightBox();

	$("#casacde-thumb, .view-video").click(function(e) {
		$.modal(
			'<iframe src="http://youtube.com/embed/lj7B494o9v0?hd=1&autoplay=1&controls=1&rel=0&showinfo=0" class="youtube-player" width="630" height="380" frameborder="0"></iframe>',
			{
				close: true,
				overlayClose: true,
				closeClass: 'modal-close',
				closeHTML: '<a href="#" class="ir"></a>',
				opacity: 80,
				overlayCss: { backgroundColor: "#000", cursor: "pointer" }
			}
		);

		e.preventDefault();
	});

	$("img").bind("contextmenu", function() {
		// don't steal our images please
		return false;
	});
});

(function($) {
    $.fn.valChange = function(newValue) {
        return this.each(function() {
            var obj = $(this);
            obj.val(newValue);
            obj.change();
        });
    };
})(jQuery);

