﻿$(function(){
	var ph = $("div.thumb-container").height();
	var elh = $("img.video-symbol").height();
	var nh = (ph - elh) / 2; //new margin to apply
	$("img.video-symbol").css('top', nh);
});

SU4SSidebar = function (videoID) {

    if ($("div.media-holder").children().length > 0) {

        this.videoID = videoID;

        this.container = $("div.sidebarcomponent div.sidebar-media-container");
        this.overlay = $("div.sidebarcomponent div.overlay");

        this.container.appendTo("body");
        this.overlay.appendTo("body");

        this.window = $(window);
        this.body = $("body");


        $("#sidebar-thumb").click(this.bind(this.OnThumbClick));
        this.container.find("a.close").click(this.bind(this.OnCloseButtonClick));

        this.iframe = null;

        if (this.videoID != null) {
            this.iframe = this.container.find("iframe.youtube-player");
            this.iframe.load(this.bind(this.OnIframeLoad));
            this.loadingImg = $("#loading-img");
        }

        if ($.browser.msie && $.browser.version.substring(0, 1) == "6") {
            this.container.css("position", "absolute");
            this.overlay.css("position", "absolute");
        }
    } else {
        var parent = $("#sidebar-thumb").parent();
        $("#sidebar-thumb").children().appendTo(parent);
        $("#sidebar-thumb").remove();
    }
}

SU4SSidebar.prototype.OnIframeLoad = function (event) {
    this.loadingImg.css("display", "none");
    this.iframe.css("display", "block");
}

SU4SSidebar.prototype.OnThumbClick = function (event) {
    event.preventDefault();
    this.container.css("display", "block");
    this.overlay.css("display", "block");
    this.overlay.width(this.window.width());
    this.overlay.height(this.window.height());
    this.body.css("overflow", "hidden");
    if (this.videoID != null) {
        this.iframe.css("display", "none");
        this.loadingImg.css("display", "block");
        this.iframe.attr("src", "http://www.youtube.com/embed/" + this.videoID + "?rel=0");
    }
	else
		$('div.media-holder').jScrollPane({maintainPosition: false});
}

SU4SSidebar.prototype.OnCloseButtonClick = function (event) {
    event.preventDefault();
    this.container.css("display", "none");
    this.overlay.css("display", "none");
    this.body.css("overflow", "visible");
    if (this.videoID != null) {
        this.iframe.attr("src", "");
    }
}

SU4SSidebar.prototype.bind = function (func) {
    var _this = this;
    return function () {
        func.apply(_this, arguments)
    };
}



