﻿/// <reference path="jquery-1.3.2-vsdoc.js" />
/// <reference path="jQuery/jquery.cookie-vsdoc.js" />
/// <reference path="Modal.js" />

// Go Slow
//#region
var g_speed = (function () {
	var c_cookie = "slow";
	return {
		isSlow: function () {
			return $.cookie(c_cookie) == "1";
		},
		goSlow: function (slow) {
			if (slow === undefined)
				slow = true;
			$.cookie(c_cookie, slow ? "1" : "0", { path: "/" });
		}
	};
})();
//#endregion

// Document Load
//#region
$(document).ready(function () {
	$('a[href^="http://"]')
	  .attr({
	  	target: "_blank",
	  	title: "Opens in a new window"
	  })
	  .append(' [^]');

	$.modal(".modal");

	var versionText = g_speed.isSlow() ? "High version" : "Low version";
	$("#footer .privacy").before("<a class=\"low-version\" href=\"#\">" + versionText + "</a><div class=\"heart\"></div> |&nbsp;");

	var $lowVersion = $("#footer .low-version");
	var $heart = $("#footer .heart");

	var lowPosition = $lowVersion.position();

	$heart.css({
		bottom: lowPosition.top + 12,
		left: (lowPosition.left + ($lowVersion.width() / 2)) - ($heart.width() / 2),
		display: g_speed.isSlow() ? "none" : "block"
	});

	var timeout = setTimeout(function () {
		$heart.fadeOut();
		timeout = null;
	}, 10000);

	$lowVersion.hover(function () {
		if (timeout != null)
			clearTimeout(timeout);

		if (!g_speed.isSlow())
			$heart.fadeIn();
	},
	function () {
		if (timeout != null)
			clearTimeout(timeout);

		$heart.fadeOut();
	});

	$lowVersion.click(function (evt) {
		evt.preventDefault();
		var slow = !g_speed.isSlow();
		g_speed.goSlow(slow);

		if (slow)
			$lowVersion.text("High version");
		else $lowVersion.text("Low version");

		location.reload();
	});
});
//#endregion
