function Player()
{
	this.next = next;
	this.loop = loop;
	this.play = play;
	this.stop = stop;
	this.back = back;
	this.next_icon = "<div id=\"next\"><img src=\"/fileadmin/templates/images/navigationelemente/next_schmoe.gif\" /></div>";
	this.back_icon = "<div id=\"back\"><img src=\"/fileadmin/templates/images/navigationelemente/prev_schmoe.gif\" /></div>";
	this.navigation = navigation;
}

/**
 * Blï¿½ttert den Player nach vorne
 * @return void
 */
function back()
{
	$("#tvbox_container #news_entries li.tvbox_item:first").fadeOut(500, function(){
		$("#tvbox_container #news_entries li.tvbox_item .text").hide();		
		var lastElement = $("#tvbox_container #news_entries li.tvbox_item:last").remove();		
		$("#tvbox_container #news_entries li.tvbox_item:first").before(lastElement);
		$("#tvbox_container #news_entries li.tvbox_item:first").fadeIn(500, function(){
			$(this).find(".text").oneTime(500, "textSlide", function(){
				$(this).slideDown("slow");
			});			
		});
	});
}

/**
 * Jeder 15sek. next()
 * @return void
 */
function loop()
{
	var cObj = this;
	
	$("#tvbox_container").everyTime(13000, "player", function(){
		cObj.next();
	});
}

/**
 * Initialisiert die Navigation
 * @param Player cObj
 * @param jQuery Event event
 * @param Object element
 * @return void
 */
function navigation(cObj, event, element)
{	
	var factor = $(element).width() / (event.pageX - $(element).offset().left);
	
	if (factor <= 2)
	{
		if ($("#tvbox_container #next").size() == 0)
		{
			$("#tvbox_container #back").remove();
			$("#tvbox_container").append(cObj.next_icon);
			$("#tvbox_container #next").css("top", ($("#tvbox_container #next img").height() + 20) - 402);
			$("#tvbox_container #next").css("left", $("#tvbox_container").width() - $("#tvbox_container #next").width());
		}
		
		$("#tvbox_container #next").click(function(){
			cObj.stop();
			cObj.next();
			cObj.loop();
		});
	}else
	{
		if ($("#tvbox_container #back").size() == 0)
		{
			$("#tvbox_container #next").remove();
			$("#tvbox_container").append(cObj.back_icon);	
			$("#tvbox_container #back").css("top", ($("#tvbox_container #back img").height() + 20) - 402);
			$("#tvbox_container #back").css("left", 0);
		}
		
		$("#tvbox_container #back").click(function(){
			cObj.stop();
			cObj.back();
			cObj.loop();
		});
	}
}

/**
 * Blï¿½ttert den Player nach vorne
 * @return void
 */
function next()
{
	$("#tvbox_container #news_entries li.tvbox_item:first").fadeOut(500, function(){		
		$("#tvbox_container #news_entries li.tvbox_item .text").hide();		
		$("#tvbox_container #news_entries").append($(this).remove());
		$("#tvbox_container #news_entries li.tvbox_item:first").fadeIn(500, function(){
			$(this).find(".text").oneTime(500, "textSlide", function(){
				$(this).slideDown("slow");
			});			
		});
	});
}

/**
 * Player fï¿½r die Newseintrï¿½ge mit groï¿½en Bild und Text im Bidl
 * auf der Startseite, welches sich jede 15 Sek. autom. wechselt
 * und manuell vor- und zurï¿½ckspulbar ist
 * @return void
 */
function play()
{
	var cObj = this;
	
	//News wo die Kategorie V3 Startseite mit aufgelistet wird, entfernen
	$("#tvbox_container ul li.tvbox_item .text .categories").each(function(){
		
		if ($(this).text().match(/Startseite V3,/))
		{
			$(this).text($(this).text().replace("Startseite V3,", ""));
		}else
		{			
			$(this).text($(this).text().replace("Startseite V3", ""));
		}
	});
	
	//Erste News anzeigen
	$("#tvbox_container ul li.tvbox_item:first").show();
	$("#tvbox_container ul li.tvbox_item:first .text").oneTime(500, "textSlide", function(){
		$(this).slideDown("slow");
	});	
	this.loop();
	
	//Wenn Mauszeige Player verlässt, dann Navigation ausblenden
	$("#tvbox_container").mouseout(function(){
		$("#back", this).delay(1000).fadeOut(function(){
			$(this).remove();
		});
		$("#next", this).delay(1000).fadeOut(function(){
			$(this).remove();
		});
	});
	
	//Player Navigation starten
	$("#tvbox_container").mousemove(function(event){
		cObj.navigation(cObj, event, this);
	});
}

/**
 * Stoppt den Player
 * @return void
 */
function stop()
{
	$("#tvbox_container").stopTime("player");
}
