﻿/* Variables */
var fishingExpanded = false;
var shootingExpanded = false;

/* Function Definitions */
function expandFishing() {
    fishingExpanded = true;
    shootingExpanded = false;

    //Stop mouseover animations
    stopAllAnimations();

    //Move shooting column across to 840px;
    $('#shootingImageWrapper').animate({ left: "840px" }, { duration: 1000, complete: function () {
        //Hide text
        hideTextFishingExpand();

        //Show the fishing subtitle and link (will do nothing if they're already showing)
        $('#fishingSubtitle').fadeIn('fast');
        $('#fishingLink').fadeIn('fast');

        //Show the small shooting title
        $('#shootingTitleVertical').fadeIn('fast');

        $("#freshwaterSpeciesSelect").fadeIn('fast');
        $("#saltwaterSpeciesSelect").fadeIn('fast');
    }
    });

    //Hide the shooting availability and destination (if showing), then fade in the fishing blocks when completed
    $('#shootingAvailability').fadeTo('fast', 0, function () {
        $('#fishingDestination').fadeTo('fast', 1);
    });
    $('#shootingDestination').fadeTo('fast', 0, function () {
        $('#shootingDestination').css('display', 'none');
        $('#fishingNewsReports').fadeTo('fast', 1);
    });
}

function hideTextFishingExpand() {
    //Hide hints
    $('#hintRightArrow').fadeTo('fast', 0);
    $('#hintLeftArrow').fadeTo('fast', 0);

    //Hide the text in shooting
    $('#shootingSubtitle').fadeOut('fast');
    $('#shootingLink').fadeOut('fast');
    $('#shootingTitleHorizontal').fadeOut('fast');

    //Hide the fishing title(s) too
    $('#fishingTitleHorizontal').fadeOut('fast');
    $('#fishingTitleVertical').fadeOut('fast');
}

function expandShooting() {
    shootingExpanded = true;
    fishingExpanded = false;

    $("#freshwaterSpeciesSelect").hide();
    $("#saltwaterSpeciesSelect").hide();

    //Stop all current animations and begin this one
    stopAllAnimations();

    //Move shooting column across to 46px;
    $('#shootingImageWrapper').animate({ left: "46px" }, { duration: 1000, complete: function () {
        //Hide text
        hideTextShootingExpand();

        //Show the subtitle and link (will do nothing if they're already showing)
        $('#shootingSubtitle').fadeIn('fast');
        $('#shootingLink').fadeIn('fast');

        //Show the small fishing title
        $('#fishingTitleVertical').fadeIn('fast');
    }
    });

    //Hide the fishing offer and destination (if showing) then fade in the shooting blocks when completed
    $('#fishingNewsReports').fadeTo('fast', 0, function () {
        $('#shootingDestination').fadeTo('fast', 1);
    });
    $('#fishingDestination').fadeTo('fast', 0, function () {
        $('#fishingDestination').css('display', 'none');
        $('#shootingAvailability').fadeTo('fast', 1);
    });

    
}

function hideTextShootingExpand() {
    //Hide hints
    $('#hintRightArrow').fadeTo('fast', 0);
    $('#hintLeftArrow').fadeTo('fast', 0);

    //Hide the text in fishing
    $('#fishingSubtitle').fadeOut('fast');
    $('#fishingLink').fadeOut('fast');
    $('#fishingTitleHorizontal').fadeOut('fast');

    //Hide the shooting title(s) too
    $('#shootingTitleHorizontal').fadeOut('fast');
    $('#shootingTitleVertical').fadeOut('fast');
}

function hintFishing() {
    //Stop all current animations and begin this one
    stopMouseoverAnimations();

    //Reset the columns
    resetColumns();

    //Move the shooting column a little bit right
    $('#shootingImageWrapper').delay(1000).animate({ left: "+=37" }, { duration: 1000, easing: 'easeOutBack', complete: function () {
        $('#hintRightArrow').fadeTo('fast', 1);
    }
    });
}

function hintShooting() {
    //Stop all current animations and begin this one
    stopMouseoverAnimations();

    //Reset the columns
    resetColumns();

    //Move the shooting column a little bit left
    $('#shootingImageWrapper').delay(1000).animate({ left: "-=37" }, { duration: 1000, easing: 'easeOutBack', complete: function () {
        $('#hintLeftArrow').fadeTo('fast', 1);
    }
    });
}

function resetColumns() {
    //Stop any mouseover animations
    stopMouseoverAnimations();

    //Remove any hint arrows
    $('#hintRightArrow').fadeTo('fast', 0);
    $('#hintLeftArrow').fadeTo('fast', 0);
    //Move the shooting column back
    $('#shootingImageWrapper').animate({ left: "443px" }, 'fast');
}

function stopMouseoverAnimations() {
    //Call stop on every element we move on mouseenter/leave to stop them messing with the main animation
    $('#shootingImageWrapper').stop(true);

    $('#hintRightArrow').stop(true);

    $('#hintLeftArrow').stop(true);
}

function stopAllAnimations() {
    //Call stop on every element we move, full stop
    $('#shootingImageWrapper').stop(true);

    $('#hintRightArrow').stop(true);
    $('#hintLeftArrow').stop(true);

    $('#fishingTitleHorizontal').stop(true);
    $('#fishingTitleVertical').stop(true);

    $('#shootingTitleHorizontal').stop(true);
    $('#shootingTitleVertical').stop(true);

    $('#fishingSubtitle').stop(true);
    $('#shootingSubtitle').stop(true);

    $('#fishingLink').stop(true);
    $('#shootingLink').stop(true);

    $('#fishingDestination').stop(true);
    $('#fishingNewsReports').stop(true);
    $('#shootingDestination').stop(true);
    $('#shootingAvailability').stop(true);
}


$(document).ready(function () {
    //Remove the anchor tags that provide no-JS features
    $('#fishingMouseOverWrapper').unwrap();
    $('#shootingMouseOverWrapper').unwrap();

    //animation for resizing fishing to be full width
    $('#fishingImageWrapper').click(function () {
        expandFishing();
    });

    //animation for resizing shooting to be full width
    $('#shootingImageWrapper').click(function () {
        expandShooting();
    });

    //bind handlers to form <select> elements
    $('#quarrySelect').change(function () {
        $('#quarrySelectForm').submit();
    });

    //bind handlers to form <select> elements
    $('#freshwaterSpeciesSelect').change(function () {
        $('#freshwaterSpeciesSelectForm').submit();
    });

    //bind handlers to form <select> elements
    $('#saltwaterSpeciesSelect').change(function () {
        $('#saltwaterSpeciesSelectForm').submit();
    });

    $('#shootingMouseOverWrapper').click(function () {
        if (shootingExpanded) {
            document.location.href = "/destinationShooting.aspx";
        }
    });

    $('#fishingMouseOverWrapper').click(function () {
        if (fishingExpanded) {
            document.location.href = "/destinationsFishing.aspx";
        }
    });

    $('#fishingNewsReports p.fishing-news:first').addClass("active");
    setInterval("rotateContent()", 6000);
});

function rotateContent() {
    rotateShootingAvailability();
    rotateFishingNews();
}

function rotateShootingAvailability() {
    var $active = $('#shootingAvailability p.availability.active');
    if ($active.length == 0) $active = $('#shootingAvailability p.availability:last');

    var $next = $active.next("p.availability").length > 0 ? $active.next("p.availability") : $('#shootingAvailability p.availability:first');

    $active.hide();
    $next.show();

    $active.removeClass("active");
    $next.addClass("active");
}

function rotateFishingNews() {
    var $active = $('#fishingNewsReports p.fishing-news.active');
    if ($active.length == 0) $active = $('#fishingNewsReports p.fishing-news:last');

    var $next = $active.next("p.fishing-news").length > 0 ? $active.next("p.fishing-news") : $('#fishingNewsReports p.fishing-news:first');

    $active.hide();
    $next.show();

    $active.removeClass("active");
    $next.addClass("active");
}
