 jQuery(document).ready(function(){
	// ---------------------------------------------------------------------------------------------------------------
	// Holt den Loginstatus in die Box rechts oben
	// ---------------------------------------------------------------------------------------------------------------
	UserStatus();
	
	// ---------------------------------------------------------------------------------------------------------------
	// Logout FE User
	// ---------------------------------------------------------------------------------------------------------------
	jQuery("#logoutButton").live("click",function(){
		logoutUser();
	});
	jQuery("#logoutButton").live("mouseover",function() {
		jQuery(this).css("cursor","pointer");
    });
	
	
	// ---------------------------------------------------------------------------------------------------------------
	// Zeigt die Box zum Editieren des Shoutbox Statuses
	// ---------------------------------------------------------------------------------------------------------------
	// In LoginBox
	jQuery('.top_login div').live("click", function(e) {
		showShoutBoxEdit(e, -150);
	});
	// Auf Profilseite
	jQuery('#ShoutboxEdit').live("click", function(e) {
		showShoutBoxEdit(e,-10);
	});
	// Cursor => Zeiger
	jQuery("#ShoutboxEdit").live("mouseover",function() {
		jQuery(this).css("cursor","pointer");
    });
	
	
	// ---------------------------------------------------------------------------------------------------------------
	// Zeichenzähler in Shoutboxedit
	// ---------------------------------------------------------------------------------------------------------------
	jQuery('#ShoutboxInput input[name=shoutbox]').live("keyup", function() {
		maxChars = 140;
		str = jQuery(this).val();
		remChars = maxChars - str.length;
		jQuery('.ShoutboxChars .CharCount').html(remChars);
			
	});
	
	
	// ---------------------------------------------------------------------------------------------------------------
	// Emoticons
	// ---------------------------------------------------------------------------------------------------------------
	//
	jQuery('#SmileySelect').live("click",function(){
		jQuery('#SmileyPalette').toggle();
	});
	
	jQuery('#SmileyPalette img').live("click", function() {
		
		jQuery(this).clone().replaceAll('#SmileySelect img');
		var htmlStr =jQuery(this).attr('src');
		
		jQuery('#shoutboxForm input[name=shoutboxSmiley]').val(htmlStr);
		jQuery('#SmileyPalette').hide();
		
	});
	
	
	
	
	// ---------------------------------------------------------------------------------------------------------------
	// Schickt das Shoutboxformular an den Server
	// ---------------------------------------------------------------------------------------------------------------
	jQuery('input[name="shoutboxSubmit"]').live("click", function() {
		jQuery.get('http://www.energy.de/?eID=nrj_news_ext&mode=feUser_ShoutBox_edit', jQuery("#shoutboxForm").serialize(), function(data){
			jQuery('#popuup_div').html(jQuery(data).find('HTML').text());
			showShoutBox();
			jQuery('#popuup_div').fadeOut(750);
		});
		return false;
	});
	
	// ---------------------------------------------------------------------------------------------------------------
	// Schliesst die Box zum Editieren des Shoutbox Statuses
	// ---------------------------------------------------------------------------------------------------------------
	jQuery('.CloseShoutbox').live("click",function(){
		showShoutBox();
		jQuery('#popuup_div').fadeOut(750);
	});
	
	// ---------------------------------------------------------------------------------------------------------------
	// Zeigt die Shoutbox eines FE Users
	// ---------------------------------------------------------------------------------------------------------------
	showShoutBox();
	
	
 });
 

function showShoutBox() {
	
	if (jQuery('.userShoutbox').length) {
		userID = jQuery('input[name=feUserID]').val(); ;
		jQuery.get('http://www.energy.de/?eID=nrj_news_ext&mode=feUser_shoutbox&userID=' + userID , function(data){
			jQuery('.userShoutbox').html(jQuery(data).find('HTML').text());
		});
	}
} 
 
function showShoutBoxEdit(e,offsetX) {
	//getting height and width of the message box
	var height = jQuery('#popuup_div').height();
	var width = jQuery('#popuup_div').width();
	//calculating offset for displaying popup message
	leftVal=e.pageX+ offsetX +"px";
	topVal=e.pageY +"px";
	// Load the HTML
	jQuery.get('http://www.energy.de/?eID=nrj_news_ext&mode=feUser_ShoutBox_edit', function(data){
		jQuery('#popuup_div').html(jQuery(data).find('HTML').text());
	});
	// show the PopUp	
	//jQuery('#popuup_div').css({left:leftVal,top:topVal}).fadeIn(500);
	
	// show the PopUp an fixer position
	jQuery('#popuup_div').fadeIn(500);

}

 
function logoutUser() {
	
	jQuery.get('http://www.energy.de/?logintype=logout');
	UserStatus();
	location.href= '/myenergy/';
	

} 
 
function UserStatus() {
	jQuery.get('http://www.energy.de/index.php?eID=nrj_news_ext&mode=feUser_loginStatus', function(data){
		jQuery('.top_login').html(jQuery(data).find('HTML').text());
	});

	//alert(rString);
	//alert("USERSTATUS");
}