iPad = false;

var leftPos = 0;

/* --------- Deep Linking for Video ---------- */
    $(".video").live("click", function() {
        SWFAddress.setValue(this.rel);
    });
    
    function handleChange(event) {
        if (event.path != "/") {
            var videoName = event.path;
            $("#video-section").show();
            $("#video-backdrop").fadeTo("fast", .9, function() {
                if (!iPad) {
                    jwplayer("video-container").setup({ 
                        flashplayer: "/jwplayer/player.swf", 
                        file: ".."+videoName+".flv", 
                        height: 270, 
                        width: 480,
                        autostart: autoplay
                    });
                }
                else {
                    $("#video-container").html('<video width="100%" height="100%" controls="controls" autoplay="true" autobuffer="true"><source src="'+videoName+'.m4v" type="video/mp4" /> </video>');
                }
            });
            $("#video-function").show();
        }
        else {
            $("#video-container").html();
            $("#video-backdrop").fadeOut("fast");
            $("#video-section").fadeOut("fast");
        }
    }
    
    SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
    
$(document).ready(function() {

	// Left arrow button
    $("#vid-menu-left").live("click", function() {
    	if (leftPos != '0' ) {
		    leftPos += 850;
		    	    
		    $("#video-tn").animate({
				marginLeft: leftPos+'px'
			});
		}
    });
    
    // Right arrow button
    $("#vid-menu-right").live("click", function() {
    	if (leftPos >= '-850' ) {
		    leftPos -= 850;
		    	    
		    $("#video-tn").animate({
				marginLeft: leftPos+'px'
			});
		}
    });
    
    // Close button
    $("#video-section #video-close").live("click", function() {
        jwplayer("video-container").setup({ 
            flashplayer: "/jwplayer/player.swf", 
            file: "", 
            height: 270, 
            width: 480 
        });
        SWFAddress.setValue('');
        $("#video-container").html();
        $("#video-backdrop").fadeOut("fast");
        $("#video-section").fadeOut("fast");
    });
    
    $(this).keyup(function(e) {
        if (e.which == 27 && $("#video-backdrop").css("display") != "none") {
            jwplayer("video-container").setup({ 
                flashplayer: "/jwplayer/player.swf", 
                file: "", 
                height: 270, 
                width: 480 
            });
            SWFAddress.setValue('');
            $("#video-container").html();
            $("#video-backdrop").fadeOut("fast");
            $("#video-section").fadeOut("fast");
        }
    });
});
