﻿var muted = false;
var videoPlayer = null;
var ios;

function CUIndexController() {
    //console.log("init object");
    this.checkUserAgent();
    videoPlayer = document.getElementById("player");
    $('.slideshow').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
    this.decidePlayer();
}

CUIndexController.prototype.checkUserAgent = function () {
    //console.log("checking user agent");
    var iphone = navigator.userAgent.match(/iPhone/i);
    var ipad = navigator.userAgent.match(/iPad/i);
    if (iphone != null || ipad != null) {
        ios = true;
    }
    else {
        ios = false;
    }
    //console.log("ios - " + ios);
}

CUIndexController.prototype.decidePlayer = function () {
    //console.log("starting player");
    if (ios) {
        this.startHTML5Player();
    }
    else {
        this.startFlash();
    }
}

CUIndexController.prototype.startHTML5Player = function () {
    //console.log("starting  HTML5 player");
    $(videoPlayer).load();
    $(videoPlayer).bind("ended", function () {
        videoPlayer.play();
    });
}

CUIndexController.prototype.startFlash = function () {
    //console.log("starting Flash player");
    $(videoPlayer).hide();
    videoPlayer.volume = 0;
    swfobject.embedSWF("CASTUP_PROMO.swf", "flashContent", "920", "384", "9.0.0");
}
