﻿
var featureWiget = "off";
var posLeft = 0;
var origHeight = 0;
var centerFeatureContent = function(posLeft, strDisplay) {
    $(".feature_content").attr("style", "left: " + posLeft + "px; " + strDisplay);
}

$(document).ready(function () {
    initFeatures();
});

var initFeatures = function () {
    posLeft = Math.ceil(($(window).width() - $(".feature_content").width() - 1) / 2);

    $(window).resize(function () {
        var strDisplay = (featureWiget == "on") ? "display: block;" : "";
        posLeft = Math.ceil(($(this).width() - $(".feature_content").width() - 1) / 2);
        centerFeatureContent(posLeft, strDisplay);
    });
    centerFeatureContent(posLeft, "");

    if (aryFeature.length > 0)
        $(".feature_listing").html(generateFeatures());

    origHeight = $('.content_block').height() + "px";
    $(".featureClick").unbind("click").bind("click", function () {
        if (parseInt(origHeight) < $('.content_block').height())
            origHeight = $('.content_block').height() + "px";

        id = $(this).attr("id");
        if (featureWiget == "off") {
            $(".feature_content a.link").html("");

            $('#rays,#cap,#history,#phone').hide();
            $('.bottles').addClass('single');
            $('.theglass').hide("fast");

            $('html,body').animate({ scrollTop: 0 }, 1000);
            $('.content_block').animate({ height: '455px' }, 1000, function () {
                $('.content,.more-content').hide();
                $('.feature_link,.feature_content').fadeIn('slow', function () {
                    $("img.corner").show();
                });
                changeFeature(id);
            });

            lastFeature = $(this);
            lastFeature.removeClass("inactive").attr("disabled", "disabled");
            featureWiget = "on";
        }
        else {
            lastFeature.addClass("inactive").attr("disabled", "");
            lastFeature = $(this);
            lastFeature.removeClass("inactive").attr("disabled", "disabled");
            changeFeature(id);
        }
        return false;
    });

    $(".feature_content a.close").unbind("click").bind("click", function () {
        featureWiget = "off";
        $(".feature_link,.feature_content").fadeOut("slow", function () {
            $("img.corner").hide();
        });
        $(".content_block").animate({ height: origHeight }, 500, function () {
            $(".theglass").show("fast", function () {
                $(".bottles").removeClass("single");
            });
            lastFeature.addClass("inactive").attr("disabled", "");

            $('#rays,#cap,#history,#phone').show();
            $('.content,.more-content').show();
        });

        return false;
    });
}

var generateFeatures = function() {
    var strHtml = "<img src=\"" + strRoot + "/images/news.gif\" border=\"0\" class=\"sup promo\" />";
    for (var x = 0; x < aryFeature.length; x++) {
        promo = (x == 0) ? " promo" : "";
        strHtml = strHtml + " &nbsp; <img src=\"" + strRoot + "/images/f_line.gif\" class=\"sup" + promo + "\" /> &nbsp; <a href=\"" + aryFeature[x][2] + "\" id=\"f" + x + "\" class=\"inactive featureClick\"><img src=\"" + strRoot + "/features/" + aryFeature[x][0] + "\" border=\"0\" /></a>";
    }
    return strHtml;
}

var changeFeature = function(id) {
    index = id.replace('f', '');
    $(".feature_content a.link").fadeOut("slow", function() {
        $(".feature_content a.link").html("<img src=\"" + strRoot + "/features/" + aryFeature[index][1] + "\" border=\"0\" />").attr("href", aryFeature[index][2]).fadeIn("fast");
    });
}

