﻿// A self-executing anonymous function,
// standard technique for developing jQuery plugins.
var firsttime = false;
var timerLoad = null;
(function ($) {


if(jQuery.browser.version != "7.0")
{
    $.fn.splashScreen = function (settings) {

        // Providing default options:

        settings = $.extend({
            textPositionX: [230, 65],
            textPositionY: [477, 575],
            textLayers: ['Styles/images/try_a_pair.png', 'Styles/images/main_gallery_name_06.jpg'],
            textShowTime: 500,
            textTopOffset: 80
        }, settings);


        var offsetImg = 0;
        var offset = 0;
        if ($.browser.webkit) {
            offset = +9;
            offsetImg = +9;

        }
        var ua = $.browser;
        if (ua.mozilla) {
            offset = 0;
            offsetImg = 0;

        }
        //alert(jQuery.browser.version);
        if (jQuery.browser.version == "8.0" ) {
            offset = 0;
            offsetImg = 2;
            $('body').css({ 'overflow-y': 'hidden' });
        }
          if (jQuery.browser.version == "9.0" ) {
            offset = 0;
            offsetImg = 0;
            $('body').css({ 'overflow-y': 'hidden' });
        }
        var promoIMG = this;
        //alert(promoIMG.css('backgroundImage'));
        // Creating the splashScreen div.
        // The rest of the styling is in splashscreen.css
        var splashScreen = $('<div>', {
            id: 'splashScreen',
            css: {
                backgroundImage: "url('Styles/images/main_img02.jpg')",
                backgroundPosition: ((($(document).width() / 2) - promoIMG.width() / 2) - offsetImg) + 'px ' + 75 + 'px',
                height: $(document).height()
            }
        });
        $('body').append(splashScreen);

        splashScreen.click(function () {
            splashScreen.fadeOut("slow");
            $('#navigation').fadeIn("slow");
            $(".scrollable").scrollable();
        });

        // Binding a custom event for changing the current visible text according
        // to the contents of the textLayers array (passed as a parameter)

        splashScreen.bind('changeText', function (e, newID) {

            // If the image that we want to show is
            // within the boundaries of the array:

            if (newID < 2) {
                showText(newID);
            }
            else {
                splashScreen.click();
            }
        });

        splashScreen.trigger('changeText', 0);

        // Extracting the functionality into a
        // separate function for convenience.

        function showText(id) {
            var text = $('<img>', {
                src: settings.textLayers[id],
                css: {
                    position: 'absolute',
                    top: promoIMG.offset().top + settings.textPositionY[id] + 'px',
                    left: promoIMG.offset().left + settings.textPositionX[id] - offset + 'px'
                }
            }).hide();

            text.ready(function () {
            if(!firsttime){
                firsttime = true;
                    text.delay(1000).fadeIn(1000).delay(settings.textShowTime).fadeIn(0, function () {
                    splashScreen.trigger('changeText', [id + 1]);
                });}
                else
                {
                    
                    text.fadeIn(400).delay(settings.textShowTime).fadeIn('slow', function () {
                    splashScreen.trigger('changeText', [id + 1]);
                    timerLoad = setTimeout("scroller()",1500);
                });
                }
            });
            splashScreen.append(text);

        }

        return this;
    }
    }


})(jQuery);

function scroller()
{
    $('body').css({ 'overflow-y': 'auto' });
}
