﻿if ($.cookie("textSizeCss")) {
	$("link#styleSwitcher").attr("href", $.cookie("textSizeCss"));
}
var textSizeStyles = [
	"/styles/text-size/small.css",
	"/styles/text-size/normal.css",
	"/styles/text-size/large.css",
	"/styles/text-size/x-large.css"
];
$(document).ready(function() {
	var textSizeStylesLength = textSizeStyles.length;
	$("#textSize a").click(function() {
		var currentIndex, newIndex, $t, $stylesheet, stylesheetPath, tmp;
		$t = $(this);
		$styleSheet = $("link#styleSwitcher");
		currentIndex = 1;
		for (var i = 0; i < textSizeStylesLength; i++) {
			if (textSizeStyles[i] === $styleSheet.attr("href")) {
				currentIndex = i;
				break;
			}
		}
		if ($t.attr('id') === "textSizeLarger") {
			newIndex = (currentIndex + 1) >= textSizeStylesLength ? currentIndex : currentIndex+1;
		}
		else {
			newIndex = (currentIndex - 1) < 0 ? currentIndex : currentIndex-1;
		}
		$styleSheet.attr("href", textSizeStyles[newIndex]);
		$.cookie("textSizeCss", textSizeStyles[newIndex], { expires: 365, path: '/' });
		return false;
	});
});

function setActiveStyleSheet(title) {
	var i, a, main;
	for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		
		if ($(a).attr("rel").indexOf("style") != -1 && $(a).attr("title")) {
			a.disabled = true;
			if ($(a).attr("title") == title) {
				a.disabled = false;
			}
		}
	}
}
function printPage(){
	var ppHash = "#PrintPreview";
	if (window.location.hash === ppHash && window.name === "PrintPreview") {
		window.print();
		window.close();
	}
	else {
		winLoc = window.location.toString();
		if (winLoc.indexOf("#") != -1) {
			winLoc = winLoc.split("#")[0];
		}
		winLoc += ppHash;
		
		//open current page with printPreview parameter set.
		previewWin = window.open(winLoc, "PrintPreview", "width=1000,height=700,location=no,tabs=no,tabbar=no,resizable=yes,scrollbars=yes,status=yes,menubar=no,toolbar=no");
	}
}
$(document).ready(function() {
	var ppHash = "#PrintPreview";	
	if (window.location.hash === ppHash){// || window.name === "PrintPreview") {
		setActiveStyleSheet("printPreview");
	}
});