var menu_open = false;
var menu_timer;
var content_height, content_width;
var menu_height, menu_width;
var tttimer;
Shadowbox.init({  
    players:    ["qt", "img", "swf"],
	continuous: true,
	useSizzle: false,
	
}); 
function menu_controls() {
	
	if (thisurl != '/') {		
		$("#menu_over").hover(function() {
			if (menu_open == false) {
				$("#content").css('background-image', 'url('+themeurl+'/menu_arrow_f2.png)');
				menu_open = true;
				$("#menu").show('slow', function () {});
				//$(".wrapper").css("width", 100+content_width+menu_width);
				$("#menu").mouseout();
			} else {
				$("#content").css('background-image', 'url('+themeurl+'/menu_arrow.png)');
			}
		},function() {
			if (menu_open == false) {
			} else {
				$("#content").css('background-image', 'url('+themeurl+'/menu_arrow_f2.png)');
			}
		});
		
		$("#menu").hover(function() {
			clearTimeout(menu_timer);
		},function() {
			menu_timer = setTimeout(function(){  
				$("#menu").hide('slow', function () {menu_open = false; /*$(".wrapper").css("width", 100+content_width);*/});
				$("#content").css('background-image', 'url('+themeurl+'/menu_arrow.png)');
			}, 1500);	
		});
		
		$("#menu_over").click(function() {
			if (menu_open == true) {
				clearTimeout(menu_timer);
				$("#content").css('background-image', 'url('+themeurl+'/menu_arrow.png)');
				menu_open = false;
				$("#menu").hide('slow', function () { /*$(".wrapper").css("width", 100+content_width);*/ });
			}
		});
	} else {
		menu_open = true;
		//$(".wrapper").css("width", 100+content_width+menu_width);
		$('#menu').show('slow');	
		$("#content").css('background-image', 'none');
	}
	
}

function go_link(thisurl) {
	if (thisurl.indexOf(baseurl) != -1) {
		$("#content").hide('slow', function () {document.location = thisurl;});
	} else {
		$("#content").hide('slow', function () {
			$(".header").after('<div id="loading">Bye bye!</div>');
			$("#loading").hide().fadeIn();
			var goaway = setTimeout(function () {
				document.location = thisurl;
			}, 1000);
		});
	}
}

$(window).load(function () {
	menu_width = parseInt($("#menu").width());

	$("#loading").fadeOut("slow", function () {
		$("#loading").remove();
		$("#content").show('slow', menu_controls());

	});

	$("a").click(function() {
		if ($(this).attr('rel') != '') return;
		target = $(this).attr('target');
		thisurl = $(this).attr('href');
		if (target == "_blank" || thisurl.indexOf('http://') == -1) return;
		$(this).attr('href','javascript:;');
		if (menu_open == true) {
			$("#menu").hide('slow', go_link(thisurl));
		} else {
			go_link(thisurl);
		}
		
	});
	
	$(".header a").hover(function() {
		$("#header_img").attr('src', ''+themeurl+'/site_title_f2.png');							  
	},function() {
		$("#header_img").attr('src', ''+themeurl+'/site_title.png');							  
	});
	
	$("#madeincut").hover(function() {
		url = $(this).attr('src');
		newurl = url.substr(0, url.indexOf('.png'))+'_f2.png';
		$(this).attr('src', newurl);							  
	},function() {
		url = $(this).attr('src');
		newurl = url.substr(0, url.indexOf('_f2.png'))+'.png';
		$(this).attr('src', newurl);							  
	});
	
	$("body").append('<div id="tooltip"></div>');
	
	$("a").hover(
		function() {
			delay = 500;
			titolo = '';
			if ($(this).attr("title") == "") {
				if ($(this).attr("target") == "_blank") {
					delay = 20;
					titolo = "This link opens in a new window.";
				} else {
					return;	
				}
			} else {
				titolo = $(this).attr("title");
			}
			$("body").mousemove(function (e) {
				$("#tooltip").css("left", e.pageX+10);
				$("#tooltip").css("top", e.pageY-25);
			});
			$(this).attr("title", "");
			$("#tooltip").html(titolo);
			tttimer = setTimeout(function () {
			$("#tooltip").show("fast"); }, delay);
		},
		function() {
			$(this).attr("title", titolo);
			clearTimeout(tttimer);
			$("#tooltip").hide("fast");
			$("body").unbind("mousemove");
		}
	);
});

$(document).ready(function() {
						   
	$(".section-title, .content_sect, .menulink a, .section_flag, .new_flag, .exh_title, .exh_links, .thumb-it").each( function() { 
		el = $(this);
		FLIR.replace(el, new FLIRStyle({ cFont:'avantgreek', output:'png', useExtendedStyles:true  } )); 
	});
	
	content_height = parseInt($("#content").height());//('height');
	content_width = parseInt($("#content").width());//css('width');
	
	$("#menu").css('display', 'block');
	$("#content").css('display', 'block');
	$('#menu').hide();	
	$('#content').hide();
	$("#loading").hide().fadeIn("slow");
	$(".collapsible_div").hide();
	
	$(".collapsible_link").toggle(function () {
		name = "#collapsible_"+$(this).attr("rel");
		$(name).slideDown();
	}, function () {
		name = "#collapsible_"+$(this).attr("rel");
		$(name).slideUp();	
	});
	$("#collapsible_link_"+section).click();
});