﻿(function ($)
{
    jQuery.fn.headerScript = function (options)
    {
        var defaults = {
            startTop: "-526",
            startRight: "-800",
            restingPosition: "50"
        };

        var o = jQuery.extend(defaults, options); ///Options are what you pass in to the function when you call it.

        return this.each(function ()
        {
            var el = $(this);
            var imgContainer = $(".headerContainer");
            var targetImage = imgContainer.children("img.homeHeadImg");
            var count = 0;
            var mastHeadText = $(".mastheadText");
            var specialsContainer = $("#special");
            var specialsText = $("#special .specialsImage");
            var timer; ///Declare in global scope to give access to other functions
            targetImage.css({
                display: "block"
            });


            $(".background").click(function ()
            {
                window.location = "views/content/contact.aspx";
            });

            var t = setTimeout(function ()
            {
                mastHeadText.fadeTo(200, 0, function ()
                {
                    $(".calloutTxt").fadeTo(200, 0);
                    $(".christmasSpecial").delay(300).fadeIn();
                    specialsContainer.delay(500).fadeIn().slide();
                });

            }, 4000);

            /////get the timer started yeah!

            el.bind('inview', function (event, isInView, visiblePartX, visiblePartY)
            {
                if (isInView)
                {
                    targetImage.animate({
                        right: o.restingPosition + "px"
                    }, 1000, 'swing', function ()
                    {
                        $(".mastheadText").fadeIn(400);
                        $(".calloutTxt").fadeIn(400).css("display", "block");
                    });
                }
            });
        });
    };
})(jQuery);
