var flashEnabled = false;
var controlsVisible = false;
var player;

function onJavaScriptBridgeCreated(playerId) {
	player = document.getElementById(playerId);
    flashEnabled = true;
}
function revealControls() {
    $('a#rewind').show().animate({"top" : "+=40"}, 500 );
    $('a#mute').show().animate({"top" : "+=80"}, 500 );
    $('a#unmute').animate({"top" : "+=80"}, 500 );
    //$('a#rewind').slideDown();
    controlsVisible = true;
}
function toggleVideo() {
    if(!flashEnabled) {
		if (player.paused) {
			player.play();
		} else {
			player.pause();
		}
	} else {
	    var state = player.getState();
		if (state == "ready" || state == "paused") {
			player.play2();
		} else if (state == "playing") {
			player.pause();
		}
	}
	if (!controlsVisible) {
        revealControls();
    }
}
function rewindVideo() {
    if (flashEnabled) {
        player.seek(0);
    } else {
        player.currentTime = 0;
    }
}
function toggleMute() {
    if (flashEnabled) {
        if (player.getVolume() == 1) {
            player.setVolume(0);
        } else {
            player.setVolume(1);
        }
    } else {
        player.muted = (player.muted) ? false : true;
    }
}
$(document).ready(function() {
	var timeStamp = new Date().getTime();
	$('<input type="hidden" name="timestamp" value="'+ timeStamp +'" />').appendTo('form#formthing');
	$('ul#navigation li ul li:first-child').addClass('firstFish');
	$('ul#navigation li ul li:last-child').addClass('lastFish');
	$("form").validate();
	$("#accordion").accordion({
		autoHeight: false
	});
	$("h1#toplogo").click(function(e){
		window.location="/";
	});
    
    player = $("#html5video").get(0);
    
	$("img#thisYou").click(function(){
		toggleVideo();
	});
	$('a.btn').click(function(){
        switch ($(this).attr('id')) {
            case "play":
                $('a#pause').show();
                $('a#play').hide();
                toggleVideo();
                break;
            case "pause":
                $('a#pause').hide();
                $('a#play').show();
                toggleVideo();
                break;
            case "rewind":
                rewindVideo();
                break;
            case "mute":
                $('a#mute').hide();
                $('a#unmute').show();
                toggleMute()
                break;
            case "unmute":
                $('a#mute').show();
                $('a#unmute').hide();
                toggleMute()
                break;
            default:
                break;
        }
	});
});
