/*
 * This document handles the movieplayer on the frontpage
 * It also handles the movieplayers links and stuff like that
 */

// When document is ready
$(document).ready(function() {
    
	$("#movie").hide();
	$("#closeviewer").hide();
	$("#movie-links").hide();

    // Function to embed a video using the jquery swfobject plugin
    function embed(target) {
        // Use the jquery.swfobject plugin syntax "flash()"
        $("#movie").flash({
            swf: target,
            width: 710,
            height: 427,
            wmode: 'transparent'
        });
    }
    
    
    // Function to enable the movie-list menu items
    // It takes the anchor elements and links them to the
    // embed function
    $("#movie-list li a").click(function(event){
        // Prevents the browser from following the anchor's target
        event.preventDefault();
        // Insted we want to embed the target in the movieplayer
        // So we call on the embed function and gives it the click events target href value
        embed(event.currentTarget["href"]);
    });

    // Close the viewer
    $("#closeviewer").click(function(event){
      $("#closeviewer").slideUp(300);
      $("#movie").slideUp(300);
      $("#movie-links").slideUp(300);
      $("#episodecompilation").hide();
    });

    // Show episode and links area whenever you click an episode link
    $("#movie-list a").click(function(event){
       $("#closeviewer").slideDown(300);
       $("#movie").slideDown(300);
       $("#movie-links").slideDown(300);
        $("#episodecompilation").hide();
    });
    
    // Function to set links
    $("#movie-list a[title=Episode 1]").click(function(event){
    	$("#movie-links .episode").hide();
    	$("#movie-links #episode1").show();
    });

    $("#movie-list a[title=Episode 2]").click(function(event){
    	$("#movie-links .episode").hide();
    	$("#movie-links #episode2").show();
    });
    
    $("#movie-list a[title=Episode 3]").click(function(event){
    	$("#movie-links .episode").hide();
    	$("#movie-links #episode3").show();
    });
    
    $("#movie-list a[title=Episode 4]").click(function(event){
    	$("#movie-links .episode").hide();
    	$("#movie-links #episode4").show();
    });
    
    $("#movie-list a[title=Episode 5A]").click(function(event){
    	$("#movie-links .episode").hide();
    	$("#movie-links #episode5A").show();
    });
    
    $("#movie-list a[title=Episode 5B]").click(function(event){
    	$("#movie-links .episode").hide();
    	$("#movie-links #episode5B").show();
    });
    
    $("#movie-list a[title=Episode 6]").click(function(event){
    	$("#movie-links .episode").hide();
    	$("#movie-links #episode6").show();
    });
    
    $("#movie-list a[title=Episode 7]").click(function(event){
    	$("#movie-links .episode").hide();
    	$("#movie-links #episode7").show();
    });
    
    // Function to display the long episode with everything in it
   	$("#seeallepisodes").click(function(event){
   		event.preventDefault();
   		$("#closeviewer").show();
   		$("#episodecompilation").show();
   	});

    // Function to initalize, it takes the first movie in the list
    // and displays it using the embed function
    function init() {
        // store the link of the first item in the movie-list
        var link = $("#movie-list li a")[7];
        // embed it using the embed function and gives it the link variable
        embed(link);
    }

    
    // Do the initializing
    init();


});
