var Video = {
	initialize: function(baseURI, webRoot) {
		this.baseURI = baseURI;
		this.webRoot = webRoot;
	},
	initializeMovie: function(title, imgUri) {
		var so = new SWFObject(this.webRoot + "sparkPlayerChapterGS.swf", "sparkPlayer", "512", 288 + 20, "8", "#000000");
		so.addParam("wmode", "window");
		so.addParam("allowFullScreen", "false");
		so.addParam("allowScriptAccess", "always");
		so.addParam("quality", "best");
		so.addParam("scale", "noscale");
		so.addParam("play", "true");
		so.addVariable("copyright", "solutionpark.ch");
		so.addVariable("playerHeaderVisible", "false");
		so.addVariable("sliderVisible", "true");
		so.addVariable("timerVisible", "true");
		so.addVariable("thumbnail", this.webRoot + imgUri);
		so.addVariable("stopButtonVisible", "true");
		so.addVariable("playerTitle", title);
		so.addVariable("fullScreenButton", "larger");
		so.addVariable("fullScreenMode", "html");
		so.addVariable("centerPlayButtonVisible", "false");
		so.addVariable("fullScreenButtonVisible", "true");
		so.addVariable("movieHighestScale", "2");
		so.addVariable("buffertime", "7");
		so.addVariable("switchAfterEmptyBuffer", "3");
		so.addVariable("switchBandwidthMessage", "LOW BANDWITH DETECTED - SWITCH TO LOW QUALITY");
		so.addVariable("inPoint", "0");
		so.addVariable("movieSize", "512x288");
		so.addVariable("warningLowBandwidth", "CLICK FOR BANDWITH CHECK");
		so.addVariable("warningAfterEmptyBuffer", "3");
		so.addVariable("checkBandwidthURL", "http://download.solutionpark.tv/flash/solutionpark/bandwidth.jpg");
		so.addVariable("useFastStartBuffer", "false");
		so.addVariable("colorTrans", "0x333333,0x00FF00,0xAAAAAA,0xFFFFFF,0x000000,0x0000FF");
        so.addVariable("volumeBarVisible", "true");
        return so;
	},
    showMovieFlv: function(title, imgUri, flvMovieId, videoId) {
        var so = this.initializeMovie(title, imgUri);
        so.addVariable("autoStart", "false")
        so.addVariable("movieSrc", "http://dl.garage-suisse.ch/videos/" + flvMovieId + ".flv");
        so.addVariable("streamSrc", "rtmp://flash.garage-suisse.ch/ondemand/gsvideos/" + flvMovieId);
        so.write('player_' + videoId);
        return false;
    },
    showMovieXml: function(title, imgUri, xmlMovieId, videoId) {
        var so = this.initializeMovie(title, imgUri);
        so.addVariable("autoStart", "false")
        so.addVariable("videoSrcXML", this.webRoot + "/xmls/" + xmlMovieId);
        so.write('player_' + videoId);
        return false;
    },
    initializeMovieOverlay: function(title, imgUri) {
        if (document.getElementById('overlay_player') == null) {
            var div = document.createElement('div');
            div.setAttribute('id', 'overlay');
            div.style.display = 'none';
            document.body.appendChild(div);
            var close = document.createElement('a');
            close.setAttribute('class', 'close');
            close.innerHTML = 'X';
            div.appendChild(close);
            $("#overlay .close").click(function(){
                Video.hideOverlay();
            });
            //Click out event!
            $("#overlay_background").click(function(){
                Video.hideOverlay();
            });
            var overlay = document.createElement('div');
            overlay.setAttribute('id', 'overlay_player');
            div.appendChild(overlay);
            var text = document.createElement('div');
            text.setAttribute('id', 'overlay_title');
            div.appendChild(text);
            var background = document.createElement('div');
            background.setAttribute('id', 'overlay_background');
            background.style.display = 'none';
            document.body.appendChild(background);
        }
        var so = this.initializeMovie(title, imgUri);
        so.addVariable("autoStart", "true")
        return so;
    },
    showMovieXmlOverlay: function(title, imgUri, xmlMovieId, videoId) {
        var so = this.initializeMovieOverlay(title, imgUri);
        so.addVariable("videoSrcXML", this.webRoot + "/xmls/"+xmlMovieId);
        so.write('overlay_player');
        document.getElementById('overlay_title').innerHTML = '<a href="' + this.webRoot + 'videos/view/' + videoId + '">' + title + '</a>';
        this.showOverlay();
        return false;
    },
    showMovieFlvOverlay: function(title, imgUri, flvMovieId, videoId) {
        var so = this.initializeMovieOverlay(title, imgUri);
        so.addVariable("movieSrc", "http://dl.garage-suisse.ch/videos/" + flvMovieId + ".flv");
        so.addVariable("streamSrc", "rtmp://flash.garage-suisse.ch/ondemand/gsvideos/" + flvMovieId);
        document.getElementById('overlay_title').innerHTML = '<a href="' + this.webRoot + '">' + title + '</a>';
        so.write('overlay_player');
        this.showOverlay();
        return false;
    },
    showOverlay: function() {
        /* centering the overlay */
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $("#overlay").height();
        var popupWidth = $("#overlay").width();
        $("#overlay").css({
            "position": "absolute",
            "top": windowHeight/2-popupHeight/2,
            "left": windowWidth/2-popupWidth/2
        });
        //only need force for IE6
        $("#overlay_background").css({
            "height": windowHeight
        });
        /* actually show the overlay */
        $("#overlay_background").css({  
            "opacity": "0.7"  
        });
        $("#overlay_player").hide();
        $("#overlay_background").fadeIn("slow");  
        $("#overlay").fadeIn("slow", function() { /* show player after fadeIn */
            $("#overlay_player").show();
        });  
    },
    hideOverlay: function() {
        $("#overlay_player").hide();
        $("#overlay_background").fadeOut("slow");  
        $("#overlay").fadeOut("slow");  
    }
 
}
