var ImgRight = "/arrow_right_pink.gif";
var ImgDown = "/arrow_down_pink.gif";

$(document).ready(function()
{
	// - HIDE/SHOW ALL - //
	$(".ec_all").click(function () {
		//if ($(".hideShow").is(":hidden")) {
		if ($(this).html() == "Show all price tables") {
			$(".hideShow").fadeIn();
			//$(".hideShow").show();
			$(this).html("Hide all price tables").css({"background":"#fff url('" + ImgDown + "') no-repeat left"});
			$(".tableHeader").html("Hide price table").css({"background":"#fff url('" + ImgDown + "') no-repeat left"});
			setCookie("ExpandAllPriceTables", "ExpandAll");
		} else {
			$(".hideShow").fadeOut();
			//$(".hideShow").hide();
			$(this).html("Show all price tables").css({"background":"#fff url('" + ImgRight + "') no-repeat left"});
			$(".tableHeader").html("Show price table").css({"background":"#fff url('" + ImgRight + "') no-repeat left"});
			setCookie("ExpandAllPriceTables", "ContractAll");
		}
	});
	// - HIDE/SHOW TABLE - //
	$(".tableHeader").click(function () {
		//var myTable = $(this).parents().siblings(".hideShow");
		var myTable = $(this).parents(".priceTable").find(".hideShow");
		if ($(myTable).is(":hidden")) {
			$(myTable).show();
			$(this).html("Hide price table").css({"background":"#fff url('" + ImgDown + "') no-repeat left"});
		} else {
			$(myTable).hide();
			$(this).html("Show price table").css({"background":"#fff url('" + ImgRight + "') no-repeat left"});
		}
		var myTable = null;
		isAllShown();
	});
	// - CHECK IF TABLES ARE COLLAPSED OR EXPANDED AND UPDATES HIDE/SHOW ALL - //
	function isAllShown() {
		$(".tableHeader").each(function(f){
			if ( $(this).text() == "Show price table") {
				$(".ec_all").html("Show all price tables").css({"background":"#fff url('" + ImgRight + "') no-repeat left"});
			} else {
				$(".ec_all").html("Hide all price tables").css({"background":"#fff url('" + ImgDown + "') no-repeat left"});
				return;
			}
		});
	}
});

// - LOAD COOKIE AND UPDATE HIDE/SHOW STATE - //
function isShownOrHidden() {
	if (getCookie("ExpandAllPriceTables") == "ExpandAll") {
		//$(".hideShow").fadeIn();
		$(".hideShow").show();
		$(".ec_all").html("Hide all price tables").css({"background":"#fff url('" + ImgDown + "') no-repeat left"});
		$(".tableHeader").html("Hide price table").css({"background":"#fff url('" + ImgDown + "') no-repeat left"});
	} else {
		//$(".hideShow").fadeOut();
		$(".hideShow").hide();
		$(".ec_all").html("Show all price tables").css({"background":"#fff url('" + ImgRight + "') no-repeat left"});
		$(".tableHeader").html("Show price table").css({"background":"#fff url('" + ImgRight + "') no-repeat left"});
	}
}