﻿
function flashPutHref(href) { location.href = href; }

function setupSlideshow() {
    // Set a cookie to not play the walkon video any more.
    $.cookie("walkon", "true");
    // SWFObject embed
    var flashvars = {
        paramXMLPath: "param-home.xml?" + Math.floor(Math.random() * 11),
        initialURL: escape(document.location),
        xmlFilePath: "images-home.xml"
    }
    var params = {
        base: ".",
        bgcolor: "#FFFFFF",
        allowfullscreen: "false"
    }
    var attributes = {}
    $("#flashWalkonWrapper").hide();
    swfobject.embedSWF("slideshowpro.swf", "flashSlideshow", "722", "276", "9.0.0", false, flashvars, params, attributes);

}

function setupWalkon() {
    var flashvars2 = {
        id: "player1",
        file: "Steve_Website_Tour_Alpha Channel.flv",
        autostart: true,
        screencolor: "FFFFFF",
        backcolor: "EEEEEE",
        frontcolor: "000000",
        stretching: "none",
        controlbar: "over",
        height: 276,
        width: 400,
        bufferlength: 5,
        screenalpha: 0.5,
        plugins: "gapro-1",
        "gapro.accountid": "UA-2501924-1",
        "gapro.trackstarts": true,
        "gapro.trackpercentage": true,
        "gapro.tracktime": true
    }

    var params2 = {
        wmode: "transparent",
        allowfullscreen: true
    }

    var attributes2 = {
        id: "player1",
        name: "player1"
    }

    swfobject.embedSWF("video/player.swf", "flashWalkon", "722", "276", "8.0.0", "video/expressInstall.swf", flashvars2, params2, attributes2);

    $("#flashWalkonWrapper").append("<p class='ac'><a href='#' id='flashWalkonClose'>Hide This</a></p>");
    $("#flashWalkonClose").click(function() {
        player.sendEvent("STOP", "true");
        setupSlideshow(); return false;
    });
}

var player;
var bHybrids = false;
var bProducts = false;
var bCrosscheck = false;
var bCall = false;

function playerReady(obj) {
    player = document.getElementById(obj['id']);
    if (player == null)
        player = document.getElementsByName(obj['id'])[0];

    player.addModelListener('TIME', 'timeTracker');
    player.addModelListener('STATE', 'stateTracker');

}

function stateTracker(obj) {
    if (obj.newstate == 'COMPLETED') {
        setupSlideshow();
    }
}

function timeTracker(obj) {
    var iPosition = obj.position;

    window.status = iPosition;
    
    if( iPosition < 22 )
        return;

    if (iPosition >= 22 && iPosition <= 24 && bHybrids == false) {
        bHybrids = true;
        highlightNav("#navHybrids");
    }
    else if ( iPosition >= 33 && iPosition <= 35 && bProducts == false )
    {
        bProducts = true;
        highlightNav("#navProducts");
    }
    else if( iPosition >= 52 && iPosition <= 54 && bCrosscheck == false )
    {
        bCrosscheck = true;
        highlightNav("#navCrosscheck");
    }
    else if( iPosition >= 70 && iPosition <= 72 && bCall == false )
    {
        bCall = true;
        var iTop = parseInt($("#Phone").css("top"));
        $("#Phone")
            .animate(
            {
                top: (iTop - 30)
            }, 1000)
            .animate(
            {
                top: iTop
            }, 1000);
    }
}

function highlightNav(sObj)
{
    $(sObj)
            .animate(
            {
                fontSize: "150%",
                color: "#933834"
            }, 500)
            .animate({ border: "0" }, 3000)
            .animate(
            {
                fontSize: "110%",
                color: "#000000"
            }, 500);
        }

//HACK: Overwrite the Cookie. Show it all the time!
//$.cookie("walkon", "");

if ($.cookie("walkon") == "true") {
    setupSlideshow();
}
else {
    setupWalkon();
}