/*
// MSIE ClearType Fix
(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if (jQuery.browser.msie) {
				$(this).get(0).style.removeAttribute("filter");
			}
			if (callback != undefined) {
				callback();
			}
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if (jQuery.browser.msie) {
				$(this).get(0).style.removeAttribute("filter");
			}
			if (callback != undefined) {
				callback();
			}
		});
	};
	$.fn.customFadeTo = function(speed, opacity, callback) {
		$(this).fadeTo(speed, opacity, function() {
			if (jQuery.browser.msie) {
				$(this).get(0).style.removeAttribute("filter");
			}
			if (callback != undefined) {
				callback();
			}
		});
	};
})(jQuery);
*/

$(document).ready(function() {
	// Navigation
	// IE6 FUCKS UP!
	if (jQuery.browser.msie && (jQuery.browser.version.substr(0, 1) == "6")) {
		$("div#navigation").children("ul").children("li").hover(
			function() {
				$(this).children("a").addClass("selected");
			}, function () {
				$(this).children("a").removeClass("selected");
			}
		);
	} else {
		navigationListItem = $("div#navigation").children("ul").children("li");
		navigationListItem.children("ul").hide();
		navigationListItem.hover(
			function() {
				$(this).children("a").addClass("selected");
				$(this).children("ul").fadeIn("fast");
			}, function () {
				$(this).children("a").removeClass("selected");
				$(this).children("ul").fadeOut("fast");
			}
		);
	}
	
	// Subnavigation
	subnavigationListItem = $("div.subnavigation").children("ul[class!=first]").children("li");
	subnavigationListItem.children("a[class!='selected']").next("ul").hide();
	subnavigationListItem.children("a").click(
		function(event) {
			if (!$(this).hasClass("selected")) {
				event.preventDefault();
				linkToDeselect = subnavigationListItem.children("a.selected");
				linkToDeselect.removeClass("selected");
				linkToDeselect.next("ul").slideUp("normal");
				$(this).addClass("selected");
				$(this).next("ul").slideDown("normal");
			}
		}
	);
	
	// Fixes
	$("div#navigation").children("ul").find("ul").bgiframe({
		target:	$.browser.msie || $.browser.opera
	});
	
	$("div.panorama").children("a.button").bgiframe({
		target:	$.browser.msie || $.browser.opera
	});
	
	// Renders the last menu element rtl
	$("div#navigation").children("ul.last").children("li").children("a:first").each(function() {
		var menu = $(this).siblings("ul");
		var marginLeft = menu.width() - parseInt($(this).css('padding-left')) - $(this).width() - parseInt($(this).css('padding-right'));
		menu.css('margin-left', -marginLeft);
	});
	
	$("a.videopopup").open({
      width: 650,
      height: 450,
      scrollbars: false
   });
});

