﻿var Rotator = {
    images: null,
    currentIndex: 0,
    delay: 5000,
    speed: 750,

    initialise: function(images) {
        this.images = new Array(images.length);
        var initialSrc = $("#Rotator img").attr("src");
        initialSrc = initialSrc.substr(initialSrc.indexOf("%5c") + 3);
        for (var i = 0; i < this.images.length; i++) {
            this.images[i] = images.splice(Math.floor(Math.random() * images.length), 1)[0];
            if (this.images[i] == initialSrc) this.currentIndex = i;
        }
        setTimeout(function() { Rotator.rotate(); }, Rotator.delay);
    },

    rotate: function() {
        this.currentIndex = (this.currentIndex == this.images.length - 1) ? 0 : this.currentIndex + 1;
        var img = new Image();
        $(img).load(function() {
            $(this).hide();
            $("#Rotator").append(this);
            $(this).fadeIn(Rotator.speed, function() {
                $("#Rotator img:eq(0)").remove();
                setTimeout(function() { Rotator.rotate(); }, Rotator.delay);
            });
        }).attr("src", "/ulsterway/Mi.ashx?m=Mask-Header.png&i=rotator%5c" + this.images[this.currentIndex]);
    }
};

var elActiveSection = null;

$(document).ready(function() {
    var $el = $(".PageMenu a.Selected");
    if ($el.length > 0) {
        $(".PageMenu img.Arrow").css({ "top": ($el.position().top) + "px", "display": "block" });
        if ($el.outerHeight() > 30) $(".PageMenu img.Arrow").attr("src", "/ulsterway/i/PageMenu-A-Arrow2.png").css("height", "38px");
    }

    $("#ctl00_txtSearch").focus(
        function() { if (this.value == "Ulster Way Search") $(this).css("color", "#000000").val(""); }
    ).blur(
        function() { if (this.value == "") $(this).css("color", "").val("Ulster Way Search"); }
    ).keypress(
        function(e) { if (e.which == 13) window.location.href = "/ulsterway/search/?Keywords=" + encodeURIComponent(this.value); }
    );

    $("map#Map area").tooltip({ delay: 100, track: true, /*showBody: " / ",*/showURL: false, left: 10,
        bodyHandler: function() { return $(this).attr("custom"); }
    });

    $("#WalkListTable tr").mouseover(function() {
        if (elActiveSection != null) $(elActiveSection).css("background-color", "");
        elActiveSection = this;
        $(elActiveSection).css("background-color", "#cbe0ef");
        if (document.getElementById("SearchMap") != null) document.getElementById("SearchMap").focusSection(this.id.substr(2));
    }).click(function(e) {
        e.preventDefault();
        window.location.href = $(this).find("a").eq(0).attr("href");
    });
    
    
    if (Phizz.Browser.IsIE6) {
        var objs = Phizz.Dom.ByClass("A", "IMG");
        for (var i = 0; i < objs.length; i++) Phizz.Tools.EnableIE6ImageTransparency(objs[i]);
    }
});


function focusSection(id) {
    if (elActiveSection != null) {
        if (elActiveSection.id == "s_" + id) return;
        $(elActiveSection).css("background-color", "");
    }
    elActiveSection = document.getElementById("s_" + id);
    $(elActiveSection).css("background-color", "#cbe0ef");
    
	var currentScrollTop = GetElement("WalkList").scrollTop;
	var currentScrollBottom = currentScrollTop + GetElement("WalkList").offsetHeight;
	var targetScroll = GetElement("s_" + id).offsetTop;
	if (targetScroll < currentScrollTop || targetScroll > currentScrollBottom - 20) {
		//disableOnMouseOver = true;
		GetElement("WalkList").scrollTop = targetScroll;
	}
}

function clickSection(id) {
    window.location.href = $("#s_" + id).find("a").eq(0).attr("href");
}
	

function validateSearch() {
    return (
		ValChecked("c", "Please select at least one County.") &&
		ValChecked("t", "Please select at least one Length.")
	);  //SetURLParameters(["Keywords", "County", "Length"], [GetElement("Keywords").value, GetCheckedValue("County"), GetCheckedValue("Length")]);
}



	

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.style.backgroundColor = oldBg;
		objActiveWalk = obj;
		oldBg = objActiveWalk.style.backgroundColor;
		objActiveWalk.style.backgroundColor = "#cbe0ef";
		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.style.backgroundColor = oldBg;
	objActiveWalk = GetElement("w_" + id);
	oldBg = objActiveWalk.style.backgroundColor;
	objActiveWalk.style.backgroundColor = "#d0e3f1";
}
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 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 fixIE6PNGs2() {
	if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.indexOf("MSIE 6.0") > -1 || navigator.appVersion.indexOf("MSIE 5.5") > -1)) {
		var src = "";
		var objsImg = document.getElementsByTagName("IMG");
		for (var i = 0; i < objsImg.length; i++) {
			src = objsImg[i].src;
			if (src.indexOf(".png") == src.length - 4) {
				objsImg[i].src = "/ulsterway/i/_.gif";
				objsImg[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', src='" + src + "')";
			}
		}
		
	}
}

RegisterEvent("Window_OnLoad", "FixTitle");



