﻿/// JQuery: feel the flash funk!
/// Dominic Winsor, Design Haus, www.dhaus.com
///
/// This code looks for a <div id="video"></div> on the page, and it expects to find an <img/> inside that.
/// It reads the src attribute from the IMG and strips off the path and extension, e.g.: http://example.com/assets/video/myfile.jpg --> 'myfile'
/// It assumes that the video (flvPath) and initial image (imgPath) share the same filename (myfile.flv and myfile.jpg)
///
/// HOW TO USE:
/// Put your video files inside the video folder and the image files inside the images folder (these are set up below)
/// If you want to customise the video displayed on a particular page, simply change the image src inside the <div id="video"> on that page.



// CONFIGURATION
var swfPath = '/furniture/flvplayer/mediaplayer.swf'; // full path to media player SWF
var flvPath = '/furniture/video/'; // folder containing FLV files
var imgPath = '/furniture/video/'; // folder containing JPG key frame



// ---
// locate the div and replace with flash
// fileName: filename without the extension, assume the FLV and JPG files have same name
function setFlashMovie( fileName )
{
    // add path to movie
    var flvFile = flvPath+fileName+'.flv';
    var imgFile = imgPath+fileName+'.jpg';

    // clear then replace with flash
    $('#video').empty();
    $('#video').flash(
        { 
            src: swfPath, 
            width: 189, 
            height: 142, 
            quality: 'high', 
            title: 'Outdoor stages: video', 
            allowscriptaccess: 'always', 
            allowfullscreen: 'true',
            flashvars: { 
                file: flvFile, 
                image: imgFile,
                shownavigation: false
                }
        },
        { version: 8 }
    );
}


// ---
// handle onload - set initial video content
$(document).ready(function(){

    // read the image.src which is inside hte #video div.
    var file = $("#video>img").attr("src");
    
    // read the href (a full http path) e.g. http://example.com/assets/video/myfile.jpg and trim it down to just 'myfile'
    file = file.substring(file.lastIndexOf('/')+1,file.lastIndexOf('.'));
    
    // replace the container div with a real flash video
    setFlashMovie(file);
});