﻿var videoPlayer;

function initVideo(videoUrl,showControls) {


	
	$("#ctl00_ctl03_panel_youtube").hide();
	
	var videoLink = document.getElementById("videoplayer").getElementsByTagName("a")[0];
    if(!videoLink)
    {
        videoLink = document.createElement("a");
        videoLink.id = "videolink";
        videoLink.style.width = "100%";
        videoLink.style.height = "100%";
        document.getElementById("videoplayer").appendChild(videoLink);
    }


	
	var videoPlaylist = null;
	var videoControls = null;
	if(showControls) {


	
	    videoControls =  {
	        fullscreen:false,
		    height:31,
		    background:'#000000 url(../../Modules/images/articles_video_controlbar_bg_small.jpg)',
		    scrubberHeightRatio:0.7,
		    scrubberBarHeightRatio:1.2,
		    volumeSliderHeightRatio:0.7,
		    volumeBarHeightRatio:1.2,
		    timeBgHeightRatio:0.84,
			
		    timeColor:'#c29547',
		    durationColor:'#afafaf',
		    progressColor:'#c29547',
		    bufferColor:'#afafaf',
			
		    sliderColor:'#000000',
		    volumeSliderColor:'#000000',
		    timeBgColor:'#000000',
			
		    buttonColor:'#bcbcbc',
		    buttonOverColor:'#c29547',

		    tooltipColor:'#000000',
		    tooltipTextColor:'#afafaf',
		    tooltips: {
			    buttons:true,
			    play:'Spela upp',
			    pause:'Stoppa',
			    mute:'Ljud av',
			    unmute:'Ljud på',
			    fullscreen:'Helsk&auml;rm',
			    fullscreenExit:'Stäng av helsk&auml;rm'
		    }

		};


	    
	   
	}



	videoPlaylist = [{
        url: videoUrl,
        accelerated:true,
        scaling:"fit",
        autoPlay:true,
        autoBuffering: true
    }];


	
	var videoPlayer = $f(
	    videoLink.id,
	    {
	        src: "Resources/flowplayer-3.2.5.swf",
	        onFail: function()  {
	            //hide video tag
                document.getElementById('player').style.display='none';
                document.getElementById('player').parentNode.innerHTML = "<br /><br />Du beh&ouml;ver flash version 9 eller h&ouml;gre f&ouml;r att kunna se videos p&aring; BeautyNista.se<br /><br /><a href=\"http://get.adobe.com/flash\">Klicka h&auml;r</a> f&ouml;r att ladda ner den senaste versionen.";
             }
	    },
	    {
	        playlist: videoPlaylist, 
		    plugins: {
		        controls: videoControls
		    }
		}
	);


}

function showVideo() {
    $("#videocontainer").css("top",$(window).scrollTop());

    $('#popupbg').css('filter', 'alpha(opacity=80)');
    $("#popupbg").fadeIn(500);
    $("#videocontainer").fadeIn(500);
}

function closeVideo() {
    if(videoPlayer)
        videoPlayer.pause();
        
    var youtube = document.getElementById("ctl00_ctl03_panel_youtube");
    if(youtube)
        document.getElementById("videoplayer").removeChild(youtube);
        
    $("#comments_container").hide();
    $("#articledescription_container").hide();

    $('#popupbg').css('filter', 'alpha(opacity=65)');
    $("#popupbg").fadeOut(500);
    $("#videocontainer").fadeOut(500);
}

function showTooltip(text,button) {

    var tip = $("<div></div>")
    .css("id","tooltip")
    .css("border", "1px solid black")
    .css("background-color", "white")
    .css("padding", "10px")
    .css("width", "300px")
    .css("position", "absolute")
    .css("z-index", "100")
    .css("top", (mouseY+10) + "px")
    .css("left", (mouseX + 10) + "px")
    .html(text);

    $("body").append(tip);

    $(button).mouseout(function() {
        tip.remove();
    });

}



var mouseX;
var mouseY;
$(document).mousemove(function(e) {
    mouseX = e.pageX;
    mouseY = e.pageY;
});
