﻿$(document).ready(function() { // wait until the DOM has loaded

    // show prev / next gallery
    // array of images is set on the advertising page
    $(".prevLink").click(function() {

        // get current image
        var currentSrc = $("div#advertisingGallery img").attr("src");
        var pos1 = currentSrc.lastIndexOf("/"); // last occurance of slash
        var pos2 = currentSrc.lastIndexOf("."); // last occurance of .
        currentSrc = currentSrc.substring(pos1 + 1, pos2);

        // get size of array
        var arrayLength = galleryArray.length;

        // get position of image in array
        var arrayPosition = getPosition(galleryArray, currentSrc);

        if (arrayPosition == 0) {
            arrayPosition = galleryArray.length - 1;
        } else {
            arrayPosition = arrayPosition - 1;
        }

        $("div#advertisingGallery img").attr("src", "images/" + galleryArray[arrayPosition] + ".jpg");
        return false;
    });

    $(".nextLink").click(function() {

        // get current image
        var currentSrc = $("div#advertisingGallery img").attr("src");
        var pos1 = currentSrc.lastIndexOf("/"); // last occurance of slash
        var pos2 = currentSrc.lastIndexOf("."); // last occurance of .
        currentSrc = currentSrc.substring(pos1 + 1, pos2);

        // get size of array
        var arrayLength = galleryArray.length;

        // get position of image in array
        var arrayPosition = getPosition(galleryArray, currentSrc);

        if (arrayPosition == galleryArray.length - 1) {
            arrayPosition = 0;
        } else {
            arrayPosition = arrayPosition + 1;
        }

        $("div#advertisingGallery img").attr("src", "images/" + galleryArray[arrayPosition] + ".jpg");
        return false;
    });

    function getPosition(arrayName, arrayItem) {
        var len = arrayName.length;
        for (var i = 0; i < len; i++) {
            if (arrayName[i] == arrayItem)
                return i;
        }
    }

    // show and hide fragrance notes
    // return false on note links
    $("a.topNoteHeader, a.heartNoteHeader, a.baseNoteHeader").click(function() { return false; });

    // top note
    $("a.topNoteHeader").hover(
            function() {
                // $("div#topNote").addClass("showNote");
                $("div#noteImage img").attr("src", "images/topNote.jpg");
				$("div#overview").attr("class", "hide");
				$("div#top_note").attr("class", "");
				$("div#heart_note").attr("class", "hide");
				$("div#base_note").attr("class", "hide");
            },
            function() {
                $("div#noteImage img").attr("src", "images/topNote.jpg");
				$("div#overview").attr("class", "");
				$("div#top_note").attr("class", "hide");
				$("div#heart_note").attr("class", "hide");
				$("div#base_note").attr("class", "hide");
            }
        );

    // heart note
    $("a.heartNoteHeader").hover(
            function() {
                $("div#noteImage img").attr("src", "images/heartNote.jpg");
				$("div#overview").attr("class", "hide");
				$("div#top_note").attr("class", "hide");
				$("div#heart_note").attr("class", "");
				$("div#base_note").attr("class", "hide");
            },
            function() {
                $("div#noteImage img").attr("src", "images/topNote.jpg");
				$("div#overview").attr("class", "");
				$("div#top_note").attr("class", "hide");
				$("div#heart_note").attr("class", "hide");
				$("div#base_note").attr("class", "hide");
            }
        );

    // base note
    $("a.baseNoteHeader").hover(
            function() {
                $("div#noteImage img").attr("src", "images/baseNote.jpg");
				$("div#overview").attr("class", "hide");
				$("div#top_note").attr("class", "hide");
				$("div#heart_note").attr("class", "hide");
				$("div#base_note").attr("class", "");
            },
            function() {
                $("div#noteImage img").attr("src", "images/topNote.jpg");
				$("div#overview").attr("class", "");
				$("div#top_note").attr("class", "hide");
				$("div#heart_note").attr("class", "hide");
				$("div#base_note").attr("class", "hide");
            }
        );


});