//  Clips JS - Richard Davey, 8th November 2007

String.prototype.trim = function ()
{
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

function prepareLinks()
{
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById) return false;
    if (!document.getElementById("clips_list")) return false;

    //  Add onclick event to the list items
    
    var clips_list = document.getElementById("clips_list");
    var li = clips_list.getElementsByTagName("li");
    
    for (var i=0; i < li.length; i++)
    {
        li[i].onclick = function()
        {
            pushClip(this.id);
            captionDiv = document.getElementById("caption");
            captionDiv.innerHTML = this.title;
            return false;
        }
    }
    
    //  Add onclick event to the clip list images
    
    var clips_links = document.getElementById("more_clips");
    var img = clips_links.getElementsByTagName("img");
    
    for (var i=0; i < img.length; i++)
    {
        img[i].onclick = function()
        {
            swapList(this.id);
            return false;
        }
    }
}

function pushClip(clip)
{
    clip = clip.substring(4).trim();
    
    clipSo.addVariable("liveclip", clip);
    clipSo.write("movie");

    embedDiv = document.getElementById("embedTag");

    embedDiv.value = '<object width="325" height="221"><param name="movie" value="http://flash.shaunthesheep.com/clips/eplayer.swf"></param><param name="wmode" value="transparent"></param><param name="FlashVars" value="quality=high&liveclip=' + clip + '"></param><embed type="application/x-shockwave-flash" src="http://flash.shaunthesheep.com/clips/eplayer.swf"  width="325"  height="221" id="player" name="player" quality="high" wmode="transparent" flashvars="quality=high&liveclip=' + clip + '" ></embed></object>';

}

function swapList(list)
{
    old_list = document.getElementById('clipset_' + current_list);
    new_list = document.getElementById('clipset_' + list.substring(9).trim());
    
    old_list.style.display = 'none';
    new_list.style.display = 'block';
    
    current_list = list.substring(9).trim();
}

clipSo = new SWFObject("http://flash.shaunthesheep.com/clips/player.swf", "player", "325", "221", "8");
clipSo.addParam("wmode", "transparent");
clipSo.addVariable("quality", "high");

window.onload = prepareLinks;

pushClip('clip' + current_clip);

