﻿function switchOverview(node) {
	var height = 69;
	var expanded = node.hasClass("ovTitle2");
	var root = node.parent().parent();
	root.find(".ovTitle2").removeClass("ovTitle2").addClass("ovTitle1");
	root.find(".ovGame").hide();
	root.find(".ovGame").css({ "height": "0px" });
	if (!expanded) {
		node.removeClass("ovTitle1").addClass("ovTitle2");
		node.find("~ .ovGame").show();
		node.find("~ .ovGame").animate({ "height": height + "px" });
	}
}

function scrollOverview(direction) {
	var scrollTo = $(".overviewContent:visible").scrollTop() + 250 * direction;
	var scrollHeight = $(".overviewContent:visible")[0].scrollHeight;
	var height = $(".overviewContent:visible").height();
	if (scrollTo < 0) scrollTo = 0;
	if (scrollTo > scrollHeight - height) scrollTo = scrollHeight - height;
	$(".overviewContent:visible").animate({ scrollTop: scrollTo }, 300);
}

function scrollBigOverview(direction) {
	var scrollTo = $("#ovScroll").scrollTop() + 250 * direction;
	var scrollHeight = $("#ovScroll")[0].scrollHeight;
	var height = $("#ovScroll").height();
	if (scrollTo < 0) scrollTo = 0;
	if (scrollTo > scrollHeight - height) scrollTo = scrollHeight - height;
	$("#ovScroll").animate({ scrollTop: scrollTo }, 300);
}

function scrollStats(direction) {
	var elementWidth = 270;
	var scrollTo = $("#scExternal").scrollLeft() + elementWidth * direction;
	var scrollWidth = 15 * elementWidth;
	var width = $("#scExternal").width();
	if (scrollTo >= 0 && scrollTo < scrollWidth - width) {
		$("#scExternal").animate({ scrollLeft: scrollTo }, 300);
	}
}

function tabOverview(index) {
	if ($("#ovMenu").find("td:eq(" + index + ")").is(".disabled")) return;
	currentOvMode = index;
	$(".overviewContent").hide();
	$("#overviewContent_" + index).show();
	$("#overviewContent_" + index).scrollTop(0);
	$("#ovMenu").find("td").removeClass("active");
	$("#ovMenu").find("td:eq(" + index + ")").addClass("active");
}

function rgb2hex(rgb) {
	var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
	if (parts) {
		delete (parts[0]);
		for (var i = 1; i <= 3; ++i) {
			parts[i] = parseInt(parts[i]).toString(16);
			if (parts[i].length == 1) parts[i] = '0' + parts[i];
		}
		return parts.join('');
	}
	if (rgb[0] == "#") {
		rgb = rgb.replace("#", "");
	}
	if (rgb.length == 3) {
		rgb = rgb[0] + rgb[0] + rgb[1] + rgb[1] + rgb[2] + rgb[2];
	}
	return rgb;
}

(function($) {
	$.QueryString = (function(a) {
		if (a == "") return {};
		var b = {};
		for (var i = 0; i < a.length; ++i) {
			var p = a[i].split('=');
			if (p.length != 2) continue;
			b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
		}
		return b;
	})(window.location.search.substr(1).split('&'))
})(jQuery);

Date.prototype.addHours = function (h) {
	this.setTime(this.getTime() + (h * 60 * 60 * 1000));
	return this;
}
Date.prototype.toTimeStr = function () {
	var text = this.getHours();
	if (text.length < 2) text = "0" + text;
	text = text + ":" + this.getMinutes();
	if (text.length < 5) text = text + "0";
	return text;
}

