﻿function parkScroller_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function () {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function () {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function () {
        carousel.stopAuto();
    }, function () {
        carousel.startAuto();
    });
};

function parkScroller_itemLastInCallback(carousel, item, idx, state)
{
    var carouselSize = carousel.size();

    if (idx > carouselSize) {
        var curPos = (idx % carouselSize);
        if (curPos == 0) {
            curPos = carouselSize;
        }
    } else {
        curPos = idx;
    }

    
    var parkId = ($(item).attr('parkid'));
    //alert(parkId);
    var curParkData = null;
    var i = 0;
    for (i = 0; i < parkCoords.length; i += 1) {
        if (parkCoords[i].park_id == parkId) {
            curParkData = parkCoords[i];
        }
    }
    $("#parkMapMarker .parkName").text(curParkData.name);
    $("#parkMapMarker").attr("class", "marker" + curParkData.marker_style);
    $("#parkMapMarker").css("top", curParkData.top);
    $("#parkMapMarker").css("left", curParkData.left);

    var parkUrl = $('#imgmap20117516410 area[alt="' + curParkData.name + '"]').attr("href");
    $("#parkMapMarker .parkName").attr("href", parkUrl);
}

function parkScroller_onBeforeSlide(currentSlideNumber, totalSlideQty, currentSlideHtmlObject)
{
    var parkId = $(currentSlideHtmlObject).children('a').find('img').attr('parkid');
    var curParkData = null;
    var i = 0;
    for (i = 0; i < parkCoords.length; i += 1) {
        if (parkCoords[i].park_id == parkId) {
            curParkData = parkCoords[i];
        }
    }
    $("#parkMapMarker .parkName").text(curParkData.name);
    $("#parkMapMarker").attr("class", "marker" + curParkData.marker_style);
    $("#parkMapMarker").css("top", curParkData.top);
    $("#parkMapMarker").css("left", curParkData.left);

    var parkUrl = $('#imgmap20117516410 area[alt="' + curParkData.name + '"]').attr("href");
    $("#parkMapMarker .parkName").attr("href", parkUrl);
}

var largeRotator = null;

jQuery(document).ready(function () {
    $('.parkMapArea').click(function (event) {
        event.preventDefault();
        $('#parkMapMarker').show();
        largeRotator.stopShow();
        var parkTitle = $(this).attr('alt');
        var curParkData = null;
        var i = 0;
        for (i = 0; i < parkCoords.length; i += 1) {
            if (parkCoords[i].name == parkTitle) {
                curParkData = parkCoords[i];
                var wantedElm = $('#parkPhotoScrollerList li a img[parkid="' + parkCoords[i].park_id + '"]').parent().parent();
                var elmIndex = $('#parkPhotoScrollerList li').index(wantedElm);
                largeRotator.goToSlide(elmIndex);
            }
        }
        $("#parkMapMarker .parkName").text(curParkData.name);
        $("#parkMapMarker .parkName").attr("href", $(this).attr("href"));
        $("#parkMapMarker").attr("class", "marker" + curParkData.marker_style);
        $("#parkMapMarker").css("top", curParkData.top);
        $("#parkMapMarker").css("left", curParkData.left);
    });

    $('#parkMapMarker .closeButton').click(function (event) {
        event.preventDefault();
        $('#parkMapMarker').hide();
    });

    $('#parkPhotoScrollerList').show();
    $('#parkMapMarker').show();

    largeRotator = $('#parkPhotoScrollerList').bxSlider({
        auto: true,
        pause: 6000,
        onBeforeSlide: parkScroller_onBeforeSlide,
        mode: 'fade',
        speed: 1500,
        captions: true,
        captionsSelector: '#parkPhotoScrollerDescription'
    });

    $('#promoPhotoScrollerList').bxSlider({
        auto: true,
        pause: 8000
    });

    var firstImg = $($('#parkPhotoScrollerList').children('li')[0]).find('img');
    var parkId = $(firstImg).attr('parkid');
    var curParkData = null;
    var i = 0;
    for (i = 0; i < parkCoords.length; i += 1) {
        if (parkCoords[i].park_id == parkId) {
            curParkData = parkCoords[i];
        }
    }
    $("#parkMapMarker .parkName").text(curParkData.name);
    $("#parkMapMarker .parkName").attr("href", $(firstImg).parent().attr("href"));
    $("#parkMapMarker").attr("class", "marker" + curParkData.marker_style);
    $("#parkMapMarker").css("top", curParkData.top);
    $("#parkMapMarker").css("left", curParkData.left);
});

var parkCoords = [
    {
        name: "Aiken State Park",
        top: 79,
        left: 121,
        marker_style: "BotLeft",
        park_id: 1831
    },
    {
        name: "Andrew Jackson State Park",
        top: 88,
        left: 28,
        marker_style: "TopRight",
        park_id: 1797
    },
    {
        name: "Baker Creek State Park",
        top: 70,
        left: 85,
        marker_style: "BotLeft",
        park_id: 1764
    },
    {
        name: "Barnwell State Park",
        top: 93,
        left: 119,
        marker_style: "BotLeft",
        park_id: 1773
    },
    {
        name: "Caesars Head State Park",
        top: 81,
        left: 82,
        marker_style: "TopLeft",
        park_id: 1648
    },
    {
        name: "Calhoun Falls State Park",
        top: 122,
        left: 72,
        marker_style: "TopLeft",
        park_id: 1652
    },
    {
        name: "Charles Towne Landing State Historic Site",
        top: 120,
        left: 68,
        marker_style: "BotRight",
        park_id: 1575
    },
    {
        name: "Cheraw State Park",
        top: 98,
        left: 68,
        marker_style: "TopRight",
        park_id: 1554
    },
    {
        name: "Chester State Park",
        top: 107,
        left: 127,
        marker_style: "TopLeft",
        park_id: 1564
    },
    {
        name: "Colleton State Park",
        top: 107,
        left: 40,
        marker_style: "BotRight",
        park_id: 1876
    },
    {
        name: "Colonial Dorchester State Historic Site",
        top: 106,
        left: 61,
        marker_style: "BotRight",
        park_id: 725
    },
    {
        name: "Croft State Park",
        top: 95,
        left: 107,
        marker_style: "TopLeft",
        park_id: 1443
    },
    {
        name: "Devils Fork State Park",
        top: 88,
        left: 62,
        marker_style: "TopLeft",
        park_id: 1355
    },
    {
        name: "Dreher Island State Park",
        top: 48,
        left: 124,
        marker_style: "BotLeft",
        park_id: 1371
    },
    {
        name: "Edisto Beach State Park",
        top: 127,
        left: 55,
        marker_style: "BotRight",
        park_id: 1298
    },
    {
        name: "Givhans Ferry State Park",
        top: 102,
        left: 48,
        marker_style: "BotRight",
        park_id: 1219
    },
    {
        name: "Goodale  State Park",
        top: 50,
        left: 45,
        marker_style: "BotRight",
        park_id: 1199
    },
    {
        name: "H. Cooper Black Jr. Memorial Field Trial and Recreation Area",
        top: 106,
        left: 60,
        marker_style: "TopRight",
        park_id: 26716
    },
    {
        name: "Hamilton Branch State Park",
        top: 67,
        left: 89,
        marker_style: "BotLeft",
        park_id: 1188
    },
    {
        name: "Hampton Plantation  State Historic Site",
        top: 87,
        left: 92,
        marker_style: "BotRight",
        park_id: 1142
    },
    {
        name: "Hickory Knob State Resort Park",
        top: 54,
        left: 78,
        marker_style: "BotLeft",
        park_id: 1109
    },
    {
        name: "Hunting Island State Park",
        top: 139,
        left: 45,
        marker_style: "BotRight",
        park_id: 1019
    },
    {
        name: "Huntington Beach State Park",
        top: 79,
        left: 106,
        marker_style: "BotRight",
        park_id: 1020
    },
    {
        name: "Jones Gap State Park",
        top: 83,
        left: 92,
        marker_style: "TopLeft",
        park_id: 962
    },
    {
        name: "Keowee-Toxaway State Park",
        top: 87,
        left: 69,
        marker_style: "TopLeft",
        park_id: 972
    },
    {
        name: "Kings Mountain State Park",
        top: 85,
        left: 133,
        marker_style: "TopLeft",
        park_id: 945
    },
    {
        name: "Lake Greenwood State Park",
        top: 47,
        left: 107,
        marker_style: "BotLeft",
        park_id: 926
    },
    {
        name: "Lake Hartwell State Park",
        top: 104,
        left: 57,
        marker_style: "TopLeft",
        park_id: 927
    },
    {
        name: "Lake Warren State Park",
        top: 125,
        left: 128,
        marker_style: "BotLeft",
        park_id: 935
    },
    {
        name: "Lake Wateree State Park",
        top: 108,
        left: 148,
        marker_style: "TopLeft",
        park_id: 936
    },
    {
        name: "Landsford Canal  State Park",
        top: 98,
        left: 145,
        marker_style: "TopLeft",
        park_id: 916
    },
    {
        name: "Lee State Park",
        top: 115,
        left: 56,
        marker_style: "TopRight",
        park_id: 891
    },
    {
        name: "Little Pee Dee State Park",
        top: 115,
        left: 101,
        marker_style: "TopRight",
        park_id: 881
    },
    {
        name: "Musgrove Mill  State Historic Site",
        top: 109,
        left: 110,
        marker_style: "TopLeft",
        park_id: 3888
    },
    {
        name: "Myrtle Beach State Park",
        top: 71,
        left: 112,
        marker_style: "BotRight",
        park_id: 795
    },
    {
        name: "Oconee State Park",
        top: 98,
        left: 51,
        marker_style: "TopLeft",
        park_id: 750
    },
    {
        name: "Oconee Station  State Historic Site",
        top: 93,
        left: 57,
        marker_style: "TopLeft",
        park_id: 1887
    },
    {
        name: "Paris Mountain State Park",
        top: 96,
        left: 90,
        marker_style: "TopLeft",
        park_id: 722
    },
    {
        name: "Poinsett State Park",
        top: 73,
        left: 47,
        marker_style: "BotRight",
        park_id: 662
    },
    {
        name: "Redcliffe Plantation  State Historic Site",
        top: 84,
        left: 104,
        marker_style: "BotLeft",
        park_id: 2015
    },
    {
        name: "Rivers Bridge State Historic Site",
        top: 95,
        left: 134,
        marker_style: "BotLeft",
        park_id: 566
    },
    {
        name: "Rose Hill Plantation State Historic Site",
        top: 102,
        left: 120,
        marker_style: "TopLeft",
        park_id: 540
    },
    {
        name: "Sadlers Creek State Recreation Area",
        top: 114,
        left: 69,
        marker_style: "TopLeft",
        park_id: 1888
    },
    {
        name: "Santee State Park",
        top: 86,
        left: 40,
        marker_style: "BotRight",
        park_id: 535
    },
    {
        name: "Sesquicentennial State Park",
        top: 46,
        left: 28,
        marker_style: "BotRight",
        park_id: 469
    },
    {
        name: "Table Rock State Park",
        top: 86,
        left: 76,
        marker_style: "TopLeft",
        park_id: 350
    },
    {
        name: "Woods Bay State Park",
        top: 58,
        left: 63,
        marker_style: "BotRight",
        park_id: 216
    }
];
