/* Menu stuff */
var menu_timer;
function init_menu() {
	var menus = $(".menu_items > div");
	var menu_lis = $("#header ul li");
	$(".menu_items").show();

	$.each(menus, function(i) {
		$(this).children(".title").text(menu_lis.eq(i).text());
	});
	menus.hide();

	menus.hover(function() { clearInterval(menu_timer); }, function() { menu_timer = setTimeout(function() { activate_menu(""); }, 500); });
	menu_lis.hover(function() { hover_menu($(this), true); clearInterval(menu_timer); }, function() { });
}
function hover_menu(elem, enable) {
	activate_menu(elem.attr("target"));
}
function activate_menu(target) {
	var menus = $(".menu_items > div");
	var menu_lis = $("#header ul li");

	$.each(menus, function(i) {
		var menu = $(this);
		if (menu.attr("id") == target) {
			var menu_li = $("#header ul li[target=" + target + "]");
			menu.children(".title")
				.css("left", (menu_lis.eq(i).offset().left-1) + "px")
				.attr("href", menu_lis.eq(i).children("a").attr("href"));
			menu.children(".content").css("left", (menu_lis.eq(0).offset().left-1) + "px");
			menu.show();
		}
		else {
			menu.hide();
		}
	});
}

function apply_same_height(el) {
	var max_height = -1;
	el.each(function() {
		max_height = Math.max(max_height, $(this).height());
	});
	el.height(max_height);
}

function apply_bullet_list() {
	$(".left .content ul.cute li")
		.wrapInner("<div style='float: left; width: 98.5%'></div>")
		.prepend("<div style='float: left; width: 1.5%'>&bull;</div>")
		.append("<div style='clear: both;'></div>");
}

function apply_fancybox() {
	$(".screenshot a").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutQuad',
		'easingOut'     : 'easeInQuad',
		'titlePosition'  : 'inside',
		'speedIn': 200,
		'speedOut' : 200,
		'hideOnContentClick'  : true
	});
}

$(function() {
	$("img").pngfix({imageFixSrc:'images/blank.gif'});
	init_menu();
	apply_bullet_list();
	apply_fancybox();

	$(window).load(function () {
		apply_same_height($(".same_height"));
		apply_same_height($(".same_height2"));
	});
});
