HERSHEYS.Reeses = {

    Navigation: function () {

        HERSHEYS.TabbedBrowsingInt.init();

        $(HERSHEYS.TabbedBrowsingInt).bind('NewItemShowing', function (e, data) {
            var productName = $(data).attr('title');
            HERSHEYS.Analytics.doProductView(productName);
        });
		
		HERSHEYS.TabbedBrowsing.init();

        $(HERSHEYS.TabbedBrowsing).bind('NewItemShowing', function (e, data) {
            var productName = $(data).attr('title');
            HERSHEYS.Analytics.doProductView(productName);
        });
    }
};

HERSHEYS.Reeses.updateProducts = function(){
  
  
    // find the parent
    var parentDiv = $('.nav a.active').parent().parent();

    // Update the image
    var src = parentDiv.find('img').attr('src').replace('width=180', 'width=380').replace('width=120', 'width=200');
    $('#products-big-image').find('img').attr('src', src);

    // Update the title
    $('#products-title').html(parentDiv.find('.label a').attr('title'));

    // Update the description copy
    $('#products-text').html(parentDiv.find('.description').html());

    // Update the Nutritional Information link
    var url = parentDiv.find('a').attr('href');
    $('#products-nutrition').attr('href', url);

    url == '#' ? $('#products-nutrition').hide() : $('#products-nutrition').show();

  
};

HERSHEYS.Reeses.Products = function () {

    HERSHEYS.TabbedBrowsing.init({
        navSelector: '#content-yellow-wrapper .nav a',
        contentSelector: '#products-top .tabbedContent'
    });

    $(HERSHEYS.TabbedBrowsing).bind('NewItemShowing', function (e, data) {
  
        $('html,body').animate({ scrollTop: 0 }, 500, "easeInOutQuad", function () {
            HERSHEYS.Reeses.updateProducts();
        });

        var productName = $(data).attr('title');
        HERSHEYS.Analytics.doProductView(productName);

    });

  HERSHEYS.Reeses.updateProducts();

    $(HERSHEYS.TabbedBrowsing).bind('DeepLinked', function (e, data) {
        HERSHEYS.Reeses.updateProducts();
    });

}


HERSHEYS.Reeses.initializations = {

    /* HOMEPAGE */
    'reeses': function () {

        /* Reeses minis takever */
        (function () {
            var url1 = '/reeses/experience/watch.aspx?ICID=RES1060';
            var url2 = '/reeses/products.aspx?ICID=RES1059';
            var flashvars = {};
            var attributes = {};
            var param = { wmode: 'transparent' };
            swfobject.embedSWF("/assets/swf/reeses/Resses_minis_takeover.swf", "flash_wrap", "950", "391", "10.0.0", "", flashvars, param, attributes, function (e) {
                if (e.success) {
                    $('#content').css({ 'background-image': 'none', 'position': 'relative' });
                    //  $('#content').append('<a class="replace" style="position: absolute; height: 30px; top: 237px; left: 123px; width: 203px; z-index: 999;" href="'+url1+'"></a><a class="replace" style="position: absolute; height: 30px; top: 277px; left: 123px; width: 203px; z-index: 999;" href="'+url2+'"></a>');
                }
            });
        })();

        /* OLD ROTATOR
        HERSHEYS.Rotator.init({
        autoRotate:6000,
        fadeLength : 1000
        }); */

    },





    /* PRODUCTS */
    'reeses/products': HERSHEYS.Reeses.Products,
    'reeses/recipes-and-ideas/seasonal/products': HERSHEYS.Reeses.Products,

    'reeses/experience/facts': function () {

        HERSHEYS.Rotator.init();
        $(HERSHEYS.Rotator).bind('NewItem', function (e, data) {
            var name = $(data).attr('omnititle');
            HERSHEYS.Analytics.doPageView('experience:facts', name);
        });

    },

    'reeses/experience/download': function () {

        HERSHEYS.Carousel.init({
            slideDistance: 158,
            disableAnimation: true,
            numVisible: 4
        });

        $(HERSHEYS.Carousel).bind('SlideStart', function (e, data) {

            $('#current-carousel-item').find('img').attr('src', '');
            var name = $(data).attr('alt');

        });

        $(HERSHEYS.Carousel).bind('SlideComplete', function (e, data) {
            var src = $(data).attr('src');
            var popup = src.replace('/download/', '/download_1024x768_jpg/');

            var image = $('#current-carousel-item').find('img');
            image.hide();
            image.attr('src', src);
            image.fadeIn(500);
            image.parent().attr('href', popup);

        });

        $('.download .popupImage').bind('click', function () {
            var downloadname = $(this).find('img').attr('alt');
            HERSHEYS.Analytics.doDownload('IMG', downloadname);
        });

    },
    'reeses/experience/gallery': function () {
        HERSHEYS.Carousel.init({
            slideDistance: 158,
            disableAnimation: true,
            numVisible: 4
        });

        $(HERSHEYS.Carousel).bind('SlideStart', function (e, data) {
            $('#current-carousel-item').find('img').attr('src', '');

            var name = $(data).attr('alt');
            HERSHEYS.Analytics.doPrintAdView('experience:gallery', name);

        });

        $(HERSHEYS.Carousel).bind('SlideComplete', function (e, data) {
            var src = $(data).attr('src');

            var img = $('#current-carousel-item').find('img');
            img.hide();
            img.attr('src', src);
            img.fadeIn(500);
        });

    },
    'reeses/promotions/green-lantern': function () {
        if ($('.greenLantern-anim').length > 0) {
            var greenAnimTimeout = setTimeout(function () {
                animateLantern(1000);
            }, 10000);
        }

        $('.skipAnimation').click(function () {
            animateLantern(0);
        });

        var animateLantern = function (speed) {
            $('.greenLantern-anim.txtInBrightest').animate({ 'opacity': '0' }, speed);
            $('.greenLantern-anim.instantlyWin').animate({ 'opacity': '1' }, speed);
            $('.skipAnimation').hide();
        }
    },
    'reeses/promotions': function () {
        $('.learn.modal_popup').fancybox({
            'autoScale': false,
            'onStart': function () {
                var headerH = document.getElementById('header').offsetHeight,
			footerH = document.getElementById('footer').offsetHeight,
			wrapperH = window.innerHeight - headerH - footerH;
                document.getElementById('fancybox-overlay').style.height = '100%';
            },
            'onComplete': function () {
                $("#pr_rules .pr_jscroll").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 20, showArrows: false });
            }
        });
    },
    'reeses/promotions/green-lantern/prizes': function () {

        if ($('.green-lantern').length > 0) {
            HERSHEYS.TabbedBrowsing.init({
                navSelector: '.green-lantern .MenuPrizes a',
                contentSelector: '.green-lantern .tabbedBrowsingInt .tabbedContentInt'
            });
        }
    },
    'reeses/promotions/green-lantern/characters': function () {
        var attributes = {};
        var flashvars = {};
        var params = { wmode: "transparent" };

        flashvars.config = "/xml/greenlantern-config.xml";
        flashvars.apppath = "/assets/swf/greenlantern/GreenLanternPromo.swf";
        swfobject.embedSWF("/assets/swf/greenlantern/PromoLoader.swf", "flashContent", "100%", "340", "9.0", null, flashvars, params);

    }
    /* ETC */
};

HERSHEYS.Utility.doPageInits(HERSHEYS.Reeses.initializations);

$(document).ready(function () {

    /* Wire up search result button to field and search result page. */
    HERSHEYS.Utility.stealSearchButton({
        'site': 'reeses'
    });


    /* Enable leaving notice binding */
    HERSHEYS.Utility.leavingNotice({
        'transparency': HERSHEYS.transparency,
        'title': 'REESE\'S'
    });

    HERSHEYS.ShareThis.init();

    //TODO: timmy: Dan - please modify the follwoing to set the path to the Instant Win images and associated descriptions as applicable...

    //this is the image for instant win First Prize...
    $("#Reeses-Perfect-Seat_prize_pic_prize1").html("<img src='/assets/images/reeses/promotions/ncaa/instant_first_prize.jpg'>");
    //this is the HTML description for instant win First Prize...
    $("#Reeses-Perfect-Seat_prize_message_prize1").html("<p>You have won a REESE'S&reg; Orange 100% Genuine Leather Recliner and will be entered into our Grand Prize Drawing!</p><p>Please allow 6-8 weeks for the delivery of your prize.</p>");

    //this is the image for instant win Second Prize...
    $("#Reeses-Perfect-Seat_prize_pic_prize2").html("<img src='/assets/images/reeses/promotions/ncaa/instant_second_prize.jpg'>");
    //this is the HTML description for instant win Second Prize...
    $("#Reeses-Perfect-Seat_prize_message_prize2").html("<p>You have won REESE'S&reg; Premium Stadium Seat Cushion and will be entered into our Grand Prize Drawing!</p><p>Please allow 6-8 weeks for the delivery of your prize.</p>");

});

