// Wait Plugin Start
(function($) {
    $.fn.wait = function(option, options) {
        milli = 1000;
        if (option && (typeof option == 'function' || isNaN(option))) {
            options = option;
        } else if (option) {
            milli = option;
        }
        // set defaults
        var defaults = {
            msec: milli,
            onEnd: options
        },
        settings = $.extend({}, defaults, options);

        if (typeof settings.onEnd == 'function') {
            this.each(function() {
                setTimeout(settings.onEnd, settings.msec);
            });
            return this;
        } else {
            return this.queue('fx',
            function() {
                var self = this;
                setTimeout(function() { $.dequeue(self); }, settings.msec);
            });
        }

    }
})(jQuery);
// Wait Plugin END


// Random Number START
jQuery.extend({
    random: function(X) {
        return Math.floor(X * (Math.random() % 1));
    },
    randomBetween: function(MinV, MaxV) {
        return MinV + jQuery.random(MaxV - MinV + 1);
    }
});
// Random Number END


// Plane START

var cloudMoved = false;

$(init);

function init() {
    cloudMove();
}



function dayTime() {
    $("#Bird1").attr("src", "MediaFiles/Bird1.gif");
    $("#Bird2").attr("src", "MediaFiles/Bird2.gif");
    $("#Bird3").attr("src", "MediaFiles/Bird3.gif");
    $("#Island").css('background-image', 'url(MediaFiles/IslandBackground.jpg)');
    $("#Plane").css("display", "block");
    $("#HangGliderButton").css("display", "block");
    $("#HangGlider").css("display", "block");
}


function checkTime() {

    var currentTime = new Date()
    var hours = currentTime.getHours()

    if (hours == '6') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents06.png");
        dayTime()
    }
    if (hours == '7') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents07.png");
        dayTime()
    }
    if (hours == '8') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents08.png");
        dayTime()
    }
    if (hours == '9') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents09.png");
        dayTime()
    }
    if (hours == '10') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents10.png");
        dayTime()
    }
    if (hours == '11') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents11.png");
        dayTime()
    }
    if (hours == '12') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents12.png");
        dayTime()
    }
    if (hours == '13') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents13.png");
        dayTime()
    }
    if (hours == '14') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents14.png");
        dayTime()
    }
    if (hours == '15') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents15.png");
        dayTime()
    }
    if (hours == '16') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents16.png");
        dayTime()
    }
    if (hours == '17') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents17.png");
        dayTime()
    }
    if (hours == '18') {
        $("#IslandContents").attr("src", "MediaFiles/IslandContents18.png");
        dayTime()
    }
    if (hours >= 19) {
        $("#IslandContents").attr("src", "MediaFiles/IslandContentsNight.png");
        $("#Bird1").attr("src", "MediaFiles/Trans.gif");
        $("#Bird2").attr("src", "MediaFiles/Trans.gif");
        $("#Bird3").attr("src", "MediaFiles/Trans.gif");
        $("#Island").css('background-image', 'url(MediaFiles/IslandBackgroundNight.jpg)');
        $("#Plane").css("display", "none");
        $("#HangGliderButton").css("display", "none");
        $("#HangGlider").css("display", "none");
    }
    if (hours <= 5) {
        $("#IslandContents").attr("src", "MediaFiles/IslandContentsNight.png");
        $("#Bird1").attr("src", "MediaFiles/Trans.gif");
        $("#Bird2").attr("src", "MediaFiles/Trans.gif");
        $("#Bird3").attr("src", "MediaFiles/Trans.gif");
        $("#Island").css('background-image', 'url(MediaFiles/IslandBackgroundNight.jpg)');
        $("#Plane").css("display", "none");
        $("#HangGliderButton").css("display", "none");
        $("#HangGlider").css("display", "none");
    }



    if (hours >= 6) {
        if (hours <= 18) {

            var RandNum = ($.randomBetween(1, 3))
            if (RandNum == 1) {
                var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />I could lift 2 Mark Henry' + String.fromCharCode(39) + 's with my little finger<d1v>'
            }

            if (RandNum == 2) {
                var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />Have we seen the due diligence pack yet?<d1v>'
            }

            if (RandNum == 3) {
                var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />1 sugar please<d1v>'
            }
        }
    }
    if (hours >= 19) {

        var RandNum = ($.randomBetween(1, 3))
        if (RandNum == 1) {
            var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />A future in WWE may be for me<d1v>'
        }

        if (RandNum == 2) {
            var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />They may be BIG, but not beautiful<d1v>'
        }

        if (RandNum == 3) {
            var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />Night, night blackberry<d1v>'
        }
        
    }
    if (hours <= 5) {

        var RandNum = ($.randomBetween(1, 3))
        if (RandNum == 1) {
            var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />A future in WWE may be for me<d1v>'
        }

        if (RandNum == 2) {
            var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />They may be BIG, but not beautiful<d1v>'
        }

        if (RandNum == 3) {
            var JohnContent = '<div id=JBToolTip><b>John Byrne</b><br />Night, night blackberry<d1v>'
        }
        
    }



    if (hours >= 6) {
        if (hours <= 18) {

            var RandNum = ($.randomBetween(1, 3))
            if (RandNum == 1) {
                var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />I am disappointed that Joe didn' + String.fromCharCode(39) + 't make it to number 1<d1v>'
            }

            if (RandNum == 2) {
                var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />Does that product really exist?<d1v>'
            }

            if (RandNum == 3) {
                var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />We buy in bulk, I want bigger discounts?<d1v>'
            }
            
        }
    }
    if (hours >= 19) {

        var RandNum = ($.randomBetween(1, 3))
        if (RandNum == 1) {
            var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />I hope Victoria replaces Danni next year<d1v>'
        }

        if (RandNum == 2) {
            var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />It maybe night time but I am still reading emails<d1v>'
        }

        if (RandNum == 3) {
            var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />Has that product arrived yet?<d1v>'
        }
        
    }
    if (hours <= 5) {

        var RandNum = ($.randomBetween(1, 3))
        if (RandNum == 1) {
            var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />I hope Victoria replaces Danni next year<d1v>'
        }

        if (RandNum == 2) {
            var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />It maybe night time but I am still reading emails<d1v>'
        }

        if (RandNum == 3) {
            var BrantContent = '<div id=BMToolTip><b>Brant Marcus</b><br />Has that product arrived yet?<d1v>'
        }
        
    }



    if (hours >= 6) {
        if (hours <= 18) {

            var RandNum = ($.randomBetween(1, 3))
            if (RandNum == 1) {
                var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />I can hear pins drop from 100 miles away<d1v>'
            }

            if (RandNum == 2) {
                var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />They maybe cheaper, but they won' + String.fromCharCode(39) + 't deliver<d1v>'
            }

            if (RandNum == 3) {
                var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />I told you the product was vapourware<d1v>'
            }
            
        }
    }
    if (hours >= 19) {


        var RandNum = ($.randomBetween(1, 3))
        if (RandNum == 1) {
            var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />My infrared vision allows me to see in the dark<d1v>'
        }

        if (RandNum == 2) {
            var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />How many??<d1v>'
        }

        if (RandNum == 3) {
            var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />I should have taken up juggling...<d1v>'
        }
        
    }
    if (hours <= 5) {

        var RandNum = ($.randomBetween(1, 3))
        if (RandNum == 1) {
            var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />My infrared vision allows me to see in the dark<d1v>'
        }

        if (RandNum == 2) {
            var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />How many??<d1v>'
        }

        if (RandNum == 3) {
            var RebeccaContent = '<div id=RFToolTip><b>Rebecca Fuchs</b><br />I should have taken up juggling...<d1v>'
        }
        
    }




    $('#JohnByrneToolTip').qtip({
        position: {
            corner: {
                target: 'rightTop',
                tooltip: 'leftBottom'
            }
        },
        style: {

            border: {
                width: 1,
                radius: 8
            },


            name: 'blue',
            padding: '7px 13px',
            width: {
                max: 220,
                min: 0
            },
            tip: true
        },
        content: {
            text: JohnContent
        },
        hide: { effect: { type: 'fade', length: 430} }
    });


    $('#RebeccaToolTip').qtip({
        position: {
            corner: {
                target: 'rightTop',
                tooltip: 'leftBottom'
            }
        },
        style: {

            border: {
                width: 1,
                radius: 8
            },


            name: 'blue',
            padding: '7px 13px',
            width: {
                max: 220,
                min: 0
            },
            tip: true
        },
        content: {
            text: RebeccaContent
        },
        hide: { effect: { type: 'fade', length: 430} }
    });


    $('#BrantToolTip').qtip({
        position: {
            corner: {
                target: 'rightTop',
                tooltip: 'leftBottom'
            }
        },
        style: {

            border: {
                width: 1,
                radius: 8
            },


            name: 'blue',
            padding: '7px 13px',
            width: {
                max: 220,
                min: 0
            },
            tip: true
        },
        content: {
            text: BrantContent
        },
        hide: { effect: { type: 'fade', length: 430} }
    });


    $('#ToolTipOne').qtip({
        position: {
            corner: {
                target: 'rightMiddle',
                tooltip: 'leftBottom'
            }
        },
        style: {

            border: {
                width: 1,
                radius: 8
            },


            name: 'cream',
            padding: '7px 13px',
            width: {
                max: 220,
                min: 0
            },
            tip: true
        },
        content: {
            text: '<div class=StandardToolTipFont><b>Contact us</b><br />Diverse Electronics (UK) Ltd<br/>Unit 18<br/>Meadowcroft Way<br/>Leigh Business Park<br/>Leigh<br/>WN7 3XZ</div>'
        },
        hide: { effect: { type: 'fade', length: 430} }
    });





    $('#NoBull').qtip({
        position: {
            corner: {
                target: 'topMiddle',
                tooltip: 'bottomLeft'
            }
        },
        style: {
            background: '#FFFFFF',
            border: {
                width: 1,
                radius: 8,
                color: '#CC0000'
            }
                 ,


            name: 'dark',
            padding: '7px 13px',
            width: {
                max: 220,
                min: 0
            },
            tip: true
        },
        content: {
            text: '<div class=NoBullToolTipFont>No Bull in Diverse’s world</div>'
        },
        hide: { effect: { type: 'fade', length: 430} }
    });
    
}



function cloudMove() {
    if (!cloudMoved) {
        $("#Plane")
			.css("left", $("#Plane").offset().left)
    }

    // Check the time and display the relevant parts
    checkTime();
    
    
    // Speed
    speed = $.randomBetween(4000, 12000);

    // Pause
    $("#Plane").wait($.randomBetween(4000, 8000))
    

		.animate(
			{
			    left: $("#Sky").width()
			},

			cloudMoved ? speed : speed,
			"linear",
			function() {
			    $(this)
					.css("left", -parseInt($(this).css("width")))
					.css("top", $.randomBetween(30, 140) + "px")

                // Set the background
			    $("#Plane").css('background-image', 'url(MediaFiles/Plane' + $.randomBetween(1, 3) + '.gif)');
			    

			    cloudMoved = true;

			    cloudMove();
			}
		)
}

// Plane END