﻿//*************************************************************************************
// File     : wria_functions.js
// Version  : 1
// Requires : jquery.js (version 1.2.6+)
// Author   : Kyle Weems (ksw)
// Origin   : mindfly.com
// Created  : November 5, 2008
// Modified : December 22, 2008
//*************************************************************************************

var thisArea;
$(document).ready(function() { activationSequence(); });


// activationSequence()
function activationSequence() {

    setContentHeight(8);
    $(window).resize(function() { setContentHeight(8); });
    bindTextResizers();
    wriaJsonMaps();
    
} // end function


// bindTextResizers()
function bindTextResizers() {
    $('#small').bind('click', function() {
        $('#content').css('font-size', '12px');
    });
    $('#medium').bind('click', function() {
        $('#content').css('font-size', '14px');
    });
    $('#large').bind('click', function() {
        $('#content').css('font-size', '17px');
    });
} // end function


// wriaJsonMaps()
function wriaJsonMaps() {

    if ($('#watershedMapInfo').length > 0) {
        $.getJSON('/wriaJSON.txt', function(json) {
            var thisAreaName = $('.nav_breadcrumb + h2 + h3').html()
            for (i = 0; i < json.area.length; i++) {
                if (json.area[i].name == thisAreaName) {
                    thisArea = json.area[i];
                }
            }
            $('#liWMapGeo span').html(thisArea.name);
            loadMapSidebar(thisArea.location[0]);
            loadImageMap('watershedMap', thisArea);
            bindMapAreas('watershedMap');
        });
    }
} // end function


// loadMapSidebar()
function loadMapSidebar(location) {
    $('#liWMapName span').html(location.name);
    $('#liWMapID span').html(location.ID);
    $('#liWMapGage span').html(location.Gage);
    $('#liWMapAgency span').html(location.Agency);
    $('#liWMapPeriod span').html(location.Period);
    $('#h3WMapComments + p').html(location.Comments);
    $('#h5WMapCurrent + p').html(location.Current);
    $('#h5WMapRecommended + p').html(location.Recommended);
    if (location.link != "") {
        $('#h3ViewData').html('<a href="' + location.link + '" target="_blank" title="View Real Time Data">View Real Time Data</a>')
    } else {
        $('#h3ViewData').html('');
    }
} // end function


// loadImageMap()
function loadImageMap(map, area) {
    for (i = 0; i < area.location.length; i++) {
        document.getElementById(map).innerHTML += '<area shape="circle" coords="' + area.location[i].mapx + ',' + area.location[i].mapy + ',12" alt="' + area.location[i].name + '" />';
    }
} // end function


// bindMapAreas()
function bindMapAreas(map) {
    $('#' + map + ' area').bind('click', function() {
        var location = thisArea.location[$('#' + map + ' area').index($(this))];
        loadMapSidebar(location);
    });
} // end function