﻿

var AB = {

	siteMap: function () {
		$.navigate("/SiteMap.aspx");
	},

	print: function () {
		window.print();
	},

	translate: function (code) {
		$.navigate("http://translate.google.com/translate?hl=en&ie=UTF-8&sl=en&tl=" + code + "&u=" + encodeURIComponent(window.location.href));
	},

	translateOther: function () {
		$.navigate("http://translate.google.com/#en|pl|" + encodeURIComponent(window.location.href));
	},

	setColour: function (foreground, background) {
		if (foreground != null && foreground.toString().length > 0 && background != null && background.toString().length > 0) {
			$.navigate("/Accessibility/SetColour.ashx?fg=" + encodeURIComponent(foreground) + "&bg=" + encodeURIComponent(background) + "&r=" + encodeURIComponent(window.location.href));
		} else {
			$.navigate(window.location.href = "/Accessibility/SetColour.ashx?r=" + encodeURIComponent(window.location.href));
		}
	},

	setTextSize: function (size) {
		if (size != null && size.toString().length > 0) {
			$.navigate("/Accessibility/SetTextSize.ashx?v=" + encodeURIComponent(size) + "&r=" + encodeURIComponent(window.location.href));
		} else {
			$.navigate("/Accessibility/SetTextSize.ashx?r=" + encodeURIComponent(window.location.href));
		}
	},

	showMenu: function (e, button, identifier) {
		if (/MSIE/i.test(navigator.userAgent)) $.backwardsCompatibility.hideIE6Foreground();

		var jqMenu = $("#AB" + identifier);
		$(".ABMenu").not("#AB" + identifier).hide();
		var x1 = $(button.parentNode.previousSibling.firstChild).offset().left;
		var x2 = $(button.parentNode.nextSibling.firstChild).offset().left;
		jqMenu.css({ "left": x1 + "px", "width": (x2 - x1 - 1) + "px" }).fadeIn(200);

		e.stopPropagation();
	}

};

$(function () {

	$("#AB table.ab-button").mouseover(function () {
		$(this).removeClass("down");
		$(this).addClass("over");
	}).mousedown(function (e) {
		$(this).removeClass("over");
		$(this).addClass("down");
		e.preventDefault();
	}).mouseup(function () {
		$(this).removeClass("down");
		$(this).addClass("over");
	}).mouseout(function () {
		$(this).removeClass("down");
		$(this).removeClass("over");
	});

	$("#ABTranslateButton").click(function (e) { AB.showMenu(e, this, 'Translate') });
	$("#ABColourButton").click(function (e) { AB.showMenu(e, this, 'Colour') });
	$("#ABTextSizeButton").click(function (e) { AB.showMenu(e, this, 'TextSize') });

	$(document).click(function () {
		$(".ABMenu").hide();
		if (/MSIE/i.test(navigator.userAgent)) $.backwardsCompatibility.unhideIE6Foreground();
	});

});

