$(document).ready(function () {
    $('li.subnav').hover(
        function(){
            $(this).children('li.subnav ul').stop(true, true).fadeIn();
        },
        function(){
            $(this).children('li.subnav ul').fadeOut();
        });

    $('ul#top li.share').hover(
        function(){
            $(this).children('li ul.subnav').stop(true, true).fadeIn();
        },
        function(){
            $(this).children('li ul.subnav').fadeOut();
        });

    $('ul.subnav').hover(
        function(){
            $(this).siblings().addClass('on');
        },
        function(){
            $(this).siblings().removeClass('on');
        });
    $('#emailToolTip').tooltip({
        delay: 0,
        showURL: false,
        bodyHandler: function() {
            return $("<img/>").attr("src", '/themes/gala/images/email-tooltip.png');
        }
    });


    $('#emailSubmitBtn').click(function() {
      //alert('Handler for .click() called.');
      //alert('Handler for .click() called.');
      //alert('<strong>Thank you!</strong> Your e-mail address ' + $('#emailInput').val() + ' is now registered to recieve our e-mail updates.');
      setTimeout (hideConfirmation, 5000);
      $('#emailConfirmation').html('<strong>Thank you!</strong> Your e-mail address ' + $('#emailInput').val() + ' is now registered to recieve our e-mail updates.');
      $('#emailConfirmation').show();
        $.ajax(
        {
            type: "POST",
            url: "/subscribe.php",
            data: 'email=' + $('#emailInput').val(),
            success: function(response)
            {

            }
        })

        return false;

    });



    $('#emailSubmitBtn').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : '/themes/gala/images/submitBtn-over.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : '/themes/gala/images/submitBtn.png'});             }
        );

	$("#lang_select").change(function(){
		(this.value == "en") ? window.location = "http://galaxymacau.com" : window.location = "http://" + this.value + ".galaxymacau.com";
	});

    $("#video").dialog({ autoOpen: false, width: 720, modal: true, show: 'scale', position: 'top', resizable: false, close: stopVideo });

});

function openVideoDialog(movieLocation)
{
    var flashvars = {};

    var params = {
                    allowScriptAccess: "always",
                    allowFullScreen: "true",
                    allowNetworking: "all",
                    flashVars: 'streamerType=rtmp&streamerUrl=rtmp://rtmpakmi.kaltura.com:1935/ondemand&rtmpFlavors=1&&'
                }

    swfobject.embedSWF(movieLocation, "videoPlayer", "720", "430", "8.0.0", "/assets/expressInstall.swf", flashvars, params);
    $("#video").dialog('open');
    //setVideo(movieLocation);
    return false;
}

function videoSize(width, height)
{
    //console.log(message);
    $('#videoPlayer').css('width', width);
    $('#videoPlayer').css('height', height);
    $('#video').css('width', width);
    $('#video').css('height', height);
    $('#video').dialog( 'option' , 'width' , width+36 );
}

function stopVideo()
{
    swfobject.embedSWF("/themes/gala/flash/masterVideoPlayer.swf", "videoPlayer", "500", "300", "8.0.0", "/assets/expressInstall.swf", {}, {allowscriptaccess:"always"});
    return false;
}

function hideConfirmation()
{
 $('#emailConfirmation').fadeOut();
}