// JavaScript Document

var mBReq = $.get("parse/mouseBox.php");

function mBDraw( type, id ) {
	switch ( type ) {
		case 1 : mBhomeBox(id);
		break;
		case 2 : mBlibCat(id);
		break;
		case 3 : mBlibSubcat(id);
		break;
		case 4 : mBlibVideo(id);
		break;
	}
}

function mBhomeBox(id) {
	mBReq.abort();	
	var retData = "";
	var cont = "";
	mBReq = $.get("parse/mouseBox.php?type=1&id=" + id, function (data) {
		retData = data.split("#separator#");
		cont = '<div id="title">' + retData[0] + '</div><img id="img" src="../video/' + retData[1] + '"><div id="info">Гледали: ' + retData[2] + ' | Харесали: ' + retData[3] + '</div>';
		$("#mouseBox").html(cont);
	});
}

function mBlibCat(id) {
	mBReq.abort();	
	var retData = "";
	var cont = "";
	mBReq = $.get("parse/mouseBox.php?type=2&id=" + id, function (data) {
		retData = data.split("#separator#");
		cont = '<div id="title">' + retData[0] + '</div><img id="img" src="../img/video/' + retData[1] + '"><div id="info">Подсекции: ' + retData[2] + ' | Видео: ' + retData[3] + '</div>';
		$("#mouseBox").html(cont);
	});
}

function mBlibSubcat(id) {
	mBReq.abort();	
	var retData = "";
	var cont = "";
	mBReq = $.get("parse/mouseBox.php?type=3&id=" + id, function (data) {
		retData = data.split("#separator#");
		cont = '<div id="title">' + retData[0] + '</div><img id="img" src="../img/video/' + retData[1] + '"><div id="info">Видео: ' + retData[2] + '</div>';
		$("#mouseBox").html(cont);
	});
}

function mBlibVideo(id) {
	mBReq.abort();	
	var retData = "";
	var cont = "";
	mBReq = $.get("parse/mouseBox.php?type=4&id=" + id, function (data) {
		retData = data.split("#separator#");
		cont = '<div id="title">' + retData[0] + '</div><img id="img" src="../video/' + retData[1] + '"><div id="info">Гледали: ' + retData[2] + ' | Харесали: ' + retData[4] + '<br />Продължителност: ' + retData[3] + '</div>';
		$("#mouseBox").html(cont);
	});
}

$(document).ready( function() {
	//home videos//
	$(".homeVImg").mouseover( function() {
		var cont = '<img src="img/ajaxload.gif" />';
		$("#mouseBox").html(cont);
		$("#mouseBox").css( "display", "block" );
		var txt = $(this).attr("mbid");
		mBDraw( 1, txt );
	});
	$(".homeVImg").mousemove( function(e) {
		var width = $("#mouseBox").outerWidth();
		var height = $("#mouseBox").outerHeight();
		var goWidth = e.pageX - ( width / 2 );
		if ( goWidth < 0 ) goWidth = 0;
		var goHeight = $(window).height() - (e.pageY - 5);
		if ( goHeight + height > $(window).height() ) goHeight -= ( height + 30 );
		$("#mouseBox").css( "left", goWidth + "px" );
		$("#mouseBox").css( "bottom", goHeight + "px" );
	});
	$(".homeVImg").mouseout( function() {
		$("#mouseBox").css( "display", "none" );
	});
	
	//lib cat images//
	$(".libCatImg").mouseover( function() {
		var cont = '<img src="img/ajaxload.gif" />';
		$("#mouseBox").html(cont);
		$("#mouseBox").css( "display", "block" );
		var txt = $(this).attr("mbid");
		mBDraw( 2, txt );
	});
	$(".libCatImg").mousemove( function(e) {
		var width = $("#mouseBox").outerWidth();
		var height = $("#mouseBox").outerHeight();
		var goWidth = e.pageX - ( width / 2 );
		if ( goWidth < 0 ) goWidth = 0;
		var goHeight = $(window).height() - (e.pageY - 5);
		if ( goHeight + height > $(window).height() ) goHeight -= ( height + 30 );
		$("#mouseBox").css( "left", goWidth + "px" );
		$("#mouseBox").css( "bottom", goHeight + "px" );
	});
	$(".libCatImg").mouseout( function() {
		$("#mouseBox").css( "display", "none" );
	});
	
	//lib subcat images//
	$(".libSubcatImg").mouseover( function() {
		var cont = '<img src="img/ajaxload.gif" />';
		$("#mouseBox").html(cont);
		$("#mouseBox").css( "display", "block" );
		var txt = $(this).attr("mbid");
		mBDraw( 3, txt );
	});
	$(".libSubcatImg").mousemove( function(e) {
		var width = $("#mouseBox").outerWidth();
		var height = $("#mouseBox").outerHeight();
		var goWidth = e.pageX - ( width / 2 );
		if ( goWidth < 0 ) goWidth = 0;
		var goHeight = $(window).height() - (e.pageY - 5);
		if ( goHeight + height > $(window).height() ) goHeight -= ( height + 30 );
		$("#mouseBox").css( "left", goWidth + "px" );
		$("#mouseBox").css( "bottom", goHeight + "px" );
	});
	$(".libSubcatImg").mouseout( function() {
		$("#mouseBox").css( "display", "none" );
	});
	
	//lib video images
	$(".libVideoImg").mouseover( function() {
		var cont = '<img src="img/ajaxload.gif" />';
		$("#mouseBox").html(cont);
		$("#mouseBox").css( "display", "block" );
		var txt = $(this).attr("mbid");
		mBDraw( 4, txt );
	});
	$(".libVideoImg").mousemove( function(e) {
		var width = $("#mouseBox").outerWidth();
		var height = $("#mouseBox").outerHeight();
		var goWidth = e.pageX - ( width / 2 );
		if ( goWidth < 0 ) goWidth = 0;
		var goHeight = $(window).height() - (e.pageY - 5);
		if ( goHeight + height > $(window).height() ) goHeight -= ( height + 30 );
		$("#mouseBox").css( "left", goWidth + "px" );
		$("#mouseBox").css( "bottom", goHeight + "px" );
	});
	$(".libVideoImg").mouseout( function() {
		$("#mouseBox").css( "display", "none" );
	});
});
