﻿var gtLoaded = false;

$(function() {
    try {
        if (player) { //If the player exists on the page.
            //console.log('player is not null.');
            $('#player-widget').bind('ready', function() {
                //console.log('**** player-widget ready triggered!');
                if (!gtLoaded && !$.browser.mozilla)
                    setTimeout('loadGoogleTranslate()', 3000);
            });
        }
    } catch (err) {
        loadGoogleTranslate();
    }

    //Left icons
    $('ul.left-items li[title!=""]').qtip({
        position: {
            corner: {
                target: 'topMiddle',
                tooltip: 'bottomLeft'
            }
        },
        style: {
            padding: 5,
            background: '#fafafa',
            color: 'black',
            textAlign: 'left',
            border: {
                width: 2,
                radius: 5,
                color: '#1F4F14'
            },
            tip: 'bottomLeft',
            name: 'green' // Inherit the rest of the attributes from the preset green style
        }
    }).click(function() {
        $(this).not('.no-bounce').effect('bounce', { distance: 15, times: 4 }, 500);
    });

    //Right icons
    $('ul.right-items li[title!=""]').qtip({
        position: {
            corner: {
                target: 'topMiddle',
                tooltip: 'bottomRight'
            }
        },
        style: {
            padding: 5,
            background: '#fafafa',
            color: 'black',
            textAlign: 'left',
            border: {
                width: 2,
                radius: 5,
                color: '#1F4F14'
            },
            tip: 'bottomRight',
            name: 'green' // Inherit the rest of the attributes from the preset green style
        }
    }).click(function() {
        $(this).not('.no-bounce').effect('bounce', { distance: 15, times: 4 }, 500);
    });
});

function loadGoogleTranslate() {
    console.log('Load Google Translate...');
    gtLoaded = true;
    $('div#google_translate_script').append('<scr' + 'ipt src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></scr' + 'ipt>');
}