﻿
(function ($) {

//    $(document).ready(function () {
//    });

    $(window).load(function () {
        HomepageHelper.hasImages();
        //HomepageHelper.getPhotoupload();
        //HomepageHelper.formatBrandTiles(7);
        HomepageHelper.formatPlaytimeTiles(7);

        // popunder:
        // fpstore get 50% of weight; 
        // window name "ecommpop" is used by ecomm site for pop under tracking, thus it can't be changed.
        // ecomm keycode "F25348" is used to track the sales generated by fp.com pop-under and has to stay
        // update: took keycode down on 11/10/2010; took down link: '/us/fpstore_leaving.asp?goto=fpstore&dest=http://www.fisher-pricestore.com/pls/fp/prthr?rd=F25348&pid=fromEasterEcommPopunder|800|600|EcommPop|menubar|toolbar|location|scrollbars|resizable'
        var urls = [
        //'/moments/default_popunder.aspx|800|600|FacebookLandingPopunder|menubar|toolbar|location|scrollbars|resizable',
        //'/moments/default_popunder.aspx|800|600|FacebookLandingPopunder|menubar|toolbar|location|scrollbars|resizable',
        //'/us/infantcoupon_pop_under.asp|600|470|InfPopunder',
        //'/us/trio_pop_under.asp|700|630|TrioPopunder',
        //'/us/infant_cbs/infant_cbs_pop_under.asp|900|690|InfPopunder|menubar|toolbar|location|scrollbars|resizable',
			//'/fp.aspx?st=10&e=storelanding|800|600|EcommPop|menubar|toolbar|location|scrollbars|resizable',
            //'/us/CelebrateNsave_Pop_Under.asp|1010|445|CelebrateNsavePop|menubar|toolbar|location|scrollbars|resizable'
		];
       /* if (!noPup && (urls.length > 0) && (!readCookie("ecommnopup") || readCookie("ecommnopup") != "1")) {
            HomepageHelper.popUnder(urls, '', 0);
            //HomepageHelper.popUnder(urls, 'ecommnopup', 1);
            document.cookie = "ecommnopup=1";
        } else {
            document.cookie = "ecommnopup=1";
        }*/

        jQuery("#top-tiles").jcarousel({
            scroll: 1,
            auto: 4,
            wrap: 'circular',
            boxid: 'top-tiles',
            initCallback: mycarousel_initCallback,
            //itemLoadCallback: { onBeforeAnimation: mycarousel_itemLoadCallback }, //mycarousel_itemLoadCallback,
            itemFirstInCallback: mycarousel_firstInCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
        /**
        * We use the initCallback callback
        * to assign functionality to the controls
        */
        function prevShowHide(boxid) {
            if ($('#' + boxid + ' .jcarousel-control a:first-child').is(".active")) { $('#' + boxid + ' .mycarousel-prev').hide(); }
            else { $('#' + boxid + ' .mycarousel-prev').show(); }
        }
        function nextShowHide(boxid) {
            if ($('#' + boxid + ' .jcarousel-control a:last-child').is(".active")) { $('#' + boxid + ' .mycarousel-next').hide(); }
            else { $('#' + boxid + ' .mycarousel-next').show(); }
        }

        function mycarousel_itemLoadCallback(carousel, state) {
            for (var i = carousel.first; i <= carousel.last; i++) {
                if (carousel.has(i)) {
                    if (!carousel.get(i).find('img').get(0).complete) {
                        $("#currentImg").html('loading ' + carousel.first);
                        carousel.stopAuto();
                        carousel.get(i).find('img')
						.one('load', function () { // when it finishes loading 
						    $(this).fadeIn(); // Fade it in when loaded 
						    carousel.startAuto();
						    $("#currentImg").html('loaded ' + carousel.first);
						})
                        //.attr('src', newImage) //Set the source so it begins fetching 
						.each(function () {
						    // Cache fix for browsers that don't trigger .load() 
						    if (this.complete) $(this).trigger('load');
						});
                    } else {
                        $("#currentImg").html(carousel.first);
                    }
                }
            }
        };

        function trigger(carousel, state) {
            $("#currentImg").html(carousel.first);
        }

        function mycarousel_firstInCallback(carousel, li_object, index, state) {
            var boxid = carousel.options.boxid;
            if (!carousel.autoStopped) {
                if ($('#' + boxid + ' .jcarousel-control a.active').length == 0) {
                    $('#' + boxid + ' .jcarousel-control a:first-child').addClass('active');
                } else {
                    if ($('#' + boxid + ' .jcarousel-control a:last-child').hasClass('active')) {
                        $('#' + boxid + ' .jcarousel-control a:first-child').addClass('active');
                        $('#' + boxid + ' .jcarousel-control a.active:not(:first-child)').removeClass('active');
                    } else {
                        $('#' + boxid + ' .jcarousel-control a.active:not(:last-child)').next().addClass('active');
                        $('#' + boxid + ' .jcarousel-control a.active + a.active').prev().removeClass('active');
                    }
                }
            }
        }
        function mycarousel_initCallback(carousel) {
            var boxid = this.boxid;
            var pagesize = 1;

            // Disable autoscrolling if the user clicks the prev, next button or pagination buttons.
            $('#' + boxid + ' .jcarousel-control a').bind('click', function () {
                carousel.startAuto(0);
                var index = $(this).text();
                carousel.scroll(jQuery.jcarousel.intval((index - 1) * pagesize + 1));
                if (carousel.autoStopped) {
                    $('#' + boxid + ' .jcarousel-control a').removeClass('active'); //Remove any "active" class
                    $(this).addClass('active');
                }
                //prevShowHide(boxid);
                //nextShowHide(boxid);
                return false;
            });

            $('#' + boxid + ' .mycarousel-next').bind('click', function () {
                carousel.startAuto(0);
                carousel.next();
                if (carousel.autoStopped) {
                    if ($('#' + boxid + ' .jcarousel-control a:last-child').hasClass('active')) {
                        $('#' + boxid + ' .jcarousel-control a:first-child').addClass('active');
                        $('#' + boxid + ' .jcarousel-control a.active:not(:first-child)').removeClass('active');
                    } else {
                        $('#' + boxid + ' .jcarousel-control a.active:not(:last-child)').next().addClass('active');
                        $('#' + boxid + ' .jcarousel-control a.active + a.active').prev().removeClass('active');
                    }
                }
                //prevShowHide(boxid);
                //nextShowHide(boxid);
                return false;
            });

            $('#' + boxid + ' .mycarousel-prev').bind('click', function () {
                carousel.startAuto(0);
                carousel.prev();
                if (carousel.autoStopped) {
                    if ($('#' + boxid + ' .jcarousel-control a:first-child').hasClass('active')) {
                        $('#' + boxid + ' .jcarousel-control a:last-child').addClass('active');
                        $('#' + boxid + ' .jcarousel-control a.active:not(:last-child)').removeClass('active');
                    } else {
                        $('#' + boxid + ' .jcarousel-control a.active:not(:first-child)').prev().addClass('active');
                        $('#' + boxid + ' .jcarousel-control a.active + a.active').removeClass('active');
                    }
                }
                //prevShowHide(boxid);
                //nextShowHide(boxid);
                return false;
            });
            // Pause autoscrolling if the user moves with the cursor over the clip.
            carousel.clip.hover(function () {
                carousel.stopAuto();
            }, function () {
                carousel.startAuto();
            });
            //$('#' + boxid + ' .jcarousel-control a:first-child').click();
            //$('#' + boxid + ' .jcarousel-control a:eq(0)').click();
        };
    });

})(jQuery);

window.alert = function() {return;};


