_uacct = "UA-1514009-1";
urchinTracker();

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}

function flashOod(){
    Shadowbox.open({
        player:     'html',
        content:    '<div class="shadowbox_message">You need to update your Flash player. Update by clicking on the image below, and then try again.<br /><br /><a href="http://get.adobe.com/flashplayer/"><img src="/images/get_flash_player.gif" /></a></div>',
        height:     150,
        width:      220,
        title:      'Flash Player'
    });
};

function makeShadow(config) {
    if (typeof(swfobject) != 'undefined') {
        var v = swfobject.hasFlashPlayerVersion('9');
        if (v) {
            Shadowbox.open(config);
        }
        else {
            flashOod();
        }
    }
    else {
        alert('Please try again later.');
    }
};

Shadowbox.init({
    flvPlayer:'/swf/player.swf',
    viewportPadding:20,
    overlayColor:'#111',
    overlayOpacity:0.6,
    handleOversize: "drag"
});

Shadowbox.playDemo = function() {
    makeShadow({
        player:     'flv',
        width:      640,
        height:     360,
        content:    'http://c434801.r1.cf0.rackcdn.com/overview_15072011_v1.flv',
        title:      'SONOS Overview'
    });
}

Shadowbox.playPTDemo = function() {
    makeShadow({
        player:     'flv',
        width:      640,
        height:     360,
        content:    'http://c434801.r1.cf0.rackcdn.com/play3_15072011_v1.flv',
        title:      'SONOS PLAY:3'
    });
};

Shadowbox.playPFDemo = function() {
    makeShadow({
        player:     'flv',
        width:      640,
        height:     360,
        content:    'http://c434801.r1.cf0.rackcdn.com/play5_15072011_v1.flv',
        title:      'SONOS PLAY:5'
    });
};

Shadowbox.playYTMedia = function() {
    makeShadow({
        player:     'swf',
        height:     320,
        width:      480,
        content:    'http://www.youtube.com/v/ySrHYtxDVuM&hl=en&fs=1&rel=0&autoplay=1',
        title:      'SONOS in the Media'
    });
};

Shadowbox.playiPhoneDemo = function() {
    makeShadow({
        player:     'flv',
        height:     320,
        width:      480,
        content:    'http://c0434801.cdn.cloudfiles.rackspacecloud.com/iphonedemo3.flv',
        title:      'SONOS iPhone Controller'
    });
};

Shadowbox.playControlDemo = function() {
    makeShadow({
        player:     'flv',
        width:      640,
        height:     360,
        content:    'http://c434801.r1.cf0.rackcdn.com/control_15072011_v1.flv',
        title:      'SONOS Controllers'
    });
};

Shadowbox.playiPadDemo = function() {
    makeShadow({
        player:     'flv',
        height:     270,
        width:      480,
        content:    'http://c0434801.cdn.cloudfiles.rackspacecloud.com/sonos-ipad-demo-en.flv',
        title:      'SONOS iPad Controller'
    });
};

Shadowbox.playAndroidDemo = function() {
    makeShadow({
        player:     'flv',
        height:     352,
        width:      590,
        content:    'http://c0434801.cdn.cloudfiles.rackspacecloud.com/ziggy.flv',
        title:      'SONOS Android Controller'
    });
};

$(document).ready(function() {
    $(function(){
        // find all the input elements with title attributes
        $('input[title!=""]').hint();
    });

    $('a.sonosdemo').click(function(e) {
        Shadowbox.playDemo();
        e.preventDefault();
    });

    $('a.iphonedemo').click(function(e) {
        Shadowbox.playiPhoneDemo();
        e.preventDefault();
    });

    $('a.ipaddemo').click(function(e) {
        Shadowbox.playiPadDemo();
        e.preventDefault();
    });

    $('a.s3demo').click(function(e) {
        Shadowbox.playPTDemo();
        e.preventDefault();
    });

    $('a.s5demo').click(function(e) {
        Shadowbox.playPFDemo();
        e.preventDefault();
    });

    $('a.controldemo').click(function(e) {
        Shadowbox.playControlDemo();
        e.preventDefault();
    });

    $('a.androiddemo').click(function(e) {
        Shadowbox.playAndroidDemo();
        e.preventDefault();
    });

    $('a.ytmedia').click(function(e) {
        Shadowbox.playYTMedia();
        e.preventDefault();
    });

    $('.flashmeup').click(function(e) {
        flashOod();
        e.preventDefault();
    });

    if ($('#tabs > ul').length > 0) {
        $('#tabs').tabs();
    }

    // Configure preload & image rollovers
    var pla = new Array();
    $('img.ro').each(function() {
        var src = $(this).attr('src');
        var ext = src.substring(src.lastIndexOf('.'), src.length);
        var srcro = src.replace(ext, '_ro' + ext);

        $(this).hover(function() {
            $(this).attr('src', srcro);
        }, function() {
            $(this).attr('src', src);
        });

        pla.push(srcro);
    });

    // Initiate preload of image array
    if ($.isFunction($.preload)) {
        $.preload(pla);
    }
});
