var ratings;

function WriteNonFlashMessage() {
    // Browser Detection 
     var isIE = (navigator.appName.indexOf('Microsoft') == 0);
     var isNS = (navigator.appName.indexOf('Netscape') == 0);
     var isMac = (window.navigator.appVersion.indexOf("Mac") != -1);
     var isWindows = navigator.userAgent.indexOf("Windows 95") != -1 || navigator.userAgent.indexOf("Windows 98") != -1 || navigator.userAgent.indexOf("Windows NT") != -1;
     var isUNIX = (window.navigator.appVersion.indexOf("X11") != -1) || (window.navigator.appVersion.indexOf("Linux") != -1) || (window.navigator.appVersion.indexOf("SunOS") != -1) || (window.navigator.appVersion.indexOf("IRIX") != -1) || (window.navigator.appVersion.indexOf("HP-UX") != -1);
     var isMacIE = (isMac && isIE);

     // Flash Version Detection
     var isFlash8 = false;

     if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
	      if (navigator.plugins && navigator.plugins["Shockwave Flash"] && (versionIndex = navigator.plugins["Shockwave Flash"].description.indexOf(".")) != - 1) {
		     var versionString = navigator.plugins["Shockwave Flash"].description.substring(versionIndex - 2, versionIndex);
		     if (versionString.charAt(0) == " ") versionString = versionString.substr(1);
		     versionIndex = parseInt(versionString);
		     isFlash8 = (versionIndex >= 8);
	      }
     } else if (isIE && isWindows) {
	      document.write('<script language="VBScript">\n');
	      document.write('on error resume next\n');
	      document.write('isFlash8 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8")))\n');
	      document.write('</' + 'script>\n');
     }

     if (!isFlash8) document.write("<div style=\"margin:6px 0px 10px 11px;border:dotted 1px #aaabac;padding:8px 10px;background-color:#f7f4c9;font-weight:bold;text-align:center\">This website is best experienced with the Adobe Flash Plugin. <a href=\"http://www.adobe.com/shockwave/download/ download.cgi?P1_Prod_Version=ShockwaveFlash\">Click here to download</a>.</div>");
}

function ShowBrochureOrderForm() {
	PopupWithOptions("/BrochureOrderForm.aspx", 361, 580, "BOF", "location=no, menubar=no, resizable=yes, status=no, toolbar=no, scrollbars=yes");
}

function ShowPrintView(id) {
	PopupWithOptions("/WalkForPrinter.aspx?id=" + id, 580, 650, "Walk", "location=no, menubar=yes, resizable=yes, status=no, toolbar=yes, scrollbars=yes");
}

function Search_OnFocus(obj) {
	if (Trim(obj.value) == "Quick Search") {
		$(obj).css("color", "#000000");
		obj.value = "";
	}
}

function Search_GoAdvanced() {
	window.location.href = "/Search.aspx" + ($("#ctl00_txtSearch").val().length > 0 && $("#ctl00_txtSearch").val() != "Quick Search" ? "?q=" + $("#ctl00_txtSearch").val() : "");
}

function Search_OnBlur(obj) {
	if (Trim(obj.value) == "") {
		$(obj).css("color", "#aaaaaa");
		obj.value = "Quick Search";
	}
}

function Search_OnKeyPress(obj, e) {
	if (!e) e = window.event;
	if (e.keyCode == 13) {
		Go("/Search.aspx?Keywords=" + encodeURIComponent(Trim(obj.value)))
	}
}

function County_OnClick(id) {
	if (window.location.href.indexOf("Walks.aspx") > -1) {
		SetURLParameters(["County", "Tab"], [id, "Category"]);
	} else {
		Go("/Walks.aspx?County=" + id + "&Tab=Category&Category=1&OrderBy=Name&OrderDirection=ascending");
	}
}

function AdvancedSearch() {
	if (
		ValChecked("County", "Please select at least one County") &&
		ValChecked("Length", "Please select at least one Length") &&
		ValChecked("Shape", "Please select at least one Shape") &&
		ValChecked("RouteType", "Please select at least one Route Type") &&
		ValChecked("Grade", "Please select at least one Grade")
	) SetURLParameters(["Keywords", "County", "Length", "Shape", "RouteType", "Grade"], [GetElement("Keywords").value, GetCheckedValue("County"), GetCheckedValue("Length"), GetCheckedValue("Shape"), GetCheckedValue("RouteType"), GetCheckedValue("Grade")]);
}

function OrderBy(orderBy, orderDirection) {
	SetURLParameters(["OrderBy", "OrderDirection"], [orderBy, orderDirection]);
}

var objActiveWalk = null;
var disableOnMouseOver = false;
//var oldBg = "";
function Walk_OnMouseOver(obj) {
	if (disableOnMouseOver) {
		disableOnMouseOver = false;
	} else {
		if (objActiveWalk != null) $(objActiveWalk).removeClass("focus");
		objActiveWalk = obj;
		//oldBg = objActiveWalk.style.backgroundColor;
		//objActiveWalk.style.backgroundColor = "#cbe0ef";
		$(objActiveWalk).addClass("focus");
		if (GetElement("objMap") != null) GetElement("objMap").focusPin(obj.id.substr(2));
	}
}
function Pin_OnMouseOver(id) {
	var currentScrollTop = GetElement("WalkList").scrollTop;
	var currentScrollBottom = currentScrollTop + GetElement("WalkList").offsetHeight;
	var targetScroll = GetElement("w_" + id).offsetTop;
	if (targetScroll < currentScrollTop || targetScroll > currentScrollBottom - 20) {
		disableOnMouseOver = true;
		GetElement("WalkList").scrollTop = targetScroll;
	}
	if (objActiveWalk != null) $(objActiveWalk).removeClass("focus");
	objActiveWalk = GetElement("w_" + id);
	//oldBg = objActiveWalk.style.backgroundColor;
	//objActiveWalk.style.backgroundColor = "#d0e3f1";
	$(objActiveWalk).addClass("focus");
}
function Pin_OnClick(id) {
	Go("/Walk.aspx?ID=" + id);
}
function Walk_OnClick(obj) {
	Go("/Walk.aspx?ID=" + obj.id.substr(2));
}

function ShowAONBWalks(k) {
    Go("/Search.aspx?Keywords=" + encodeURIComponent(k));
}

function ShowGallery(entity, id, image) {
	PopupWithOptions("/Gallery.aspx?Entity=" + entity + "&ID=" + id + "&Image=" + (image == "" ? "0" : image), 900, 650, "winGallery", "location=no, menubar=no, resizable=yes, status=no, toolbar=no, scrollbars=no");
}




function Item_OnMouseOver(obj) {
    obj.className = "SelectedItem";
	//obj.style.backgroundColor = "#ffffff";
}

function Item_OnMouseOut(obj) {
    obj.className = "";
	//obj.style.backgroundColor = "";
}

function Item_OnClick(id) {
	if (objActiveItem != null) {
		if (objActiveItem != "Item_" + id) {
			GetElement(objActiveItem).style.display = "none";
			objActiveItem = "Item_" + id;
			GetElement(objActiveItem).style.display = "block";
		}
	} else {
		objActiveItem = "Item_" + id;
		GetElement(objActiveItem).style.display = "block";
	}
	GetElement("ItemDetails").scrollTop = 0;
}

function Item_AutoScroll(id) {
	if (GetElement("ItemListing_" + id) != null) GetElement("ItemList").scrollTop = GetElement("ItemListing_" + id).offsetTop;
}




function ShowEvents() {
    Go("/Events.aspx?View=" + GetElement("selView").value + (GetElement("selCounty").value == "0" ? "" : "&County=" + GetElement("selCounty").value));
}

function ValidateJoinList() {
	if (!IsEmail(GetElement("txtJoinListEmail").value)) {
		alert("Please enter a valid email address.");
		GetElement("txtJoinListEmail").focus();
		return false;
	} else {
		return true;
	}
}

function FixTitle() {
	var objTitles = document.getElementsByTagName("H1");
	for (var i = 0; i < objTitles.length; i++) {
		if (objTitles[i].firstChild.nodeName.toUpperCase() == "IMG" && objTitles[i].firstChild.offsetHeight > 36) {
			objTitles[i].style.height = "76px";
		}
	}
}

function Disclaimer() {
	alert("WALKNI.COM DISCLAIMER\n\nEvery care has been taken to ensure accuracy of the information. We cannot accept responsibility for errors or omissions but where such are brought to our attention, the information will be amended accordingly.\n\nWhilst all the clubs, associations and activity operators listed on this website generally operate according to which is accepted as current best practice, it is the responsibility of the participant to ensure that they are credible and all appropriate safety standards are adhered to. The Countryside Access and Activities Network have, nor assume, any responsibility for the accuracy or the completeness of the information supplied or the service and level of care afforded by any of the clubs, associations and activity operators listed on this website.");
}

function GetFlash() {
	if (confirm("Advanced interactivity for this map is available to users with the Adobe Flash Player installed. Click OK to go to the Adobe Flash Player download website and install it now.")) {
		Go("http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash");
	}
}

function PositionStamp() {
	var objMaskedImageContainerPos = GetAbsolutePosition(GetElement("ctl00_MaskedImageContainer"));
	var objQualityStamp = GetElement("QualityStamp");
	objQualityStamp.style.top = (objMaskedImageContainerPos.y + 165) + "px";
	objQualityStamp.style.left = (objMaskedImageContainerPos.x + 430) + "px";
}

function PositionGetInTouch() {
	var objMaskedImageContainerPos = GetAbsolutePosition(GetElement("ctl00_MaskedImageContainer"));
	var objGetInTouch = GetElement("GetInTouch");
	objGetInTouch.style.top = (objMaskedImageContainerPos.y + 145) + "px";
	objGetInTouch.style.left = (objMaskedImageContainerPos.x + 378) + "px";
}

function fixIE6PNGs2() {
    $("img.alpha").enableIE6Transparency();
    $("input.alpha").enableIE6Transparency();
}

RegisterEvent("Window_OnLoad", "FixTitle");







function Week_OnMouseOver(obj) {
    obj.className = "SelectedWeek";
	//obj.style.backgroundColor = "#ffffff";
}

function Week_OnMouseOut(obj) {
    obj.className = "";
	//obj.style.backgroundColor = "";
}








(function($) {


    $.fn.enableIE6Transparency = function(options) {
        options = $.extend({
            blankImageUrl: "/i/_.gif"
        }, options);

        if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && (navigator.appVersion.indexOf("MSIE 5.5") != -1 || navigator.appVersion.indexOf("MSIE 6.0") != -1)) {
            return this.each(function(i) { $(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', src='" + $(this).attr("src") + "')").attr("src", options.blankImageUrl); });
        } else {
            return this;
        }
    };

    $.fn.enableIE6BackgroundTransparency = function(options) {
        options = $.extend({
            blankImageUrl: "/i/_.gif",
            scale: false
        }, options);

        if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && (navigator.appVersion.indexOf("MSIE 5.5") != -1 || navigator.appVersion.indexOf("MSIE 6.0") != -1)) {
            return this.each(function(i) {
                var bgCss = $(this).css("background-image");
                $(this).css({ "background-image": "none", "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='" + (options.scale ? "scale" : "crop") + "', src='" + bgCss.substring(5, bgCss.length - 2) + "')" });
            });
        } else {
            return this;
        }
    };
	
	$.backwardsCompatibility = {
		hideIE6Foreground: function () {
			$("object, select").each(function () {
				$(this).css("visibility", "hidden").addClass("IE6Foreground");
			});
		},
		unhideIE6Foreground: function () {
			$(".IE6Foreground").css("visibility", "visible").removeClass("IE6Foreground");
		}
	};

	
	$.navigate = function (url) {
		if (window.event) window.event.returnValue = false;
		window.location.href = url;
	};

})(jQuery);


$(function () {

    $("a[tooltip], img[tooltip]").tooltip({ delay: 100, track: false, /*showBody: " / ",*/showURL: false, left: 10,
        bodyHandler: function() { return $(this).attr("tooltip"); }
    });


	$(".AccommodationTable tr").each(function () { $(this).find("th:odd, td:odd").addClass("alt"); });
	$(".AccommodationTable tbody tr:last td").css("border-bottom-width", "0px");

	ratings = ["Very Poor", "Poor", "OK", "Good", "Very Good"];

	$("#Rating td.stars").mousemove(function (e) {
		var rating = Math.min(Math.floor((e.pageX - $(this).offset().left) / 23) + 1, 5);
		$(this).css("background-position", "0px " + (-115 + rating * 23) + "px");
		$("#Rating td.label").html(ratings[rating]);
	}).mouseleave(function () {
		var rating = $("input[name=Rating]").val();
		if (rating.length > 0) {
			$(this).css("background-position", "0px " + (-115 + rating * 23) + "px");
			$("#Rating td.label").html(ratings[rating]);
		} else {
			$(this).css("background-position", "0px -115px");
			$("#Rating td.label").html("<img src=\"/i/click-to-rate.png\" alt=\"click to rate\" />");
		}
	}).click(function (e) {
		$("input[name=Rating]").val(Math.min(Math.floor((e.pageX - $(this).offset().left) / 23) + 1, 5));
	});


});
