﻿var errs = 0;
var playerActive;
var ytparams = { allowScriptAccess: "always", bgcolor: "#000000", wmode: "transparent" };

function stop(obj) {
    playerActive = null;
    try {
        document.getElementById(obj + "_p").pauseVideo();
    } catch (err) {
    }
}

function onYouTubePlayerReady(playerid) {
    document.getElementById(playerid + "_p").addEventListener("onError", "playerError");
    document.getElementById(playerid + "_p").cueVideoById(playerid, 3);
    
    if (playerActive != null) {
        play(playerActive);
    }
}

function playerError(error) {
    alert(error);
}

function play(obj) {
    playerActive = obj;
    try {
        if (document.getElementById(obj + "_p") == null || document.getElementById(obj + "_p").getPlayerState() == -1) {
            swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=" + obj + "&hd=1",
                                        obj, "280", "162", "8", null, null, ytparams, { id: obj + "_p" });
        } else if (document.getElementById(obj + "_p").getPlayerState() >= 2) {
            document.getElementById(obj + '_p').playVideo();
        }
    } catch (err) { // Exception thrown. Destroy the object so we can try again.
        if (errs < 1) // If not already tried, loop and give it another go
        {
            errs++;
            play(obj);
        }
    } finally {
        errs = 0;
    }
}

$(document).ready(function() {
    $('#JLRcarousel').jcarousel({
        size: 6,
        scroll: 1,
        easing: "swing",
        animation: "2"
    });
});