HERSHEYS.JollyRancher = {};
HERSHEYS.JollyRancher.simplyScroll = function(){
	$(".nav").simplyScroll({
		className: 'horiz',
		horizontal: true,
		frameRate: 20,
		speed: 20
	});
};

HERSHEYS.JollyRancher.tabbedBrowsing = function(){
	HERSHEYS.TabbedBrowsing.init();

	$(HERSHEYS.TabbedBrowsing).bind('NewItemShowing', function (e, data) {
		var productName = $(data).attr('title');
		HERSHEYS.Analytics.doProductView(productName);
	});
};

/* randomized fruit-related global variables for Jolly-Rancher */
var fruits = new Array("grape", "apple", "watermelon");
var randomFruit = ((fruits[Math.floor(Math.random() * fruits.length)]));
var randomStyle = false;

HERSHEYS.JollyRancher.initializations = {

    'jolly-rancher': function () {

        randomStyle = true;

        var flashvars = { 'fruitname': randomFruit };
        var attributes = {};
        var param = { wmode: 'transparent' };

        swfobject.embedSWF("/assets/swf/jollyranchers/JollyRanchersHome.swf",
              "flash_wrap", "100%", "502px", "10.0.0",
              "/assets/swf/expressInstall.swf", flashvars, param, attributes, function (e) {
                  if (!e.success)
                      $('#home-bg-ani').removeClass('no_bg');

              });

        /*        $(HERSHEYS.Rotator).bind('NewItem', function (e, data) {
        var current = $('.rotator_wrapper').find('.active');
        current.hide().fadeIn(1000);
        var index = current.attr('id').replace('home', '');
        HERSHEYS.JollyRancher.UpdateFlash(Number(index) - 1);
        });

        HERSHEYS.Rotator.init();
        */
    },

    'jolly-rancher/our-story': function () {

        var flashvars = {};
        var attributes = {};
        var param = { wmode: 'transparent' };

        swfobject.embedSWF("/assets/swf/jollyranchers/JollyRanchersOurStory.swf",
              "flash_wrap", "100%", "502px", "10.0.0",
              "/assets/swf/expressInstall.swf", flashvars, param, attributes, function (e) {
                  if (!e.success) {
                      $('#main').show();
                  }
              });

        HERSHEYS.TabbedBrowsing.init({
            navSelector: '#our-story-tabbed-nav .nav a',
            contentSelector: '#our-story-tabbed-content .tabbedContent',
            'nextSelector': '.next-story',
            'previousSelector': '.prev-story'
        });
        $(HERSHEYS.TabbedBrowsing).bind('NewItemShowing', function (e, data) {
            var productName = $(data).attr('title');
            HERSHEYS.Analytics.doProductView(productName);
        });

    },

    'jolly-rancher/experience/fan-videos': function () {
		$('.modal_popup_video').fancybox({
			"overlayOpacity": 0.5,
			"overlayColor": "#000",
			'onStart': function (){
				$('.fancy-bg').each(function(){ $(this).addClass('nuebg').css('filter', 'none'); });
				$('#fancybox-outer').addClass('nuebg');
				$('#fancybox-close').addClass('alt');
			},
			'onClosed': function (){
				$('.fancy-bg').each(function(){ $(this).removeClass('nuebg') });
				$('#fancybox-outer').removeClass('nuebg');
				$('#fancybox-close').removeClass('alt');
			}
		});
    },

    'jolly-rancher/products': HERSHEYS.JollyRancher.simplyScroll,
    'jolly-rancher/seasonal': HERSHEYS.JollyRancher.simplyScroll,
    'jolly-rancher/products/hard-candy': HERSHEYS.JollyRancher.tabbedBrowsing,
    'jolly-rancher/products/fruit-chews': HERSHEYS.JollyRancher.tabbedBrowsing,
    'jolly-rancher/products/stix': HERSHEYS.JollyRancher.tabbedBrowsing,
    'jolly-rancher/products/jelly-beans': HERSHEYS.JollyRancher.tabbedBrowsing,
    'jolly-rancher/products/lollipops': HERSHEYS.JollyRancher.tabbedBrowsing,
    'jolly-rancher/seasonal/halloween': HERSHEYS.JollyRancher.tabbedBrowsing
};

HERSHEYS.Utility.doPageInits(HERSHEYS.JollyRancher.initializations);

$(document).ready(function () {

    /* append to the <body> a class based on the randomized fruit global variable earlier in this file */
    if (randomStyle == true) {
        var bodyClassName = 'jolly-rancher-' + randomFruit;
        $('body').addClass(bodyClassName);
    }

    /* Wire up search result button to field and search result page. */
    HERSHEYS.Utility.stealSearchButton({
        'site': 'jolly-rancher'
    });

    /* Enable leaving notice binding */
    HERSHEYS.Utility.leavingNotice({
        'transparency': HERSHEYS.transparency,
        'title': 'JOLLYRANCHER'
    });
    HERSHEYS.ShareThis.init();

});


