﻿/// <reference path="jquery-1.3.2-vsdoc.js"/> 
/*********************
Secret JS V1
*********************/
var productContainer;
var formType;
$(document).ready(function() {

    try {
        productInformation(); // Load Product Information and Scent Hover 
    }
    catch (e) {
        //swallow
       // alert("productInformation() error: " + e);
    }

});

function getHashTagValueFromForm(formValue) {
    return formValue.toLowerCase().replace(" ", "").replace("-", "");
}
function getFormHtmlValueFromHashTagValue(hashTagValue) {
    switch (hashTagValue) {
    //The only values that have to be added here are the ones that can't be converted straight to upper case (due to spaces, hyphens, etc)
        case "#invisiblesolid":
            return "INVISIBLE SOLID";

        case "#rollon":
            return "ROLL-ON";

        case "#bodyspray":
            return "BODY SPRAY";

        case "#bodymist":
            return "BODY MIST";

        default:
            return hashTagValue.replace("#", "").toUpperCase();
    }
}

$.expr[":"].econtains = function(obj, index, meta, stack) {
    return (obj.textContent || obj.innerText || $(obj).text() || "").toLowerCase() == meta[3].toLowerCase();
}


function checkHashTagValue() { 

    var navForm = '';
    try {
        var htmlValue = getFormHtmlValueFromHashTagValue(window.location.hash.toLowerCase());

        if (htmlValue != '') {
            navForm = $('a.productAvailability:econtains("' + htmlValue + '")').attr('id');
        }
    }
    catch (e) {
        navForm = '';
    }

    if (navForm != '') {
        //alert('navForm=' + navForm);
        try {
            showNewForm(navForm);
            return true;
        }
        catch (e) {
            //alert('error: ' + e);
            return false;
        }
    }
    return false;
}

function productInformation() {
if(!checkHashTagValue())
{
    //alert('default');
        $(".productFormScentGroup:first").show(); //Show first scent group
        $(".productAvailability:first").addClass("active");
        if ($(".productFormScentGroup:visible #productScents a:first").html() != null) {
            activateScent($(".productFormScentGroup:visible #productScents a:first"));
        }
    }
    //   if ($('#wrapper').attr('class') != "original") {

    //Scent On Hover Event
    $('#productScents a').hover(function() {
        $(this).children('img.selectedBar').show();
        var scentText = $(this).children('span').html();
        $('.currentScent').html(scentText);
    }, function() {
        var activeText = $('#productScents a.active span').html();
        if ($(this).attr('class') != "active") {
            $(this).children('img.selectedBar').hide();
        }
        var scentText = $(this).children('span').html();
        $('.currentScent').html(activeText);
    });


    //Scent On Click Event
    $("#productScents a").click(function() {
        activateScent(this);
    });


    //Product Form On Click Event
    $(".productAvailability").click(function() {
        productContainer = $(this).attr('id');
        showNewForm(productContainer);
    });

    //Product Form - end
}
function activateScent(productScentAnchor) {
    $("#productScents a").children('img.selectedBar').hide();
    $("#productScents a").removeClass("active"); //Remove any "active" class
    $(productScentAnchor).addClass("active"); //Add "active" class to selected color
    $(productScentAnchor).children('img.selectedBar').show();

    var scentText = $(productScentAnchor).children('span').html();
    $('.currentScent').html(scentText);


    var scentImageSrc = $(productScentAnchor).attr('image');
    var imgAlt = $('div#productImage img').attr('alt');
    if ($.browser.msie) {
        $('div#productImage').html('<img src="' + ImagesBaseUrl + '/Images/Products/ProductShots/' + scentImageSrc + '" alt="' + imgAlt + '" />');
    }
    else {
        $('div#productImage').fadeOut('fast', function() {
            changeScentImage(scentImageSrc);
        });
    }
}

function changeScentImage(scentImageSrc) {
    $('div#productImage img').attr('src', '/Images/Products/ProductShots/' + scentImageSrc);
    $('div#productImage').fadeIn('fast');
}
function showNewForm(productID) {
//alert(productID);
    $(".productAvailability").removeClass("active"); //Remove form "active" class
    window.location.hash = getHashTagValueFromForm($('a#' + productID).html());
    $('a#' + productID).addClass('active'); //Add "active" class to selected product form

    var scentsDivName = productID.replace('form', '#scents');
    $('.productFormScentGroup').hide(); //Hide all scent groups
    $(scentsDivName).show(); //Show related scent group
    activateScent($(scentsDivName + " #productScents a:first"));
}
