﻿//Adds The Box Site Logo Animation.
$(document).ready(function () {
    if (!isHtml5Support()) {
        window.location.href = "http://www.theboxsite.com/flashSite/HTML5.html";
        return;
    }

    $("#logo").hover(function (e) {
        clearTimeout(timer);
        timer = setTimeout(function () {
            $("#logobox").animate({ top: "0px" }, { queue: false, duration: 400, easing: "easeInBack" });
            $("#logotxt1").fadeOut(100).show("Slide");
            $("#logotxt2").show("Fast");
            timerForLogoUnderscore = setInterval(function () {
                $("#logotxt2").toggle();
            }, 200);
            var btninmp3 = $("#btninmp3");
            btninmp3[0].play();
        }, 200);
    },
    function () {
        clearTimeout(timer);
        timer = setTimeout(function () {
            $("#logobox").animate({ top: "22px" }, { queue: false, duration: 400, easing: "easeInBack" });
            $("#logotxt1").hide("Slide");
            $("#logotxt2").hide("Fast");
            clearInterval(timerForLogoUnderscore);
            clearInterval(timerForLogoUnderscore);
            var btnoutmp3 = $("#btnoutmp3");
            btnoutmp3[0].play();
        }, 200);

    });


    $("#logo").click(function () {
        window.location = "http://www.theboxsite.com";
    });

    executeDocumentReady(true);

    var x = window.location.hash;
    if (x != null && x.length > 0) {
        loadContent(x + ".html");
        return;
    }


});


function isHtml5Support() {
    var myAudio = document.createElement('audio');
    var canPlayMp3, canPlayOgg;
    if (myAudio.canPlayType) {

        // Currently canPlayType(type) returns: "", "maybe" or "probably" 

        canPlayMp3 = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/mpeg');
        canPlayOgg = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/ogg; codecs="vorbis"');
    }
    else {
        return false;
    }

    return canPlayMp3 || canPlayOgg;

}

function show_link() {
    centerNum--;
    var elem = centerArr[centerL - centerNum];
    $(elem).parent("li").css('height', 55);
    $(elem).animate({ fontSize: 50 }, 100, 'easeInBack', function () {
        Cufon.replace(elem, { textShadow: '-3px 2px 2px #cccccc' });
    }); 
    if (centerNum > 0) {
        timedShow();
    }
    
}

function timedShow() {
    var t = setTimeout("show_link()", 100)
}

var centerNum = 0;
var centerL = 0;
var centerArr = [];

function centerAnimate() {
    //
    centerNum = $('.mainOptions ul li a').length;
    centerL = $('.mainOptions ul li a').length - 1;
    centerArr = $('.mainOptions ul li a');
    $('.mainOptions ul li a').css('fontSize', 1);
    $('.mainOptions ul li').css('height', 0);
    var mp3 = $("#centermp3");
    if (mp3 != null && mp3[0].play != null) {
        setTimeout(function () {
            mp3[0].play();
        }, 100)
        
    }
    timedShow();
    //show_link();

}

function executeDocumentReady(bLoadingMain) {
    $(function () {
        $('html').fadeIn("slow").show();
    });

    //contact animation
    if ($(".contactAnim").length > 0) {
       
        $(".contactAnim").animate({
            width: "+=500",
            left: "-=250"

        }, { queue: false, duration: 1500 })
        var mp3 = $("#line");
        mp3[0].play();
    }

    //Cufon style elements
      if(!bLoadingMain)  
        Cufon.replace('.mainOptions a', { textShadow: '-3px 2px 2px #cccccc' });
      Cufon.replace('.menuUpRight a');
      Cufon.replace('.back a');
      Cufon.replace('.headline');
      Cufon.replace('#slogen p');

    $(".partnerLogin  a").click(function () {
        $(".loginForm").fadeIn(1000, function () {
        });
        return false;
    });
    $(".loginForm .back  a").click(function () {
        $(".loginForm").fadeOut(1000, function () {
        });
        return false;
    });

    //lets chack if this is iphone or ipad
    function checkIfIphone() {
        if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
            //if this is Iphone we are going to build a special effects only for Ipjone

//            $('head').append('<link rel="stylesheet" href="/Styles/IpadOrIphone.css" type="text/css" />');
//            $('head').append('<script src="/Scripts/Iphone/iscroll.js" type="text/javascript"></script>');

        }
        else {




            $(window).load(function () {
                mCustomScrollbars();
            });

            function mCustomScrollbars() {
                if($("#mcs_container").length > 0)
                    $("#mcs_container").mCustomScrollbar("vertical", 200, "easeOutCirc", 1.25, "fixed", "yes", "no", 0);
            }

            /* function to fix the -10000 pixel limit of jquery.animate */
            $.fx.prototype.cur = function () {
                if (this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null)) {
                    return this.elem[this.prop];
                }
                var r = parseFloat(jQuery.css(this.elem, this.prop));
                return typeof r == 'undefined' ? 0 : r;
            }

            /* function to load new content dynamically */
            function LoadNewContent(id, file) {
                $("#" + id + " .customScrollBox .content").load(file, function () {
                    mCustomScrollbars();
                });
            }






        }
    }

    checkIfIphone();
  
}


//preLoader

var QueryLoader = {
    /*
    * QueryLoader		Preload your site before displaying it!
    * Author:			Gaya Kessler
    * Date:			23-09-09
    * URL:				http://www.gayadesign.com
    * Version:			1.0
    * 
    * A simple jQuery powered preloader to load every image on the page and in the CSS
    * before displaying the page to the user.
    */

    overlay: "",
    loadBar: "",
    preloader: "",
    items: new Array(),
    doneStatus: 0,
    doneNow: 0,
    selectorPreload: "body",
    ieLoadFixTime: 2000,
    ieTimeout: "",

    init: function () {
        if (navigator.userAgent.match(/MSIE (\d+(?:\.\d+)+(?:b\d*)?)/) == "MSIE 6.0,6.0") {
            //break if IE6			
            return false;
        }
        if (QueryLoader.selectorPreload == "body") {
            QueryLoader.spawnLoader();
            QueryLoader.getImages(QueryLoader.selectorPreload);
            QueryLoader.createPreloading();
        } else {
            $(document).ready(function () {
                QueryLoader.spawnLoader();
                QueryLoader.getImages(QueryLoader.selectorPreload);
                QueryLoader.createPreloading();
            });
        }

        //help IE drown if it is trying to die :)
        QueryLoader.ieTimeout = setTimeout("QueryLoader.ieLoadFix()", QueryLoader.ieLoadFixTime);
    },

    ieLoadFix: function () {
        var ie = navigator.userAgent.match(/MSIE (\d+(?:\.\d+)+(?:b\d*)?)/);
        if (ie[0].match("MSIE")) {
            while ((100 / QueryLoader.doneStatus) * QueryLoader.doneNow < 100) {
                QueryLoader.imgCallback();
            }
        }
    },

    imgCallback: function () {
        QueryLoader.doneNow++;
        QueryLoader.animateLoader();
    },

    getImages: function (selector) {
        var everything = $(selector).find("*:not(script)").each(function () {
            var url = "";

            if ($(this).css("background-image") != "none") {
                var url = $(this).css("background-image");
            } else if (typeof ($(this).attr("src")) != "undefined" && $(this).attr("tagName").toLowerCase() == "img") {
                var url = $(this).attr("src");
            }

            url = url.replace("url(\"", "");
            url = url.replace("url(", "");
            url = url.replace("\")", "");
            url = url.replace(")", "");

            if (url.length > 0) {
                QueryLoader.items.push(url);
            }
        });
    },

    createPreloading: function () {
        QueryLoader.preloader = $("<div></div>").appendTo(QueryLoader.selectorPreload);
        $(QueryLoader.preloader).css({
            height: "0px",
            width: "0px",
            overflow: "hidden"
        });

        var length = QueryLoader.items.length;
        QueryLoader.doneStatus = length;

        for (var i = 0; i < length; i++) {
            var imgLoad = $("<img></img>");
            $(imgLoad).attr("src", QueryLoader.items[i]);
            $(imgLoad).unbind("load");
            $(imgLoad).bind("load", function () {
                QueryLoader.imgCallback();
            });
            $(imgLoad).appendTo($(QueryLoader.preloader));
        }
    },

    spawnLoader: function () {
        if (QueryLoader.selectorPreload == "body") {
            var height = $(window).height();
            var width = $(window).width();
            var position = "fixed";
        } else {
            var height = $(QueryLoader.selectorPreload).outerHeight();
            var width = $(QueryLoader.selectorPreload).outerWidth();
            var position = "absolute";
        }
        var left = $(QueryLoader.selectorPreload).offset()['left'];
        var top = $(QueryLoader.selectorPreload).offset()['top'];

        QueryLoader.overlay = $("<div></div>").appendTo($(QueryLoader.selectorPreload));
        $(QueryLoader.overlay).addClass("QOverlay");
        $(QueryLoader.overlay).css({
            position: position,
            top: top,
            left: left,
            width: width + "px",
            height: height + "px"
        });

        QueryLoader.loadBar = $("<div></div>").appendTo($(QueryLoader.overlay));
        $(QueryLoader.loadBar).addClass("QLoader");

        $(QueryLoader.loadBar).css({
            position: "relative",
            top: "50%",
            width: "0%"
        });
    },

    animateLoader: function () {
        var perc = (100 / QueryLoader.doneStatus) * QueryLoader.doneNow;
        if (perc > 99) {
            $(QueryLoader.loadBar).stop().animate({
                width: perc + "%"
            }, 500, "linear", function () {
                QueryLoader.doneLoad();
            });
        } else {
            $(QueryLoader.loadBar).stop().animate({
                width: perc + "%"
            }, 500, "linear", function () { });
        }
    },

    doneLoad: function () {
        //prevent IE from calling the fix
        clearTimeout(QueryLoader.ieTimeout);

        //determine the height of the preloader for the effect
        if (QueryLoader.selectorPreload == "body") {
            var height = $(window).height();
        } else {
            var height = $(QueryLoader.selectorPreload).outerHeight();
        }

        //The end animation, adjust to your likings
        $(QueryLoader.loadBar).animate({
            height: height + "px",
            top: 0
        }, 500, "linear", function () {
            $(QueryLoader.overlay).fadeOut(800);
            $(QueryLoader.preloader).remove();
        });
    }
}
