﻿var player = null;
var playerShowreel = null;
var mute = true;
var play = false;
var autoplay = true;
var isShowreel = false;

$(document).ready(function () {

    $('#nav').droppy({ speed: 100 });

    if (window.location.search.substr(1) == "home") {
        $('#wrapper').scrollTo("#item1");
    }
    if (window.location.search.substr(1) == "passionate") {
        $('#wrapper').scrollTo("#item2");
        autoplay = false;
    }
    if (window.location.search.substr(1) == "experts") {
        $('#wrapper').scrollTo("#item3");
        autoplay = false;
    }
    if (window.location.search.substr(1) == "team") {
        $('#wrapper').scrollTo("#item4");
        autoplay = false;
    }
    if (window.location.search.substr(1) == "trusted") {
        $('#wrapper').scrollTo("#item5");
        autoplay = false;
    }
    if (window.location.search.substr(1) == "connect") {
        $('#wrapper').scrollTo("#item6");
        autoplay = false;
    }
    if (window.location.search.substr(1) == "intergrated") {
        $('#wrapper').scrollTo("#item7");
        autoplay = false;
    }
    if (window.location.search.substr(1) == "gallery") {
        $('#wrapper').scrollTo("#item8");
        autoplay = false;
    }



    $('a.panel').click(function () {

        $('a.panel').removeClass('selected');
        $(this).addClass('selected');

        current = $(this);

        $('#wrapper').scrollTo($(this).attr('rel'), 800);
        stopVideo();
        return false;
    });

    $('a.panelSlider').click(function () {

        $('a.panelSlider').removeClass('selected');
        $(this).addClass('selected');

        c = $(this);

        $('#wrapperSlider').scrollTo($(this).attr('rel'), 800);
        stopVideo();
        return false;
    });



    $(window).resize(function () {
        resizePanel();
        resizePanelSlider();
    });

    $(".gallery[rel]").overlay({
        mask: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.8
        },
        closeOnClick: false,

        top: 60

    });

    $(".scroll").scrollable({ circular: true }).click(function () {
        $(this).data("scrollable").next();
    });


    $(".biog[rel]").overlay({
        mask: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.8
        },
        closeOnClick: false,

        top: 60,
        onBeforeLoad: function () {
            stopVideo();
            isShowreel = true;
        },
        onClose: function () {
            stopVideo();
            isShowreel = false;
        }

    });




    jQuery(".hov").hover(function () {
        jQuery(this).attr("src", function () { return this.src.substring(0, this.src.length - 4) + '_over.png' });
    }, function () {
        jQuery(this).attr("src", function () { return this.src.substring(0, this.src.length - 9) + '.png' });
    });


    $(".social_tooltip").tooltip({
        tip: '.tooltip',
        effect: 'fade',
        position: "bottom center",
        offset: [-140, -130]
    });

    $(".kidsco_tooltip").tooltip({
        tip: '.tooltip2',
        effect: 'fade',
        position: "bottom center",
        offset: [-130, -90]
    });



});


function resizePanel() {

    width = $(window).width();
    height = $(window).height();

    mask_width = width * $('.item').length;

    //$('#debug').html(width  + ' ' + height + ' ' + mask_width);

    $('#wrapper, .item').css({ width: width, height: height });
    $('#mask').css({ width: mask_width, height: height });
    $('#wrapper').scrollTo($('a.selected').attr('rel'), 0);

}

function resizePanelSlider() {

    width = $(window).width();
    height = $(window).height();

    mask_width = width * $('.itemSlider').length;

    //$('#debug').html(width  + ' ' + height + ' ' + mask_width);

    $('#wrapperSlider, .itemSlider').css({ width: width, height: height });
    $('#maskSlider').css({ width: mask_width, height: height });
    $('#wrapperSlider').scrollTo($('a.selected').attr('rel'), 0);

}


function playerReady(thePlayer) {

    if (!$.browser.mozilla) {
        player = window.document['player'];
        playerShowreel = window.document['playerShowreel'];
    } else {
        player = window.document['playerFF'];
        playerShowreel = window.document['playerShowreelFF'];
    }

    if (autoplay) {
        togglePlay();
    }
}

function toggleMute() {
    if (player == null) return;

    var vol = 100;
    if (mute) { vol = 0; } else { vol = 100; }

    player.sendEvent('VOLUME', vol);
    mute = !mute;

    if (mute) {
        $('#btnMute').attr('src', "images/icons/sound_low.png");
    } else {
        $('#btnMute').attr('src', "images/icons/sound_mute.png");
    }

}

function togglePlay() {
    try {
        playerShowreel.sendEvent('PLAY', false);
    } catch (Exception) { }
    if (!isShowreel) {
        if (player == null) return;

        player.sendEvent('PLAY', play);
        play = !play;
        if (play) {
            $('#btnPlay').attr('src', "images/icons/playback_play.png");
        } else {
            $('#btnPlay').attr('src', "images/icons/playback_pause.png");
        }
    }
}

function stopVideo() {
    try {
        playerShowreel.sendEvent('PLAY', false);
    } catch (Exception) { }
    if (player == null) return;

    player.sendEvent('PLAY', false);
    $('#btnPlay').attr('src', "images/icons/playback_play.png");
    play = true;
}
