//**********************************************************
//**********************************************************
$(document).ready(function()
{
var curVideoObj,curVi,ytpbc,indPlayPause;
var $bindObj;
$('#videoinfo').marquee('marquee').mouseover(function () {
$(this).trigger('stop');
}).mouseout(function () {
$(this).trigger('start');
}).mousemove(function (event) {
if ($(this).data('drag') == true) {
this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
}
}).mousedown(function (event) {
$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
}).mouseup(function () {
$(this).data('drag', false);
});
//*****************************
$(document).keyup(function(event){ytpKayControl(event.keyCode);});
$("#slider01").bind("click",function(e){ytpVolControl(e);});
//*****************************
var shuffleValue = 0;
$("#shuffle").bind("click",
function(e){
if(shuffleValue == 0)
{
$("#shuffle").attr({"class":"shuffle"});
shuffleValue = 1;
}
else
{
$("#shuffle").attr({"class":""});
shuffleValue = 0;
}
});
//*****************************
var $layer = $('#flowerid');
var $layerIsShown = 0;
$("a[flowerMenu]").bind("click",function(e)
{
$bindObj = $(this);
if(isOutPlay == true || isLogged == false)
{
playVideo($bindObj);
}
else
{
//*********
if($layerIsShown == 0)
{
$layerIsShown = 1;
flowerCX = e.pageX-380;
flowerCY = e.pageY-150;
$layer.css({ left: flowerCX+'px', top: flowerCY+'px' });
if($bindObj.parents("table[cpl]").length == 0)
{
$("td[flowerPart='bottom']").html("Добави");
}
else
{
if($bindObj.parents("table[playerList='myplaylist']").length > 0)
{
$("td[flowerPart='bottom']").html("Изтрий
");
}
else
{
$("td[flowerPart='bottom']").html("");
}
}
if($bindObj.parents("table[playerList='search']").length > 0)
{
$("td[flowerPart='left']").html(" ");
$("td[flowerPart='right']").html(" ");
}
else
{
$("td[flowerPart='left']").html("Share");
$("td[flowerPart='right']").html("Одобри");
$("a[rateVideo]").bind("click",function(){
rateVideo($bindObj);
});
}
//*********
$layer.show();
}
//*********
$("a[addtoplaylist]").bind("click",function()
{
if($bindObj.parents("table[playerList='search']").length > 0)
{
addToPlaylistFromSearch($bindObj);
}
else
{
addToPlaylist($bindObj);
}
});
//*********
$("a[removefromplaylist]").bind("click",function(){
removeFromPlaylist($bindObj);
});
}
});//*********
//*********
$("a[addtoplaylistol]").bind("click",function(){
$bindObj = $(this);
addToPlaylist($bindObj);
});
//*********
$("a[playVideo]").click(function(){
playVideo($bindObj);
});
//*********
$("a[rateVideo]").bind("click",function(){
rateVideo($bindObj);
});
//*********
$("a[shareVideo]").bind("click",function(){
shareingVideo($bindObj);
});
//*********
$('#flowerid').bind("mouseleave",function(){
$('#flowerid').hide();
$layerIsShown = 0;
});
//*********
$('img[quickPlayVideo]').bind("click",function(){
playVideo($(this));
});
//*********
var params = { allowScriptAccess: 'always'};
var atts = { id: 'myytplayer' };
swfobject.embedSWF('http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer&rel=0','myytplayer', '300', '180', '8', null, null, params, atts);
var ytplayer = $("#myytplayer");
});
//*****************************
//*******************************************************************************
//*******************************************************************************
//*******************************************************************************
function shareVideo(obj)
{
Shadowbox.open({
player: 'iframe',
title: 'Добави в списък',
content: '../site/shared_video.php?addsharedvideo='+viID,
height: 300,
width: 605
});
}
//*******************************************************************************
function removeFromPlaylist(obj)
{
$(obj).parents("tr[videoKay]").remove();
videoID = $(obj).parents("tr[videoKay]").attr("id");
$.ajax({
type: "POST",
url: "shared_video.php",
data: "deletevideoajax=yes&viid="+videoID,
success: function(msg)
{
if(msg != "")
{
alert(msg);
}
}
});
}
//*******************************************************************************
function shareingVideo(obj)
{
videoKay = $(obj).parents("tr[videoKay]").attr("videoKay");
Shadowbox.open({
player: 'iframe',
title: 'Споделена музика',
content: '../site/shared_video.php?shareingvideo='+videoKay,
height: 240,
width: 520
});
}
//*******************************************************************************
function addToPlaylist(obj)
{
viID = $(obj).parents("tr[videoKay]").attr("viid");
Shadowbox.open({
player: 'iframe',
title: 'Добави в списък',
content: '../site/shared_video.php?addsharedvideo='+viID,
height: 300,
width: 605
});
}
//*******************************************************************************
function addToPlaylistFromSearch(obj)
{
videoKay = $(obj).parents("tr[videoKay]").attr("videoKay");
Shadowbox.open({
player: 'iframe',
title: 'Добави в списък',
content: '../site/shared_video_playlist.php?addvideo='+videoKay,
height: 300,
width: 605
});
}
//*******************************************************************************
//*******************************************************************************
//*******************************************************************************
function ytpKayControl(kay)
{
if(kay == 39) ytpNext();
if(kay == 37) ytpPrev();
if(kay == 32) ytpPausePlay();
}
//*******************************************************************************
function ytpVolControl(e)
{
sliderWidth = 115;
var obj = document.getElementById('slider_');
var objpos = findPositionWithScrolling(obj);
var w = e.pageX - objpos[0] - 22;
if(w < sliderWidth)
{
$("#slider01 span").animate({"width":w+"px"}, 400);
volVal = Math.round(w*100/sliderWidth)
setVolume(volVal);
}
}
//*******************************************************************************
function iniLoadVideo(obj)
{
videoKay = $(obj).attr("videoKay");
videoTtile = $(obj).attr("videoTitle");
videoID = $(obj).attr("id");
videoPhoto = "
";
//$("td.videoinfo").html(videoTtile);
//$('#videoinfo').marquee();
$(".marquee div").text(videoTtile);
$("#photobg").html(videoPhoto);
$("table[playerList] tr,a,span").attr({"style":""});
//$(obj).attr({"style":"background:#D5D9DA;"});
$(obj).css({"background": "#AE2C00"});
$("a,span",obj).css({color: "#fff"} );
updateVideoPlayed(videoID);
ytpbc = 1;
loadNewVideo(videoKay, 0);
ytpbc = 0;
}
//*******************************************************************************
function ytpPausePlay()
{
if (ytplayer)
{
if(indPlayPause == 1)
{
indPlayPause = 0;
return ytplayer.pauseVideo();
}
if(indPlayPause == 0)
{
indPlayPause = 1;
return ytplayer.playVideo();
}
}
}
//*******************************************************************************
function ytpNext()
{
nextVideoObj = $(curVideoObj).next();
if(nextVideoObj && $(nextVideoObj).attr("videoTitle") != undefined)
{
curVideoObj = nextVideoObj;
iniLoadVideo(curVideoObj);
}
}
//*******************************************************************************
function ytpPrev()
{
prevVideoObj = $(curVideoObj).prev();
if(prevVideoObj && $(prevVideoObj).attr("videoTitle") != undefined)
{
curVideoObj = prevVideoObj;
iniLoadVideo(curVideoObj);
}
}
//*******************************************************************************
function onytplayerStateChange(newState)
{
if (ytpbc == 1) return;
if(newState == 0)
{
if($(".shuffle").length == 0)
{
nextVideoObj = $(curVideoObj).next();
}
else
{
maxel = $(curVideoObj).parent().children().length;
elemnum = Math.floor(Math.random()*maxel);
nextVideoObj = $(curVideoObj).parent().children().eq(elemnum);
}
curVideoObj = nextVideoObj;
iniLoadVideo(curVideoObj);
}
}
//*******************************************************************************
function playVideo(obj)
{
indPlayPause = 1;
curVideoObj = $(obj).parents("tr[videoKay]");
iniLoadVideo(curVideoObj);
}
//*******************************************************************************
function updateTimebar() {
var all = ytplayer.getDuration();
var part = ytplayer.getCurrentTime();
var percent = getPercent1(all, part);
var timebarWidth = 100;
var pro = Math.round(percent * (timebarWidth / 100));
if(pro > 0)
{
//alert(pro);
//document.getElementById('timebarIndicator').innerHTML = pro;
document.getElementById('timebarIndicator').style.left = pro + "%";
}
}
//*******************************************************************************
function updateytplayerInfo() {
if (ytplayer)
{
updateTimebar();
//updateBytesbar();
updateHTML("videoduration", splitTime(getDuration()));
updateHTML("videotime", splitTime(getCurrentTime()));
}
}
//*******************************************************************************
function updateVideoPlayed(viID)
{
$.ajax({
type: "POST",
url: "shared_video.php",
data: "updatevideoplayed=yes&viid="+viID
});
}
//*******************************************************************************
function rateVideo(obj)
{
var videoID = $(obj).parents("tr[videoKay]").attr("id");
if(videoID != undefined && videoID != "")
{
$.ajax({
type: "POST",
url: "shared_video.php",
data: "ratevideo=yes&viid="+videoID,
success: function(msg)
{
if(msg == 'not')
{
alert("Вече сте гласувал/а.");
}
else
{
alert("Вашият глас е отчетен.");
//$(obj).attr("title",msg);
}
}
});
}
}
//*******************************************************************************
function addPalylist(plid)
{
if(confirm('Добави към моите списъци.'))
{
$.ajax({
type: "POST",
url: "shared_video_playlist.php",
data: "addplaylist=yes&plid="+plid,
success: function(msg)
{
alert("Спсъкът е добавен.");
}
});
}
}
//*******************************************************************************
//*******************************************************************************
//*******************************************************************************
function embedPlayer()
{
var params = { allowScriptAccess: 'always'};
var atts = { id: 'myytplayer' };
swfobject.embedSWF('http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytvideo&rel=0','ytapiplayer', '300', '180', '8.0.0', null, null, params, atts);
}
//*******************************************************************************
function setVolume(newVolume) {
if (ytplayer) {
ytplayer.setVolume(newVolume);
}
}
//*******************************************************************************
function loadNewVideo(id, startSeconds) {
if (ytplayer)
{
ytplayer.loadVideoById(id, parseInt(startSeconds));
}
}
//*******************************************************************************
function onYouTubePlayerReady(playerId)
{
ytplayer = document.getElementById('myytplayer');
setInterval(updateytplayerInfo, 250);
updateytplayerInfo();
ytplayer.addEventListener('onStateChange', 'onytplayerStateChange');
}
//*******************************************************************************
function getDuration() {
if (ytplayer) {
return ytplayer.getDuration();
}
}
//*******************************************************************************
//*******************************************************************************
//*******************************************************************************
function getCurrentTime() {
if (ytplayer) {
return ytplayer.getCurrentTime();
}
}
//*******************************************************************************
function updateBytesbar() {
var all = ytplayer.getVideoBytesTotal();
var partBytes = ytplayer.getVideoBytesLoaded();
var percentBytes = getPercent2(all, partBytes);
var bytesbarWidth = 100;
document.getElementById('bytesbarIndicator').style.width = percentBytes * (bytesbarWidth / 100) + "%";
}
//*******************************************************************************
function getPercent1(all, part) {
return (all > 0) ? (100 / all) * part : 0;
}
//*******************************************************************************
function getPercent2(all, partBytes) {
return (all > 0) ? (100 / all) * partBytes : 0;
}
//*******************************************************************************
function splitTime(a)
{
var tm=new Date(a*1000)
var hours=Math.round(tm.getUTCHours());
var minutes=Math.round(tm.getUTCMinutes());
var seconds=Math.round(tm.getUTCSeconds());
if (hours > 0){
timeStr= "" + hours;
timeStr+= ((minutes < 10) ? ":0" : ":") + minutes;
timeStr+= ((seconds < 10) ? ":0" : ":") + seconds;
}
else{
timeStr= "";
timeStr= ((minutes < 10) ? "0" : ":") + minutes;
timeStr+= ((seconds < 10) ? ":0" : ":") + seconds;
}
return timeStr
}
//*******************************************************************************
function updateHTML(elmId, value) {
var obj = document.getElementById(elmId);
if(obj) obj.innerHTML = value;
}
//*******************************************************************************
function findPositionWithScrolling( oElement ) {
function getNextAncestor( oElement ) {
var actualStyle;
if( window.getComputedStyle ) {
actualStyle = getComputedStyle(oElement,null).position;
} else if( oElement.currentStyle ) {
actualStyle = oElement.currentStyle.position;
} else {
//fallback for browsers with low support - only reliable for inline styles
actualStyle = oElement.style.position;
}
if( actualStyle == 'absolute' || actualStyle == 'fixed' ) {
//the offsetParent of a fixed position element is null so it will stop
return oElement.offsetParent;
}
return oElement.parentNode;
}
if( typeof( oElement.offsetParent ) != 'undefined' ) {
var originalElement = oElement;
for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
posX += oElement.offsetLeft;
posY += oElement.offsetTop;
}
if( !originalElement.parentNode || !originalElement.style || typeof( originalElement.scrollTop ) == 'undefined' ) {
//older browsers cannot check element scrolling
return [ posX, posY ];
}
oElement = getNextAncestor(originalElement);
while( oElement && oElement != document.body && oElement != document.documentElement ) {
posX -= oElement.scrollLeft;
posY -= oElement.scrollTop;
oElement = getNextAncestor(oElement);
}
return [ posX, posY ];
} else {
return [ oElement.x, oElement.y ];
}
}