/* Code für Connect - Banner*/
var bannerTimer = null;
function initConnectBannerTimer() {
	
	if ($('#gtConnectBlink').length > 0 && bannerTimer == null) {
		bannerTimer = setInterval(onConnectBannerTimer, 1700);  
	}
}

function onConnectBannerTimer() {
	
	if ($('#gtConnectBlink').length > 0) {
		if ($('#gtConnectBlink').hasClass('phase2')) {
			$('#gtConnectBlink').removeClass('phase2');
		} else {
			$('#gtConnectBlink').addClass('phase2');			
		}
	}
	
}

/* Code für Hunt-Timer und Camp-Seite */

var huntTimer = null;
var secondsUntilHunt = -1;

function initHuntTimer() {
	secondsUntilHunt = parseInt(secondsUntilHunt);
	if (secondsUntilHunt > 0) {
		huntTimer = setInterval(onHuntTimer, 1000);  
	}		
}


function onHuntTimer() {
	
	if (secondsUntilHunt > 0) {
		secondsUntilHunt = secondsUntilHunt - 1;
		var displayMinutes = Math.floor(secondsUntilHunt/60);
		var displaySeconds = secondsUntilHunt%60;
		if (displayMinutes < 10) {
			displayMinutes = '0' + displayMinutes;
		}
		if (displaySeconds < 10) {
			displaySeconds = '0' + displaySeconds;
		}
		$('#topHuntMinutes').html(displayMinutes);
		$('#topHuntSeconds').html(displaySeconds);
		$('#mainHuntMinutes').html(displayMinutes);
		$('#mainHuntSeconds').html(displaySeconds);		
	} else {
		$('#topHuntActive').removeClass('hidden');
		$('#topHuntGray').addClass('hidden');
		
		$('#huntEnabled').removeClass('hidden');
		$('#huntDisabled').addClass('hidden');		
		clearInterval(huntTimer);
	}

}


/* Code für Chrono-Crystal */

function chronoChrystalMouseOver (event) {
	$('#huntChrono').removeClass('hidden');
}

function chronoHuntMouseOut(event) {
	$('#huntChrono').addClass('hidden');
}

function installCrystalListeners() {
	
	$('#chrono1').bind('mouseover', chronoChrystalMouseOver);
	$('#chrono2').bind('mouseover', chronoChrystalMouseOver);
	$('#chrono3').bind('mouseover', chronoChrystalMouseOver);
	$('#chronoHuntButton').bind('mouseover', chronoChrystalMouseOver);
	$('#huntChrono').bind('mouseout', chronoHuntMouseOut);
	
}

/* Durchschaltbare Nachrichten im Camp*/
function showPrevNewsMessage() {
	currentMessage--;
	if (currentMessage < 0) {
		currentMessage = 2;
	}	
	$('#newsText span').addClass('hidden');		
	$('.news'+currentMessage).removeClass('hidden');
}

function showNextNewsMessage() {
	currentMessage++;
	if (currentMessage > 2) {
		currentMessage = 0;
	}
	$('#newsText span').addClass('hidden');		
	$('.news'+currentMessage).removeClass('hidden');
}

var currentMessage=0;

/* Popup für Common-Goal*/
function showCGPopup() {
	$('#cg_information_popup').removeClass('hidden');
}

function closeCGPopup() {
	$('#cg_information_popup').addClass('hidden');
}

/* Popup für Zazzle-Store*/
function showZazzlePopup() {
	$('#zazzlePopup').removeClass('hidden');
}

function closeZazzlePopup() {
	$('#zazzlePopup').addClass('hidden');
}


/* Code für How-To-Play*/
function showHowtoPlaySection(id) {
	$('#section').html(  $('#'+id).html()  );
}

/* Bait-Warnung im Inventar*/
function showBaitDisclaimerPopup(sendingObject) {
	
	var posY = $(sendingObject).position().top + 20;
	posY = posY + 'px';
	
	$('#baitDisclaimer').css('top', posY);
	$('#baitDisclaimer').removeClass('hidden');	
}

function closeBaitDisclaimerPopup() {
	$('#baitDisclaimer').addClass('hidden');
}

/* Geschenk im Inventar*/
function showPresentPopup(presentId) {
	scrollToTop();
	$('#present_div'+presentId).removeClass('hidden');
}



// Call-Back, falls jemand eine Remindermessage postet
function remindercallback(id) {
	
	if (id != null) {
		var idArray = id.split('_');		

		$('#reminder_'+idArray[0]).addClass('hidden');
		var poster = $('#poster').attr('value'); 
		var testKey = $('#test_'+idArray[0]).attr('value');		

		$.ajax({
			type: "GET",
    		url: 'ajax_reminder.php',
    		data: 'reminderTarget='+idArray[0]+'&test='+testKey+'&postingFBid='+postingFBid
		});
		
		
		var posterObj = document.getElementById('poster');
		var postingFBid = posterObj.getValue(); 		
	}

}


// Popups im Raid
function showRaidPopup(description, password, enterRaidLocation, disbandUnit, createUnit) {
	
	if (description) {
		$('#raid_description_popup').removeClass('hidden');
	} else if (password) {
		$('#raid_password_popup').removeClass('hidden');
	} else if (enterRaidLocation) {
		$('#raid_enter_popup').removeClass('hidden');
	} else if (disbandUnit) {
		$('#raid_disband_popup').removeClass('hidden');
	} else if (createUnit) {
		$('#raid_createunit_popup').removeClass('hidden');		
	}
}

function closeAllRaidPopups() {
	$('#raid_description_popup').addClass('hidden');	
	$('#raid_password_popup').addClass('hidden');	
	$('#raid_enter_popup').addClass('hidden');
	$('#raid_disband_popup').addClass('hidden');	
	$('#raid_createunit_popup').addClass('hidden');
}


// Travel-Seite für Raids
function showRaidHuntingGround(id) {
	// alle Raid-HGs ausblenden
	$('#locationdetails div').addClass('hidden');
	// richtigen einblenden
	$('#raid_hg_'+id).removeClass('hidden');	
}


//Variable fuer Monsterwallposts
var postedGhostMonsterId;

// Callback-Function für Wallposts von Monster (nicht in live_feed.js, weil es auch vom Journal aus aufrufbar ist
function onMonsterWallpostCallback(retval) {
	/*$.ajax({
		type: "GET",
		url: 'ajax_receiver_lf.php',
		data: 'gm_instance_id='+postedGhostMonsterId+'&poster='+wallpostPoster+'&retval='+retval
	});*/
}

function onMonsterWallpostDelayedClick() {
	$.ajax({
		type: "GET",
		url: 'ajax_receiver_lf.php',
		data: 'gm_instance_id='+postedGhostMonsterId+'&poster='+wallpostPoster+'&retval=12'
	});
}


//Mouse-Over-Effekte für Eingangshalle von First-Floor und Ninth-Floor

function onImageLinkMouseOver(event) {
	var id = event.target.id + "Footer";	
	$('#'+id).removeClass('hidden');
}

function onImageLinkMouseOut(event) {
	var id = event.target.id + "Footer";	
	$('#'+id).addClass('hidden');
}

jQuery(document).ready(function() { 

	$('.entryHallMouseOverEffect').bind('mouseover', onImageLinkMouseOver);
	$('.entryHallMouseOverEffect').bind('mouseout', onImageLinkMouseOut);
	
});







/* Animation */
var animationData = null;

function showNoGhostAttracted() {
	
	$('#animationLogEntry').delay(1000)
	   					   .animate({opacity: "1.0"}, 2000);
	
	$('#notCatchedCross').delay(1000)
	 .animate({left: "277px", opacity:"1.0"}, 1)
	 .animate({top: "-=40px"}, 500)
	 .animate({top: "-=40px", opacity:"0.0"}, 500);		
}


function showGhostEscapedAnimation(ghostId, ghostMode) {

	$('#animationLogEntry').animate({opacity: "0.0"}, 3000)
	   .animate({opacity: "1.0"}, 2000);
	  			   
	var ghostImage;
	
	if (ghostMode == 'raid') {
		ghostImage =  ghostId + '.jpg';
	} else {
		ghostImage = ghostId+'_transparent.png';
	}
	
	$('#ghostAnimation').html('<img id="ghostImage" src="/fb/res/whitebg/'+ ghostImage + '" width="100%" height="100%"></img>');
	
	var yStart = -450 + Math.random()* 700;
	var yNotCatched = -30 + Math.random() * 300;
	$('#ghostAnimation').css('top', yStart + 'px');
	
	$('#ghostAnimation').animate({left: "250px", top: "100px"}, 2000)
						.delay(1500)
						.animate({left: "1000px", top: yNotCatched + 'px'}, 1000)
						.animate({opacity: "0.0"}, 500);
	
	
	$('#notCatchedCross').delay(3200)
				 .animate({left: "285px", opacity:"1.0"}, 1)
				 .animate({top: "-=40px"}, 500)
				 .animate({top: "-=40px", opacity:"0.0"}, 500);	
		
}

function insertNumbers(containerDOMObject, numberValue, showPlus, symbol) {
	
	var numberValue = numberValue.toString();
	var i = 0;
	var digitCount = numberValue.length;
	var imageArray;

	imageArray = new Array(digitCount + 1);		
	imageArray[0] = '/fb/res/whitebg/gt_font_plus.png';
	
	for (i = 0; i < digitCount; i++) {
		
		var currentDigit = numberValue.substring(i, i + 1);
		imageArray[i + 1] =  '/fb/res/whitebg/gt_font_' + currentDigit + '.png';
	}
	
	digitCount = imageArray.length;
	
	containerDOMObject.html('');
	var startIndex = 0;
	if (showPlus == false) {
		startIndex = 1;
	}
	for (i = startIndex; i < digitCount; i++) {
		containerDOMObject.append('<img style="float:left;" src="' + imageArray[i] + '"></img>');
	}
	
	if (symbol != null) {
		containerDOMObject.append('<img style="margin-left:0px;" src="/fb/res/whitebg/' + symbol + '"></img>');
	}	
	
	return digitCount;
}


function showGhostCatchAnimationPart1(ghostId, ghostMode, gbp, experience) {
	
	waitLootImagesCounter = 0;
	//resetAnimation();
	
	var ghostImage;
	
	if (ghostMode == 'raid') {
		ghostImage =  ghostId + '.jpg';
	} else {
		ghostImage = ghostId+'_transparent.png';
	}
	
	$('#ghostAnimation').html('<img id="ghostImage" src="/fb/res/whitebg/'+ ghostImage + '" width="100%" height="100%"></img>');
	
	var yStart = -450 + Math.random()* 700;
	$('#ghostAnimation').css('top', yStart + 'px');


	var sizeX = 184 * 1.8;
	var sizeY = 175 * 1.8;
	var offsetX = (sizeX - 184)/2;
	var offsetY = (sizeY - 175)/2;  

	var i = 0;
	var lootCount = animationData['loot'].length;
	if (lootCount > 6) {
		lootCount = 6;
	}
	
    var lootAnimation = $('#lootAnimation');


	var top = 100 ;
	var lootCountDisplay = lootCount;
	if (lootCount > 3) {
		top = 15;
		lootCountDisplay = 3;
	}

	var expectedWidth = 235;

	for (i = 0; i < lootCount; i++) {

		 if (i == 3) {
			 top = top + 230;
			 lootCountDisplay = lootCount - 3;				 
		 }
			 
		 if (i == 0 || i == 3) {
			left = 240;
			if (lootCountDisplay == 2) {
				left = 240 - expectedWidth / 2;				
			} else if (lootCountDisplay == 3) {
				left = 240 - expectedWidth;				
			}
		 }	
			  				 
		 var lootTypeClass = 'lootImage'; 
	     if (animationData['loot'][i]['itemCategoryTable'] == 'companion') {
	    	 lootTypeClass = 'companionLootImage';
		 } else if (animationData['loot'][i]['itemCategoryTable'] == 'souvenir_part') {
	    	 lootTypeClass = 'souvenirPartLootImage';
		 }else if (animationData['loot'][i]['itemCategoryTable'] == 'whisky') {
	    	 lootTypeClass = 'baitLootImage';
		 } 

		 lootAnimation.append(
				'<div id = "lootContainer'+i+'" class = "lootContainer" style = "opacity:0.0;filter: alpha(opacity=0);left:' + left + 'px;top:'+ top +'px;">'+
					'<div class = "lootInnerQuantity" id = "lootInnerQuantity' + i + '">'+animationData['loot'][i]['quantity']+'</div>'+
					'<div class= "isLootImage '+lootTypeClass+'" >'+'<img class="isLootImg" height="100%" src= "'+animationData['loot'][i]['image']+'" ></img></div>'+
				'</div>');
		 
		 insertNumbers($('#lootInnerQuantity' + i ), animationData['loot'][i]['quantity'], true, null);

		 left = left + expectedWidth;

	}	
	
	$('#animationLogEntry').delay(4000)
						   .animate({opacity: "1.0"}, 2000);
	
	if ($('.isLootImage').length == 0) {
		$('#friendTextInAnimation').show();
		$('#friendTextInAnimation').delay(3900)
		   						   .animate({opacity: "1.0"}, 2000);
		
		$('#huntTimerResetInAnimation').show();
		$('#huntTimerResetInAnimation').delay(3900)
		   						   .animate({opacity: "1.0"}, 2000);
		
		$('#doubleCatchAnimation').show();
		$('#doubleCatchAnimation').delay(3900)
									.animate({opacity: "1.0"}, 2000);		

		$('#ignoreMysticImmunityAnimation').show();
		$('#ignoreMysticImmunityAnimation').delay(3900)
									.animate({opacity: "1.0"}, 2000);		
		
		$('#animationVulnerability').show();
		$('#animationVulnerability').delay(3900)
		   						   .animate({opacity: "1.0"}, 2000);	
		
		$('#darkArt').show();
		$('#darkArt').delay(3900)
		   			 .animate({opacity: "1.0"}, 2000);
		
		$('#superBuff').show();
		$('#superBuff').delay(3900)
		   			 .animate({opacity: "1.0"}, 2000);		
	}	
				
	$('#ghostAnimation').animate({left: "250px", top: "100px"}, 2000)
						.animate({left: "250px"}, 1500)
						.animate({left:"-="+offsetX+"px", top:"-="+offsetY+"px", width: sizeX+"px", height: sizeY+"px"}, 300)
						.animate({left:"+="+offsetX+"px", top:"+="+offsetY+"px", width: "184px", height: "175px"}, 200) 
						.animate({left: "90px", top: "640px", width:"10px", height:"10px"}, 1000)
						.animate({opacity:"0.0"}, 200, 'swing', showGhostCatchAnimationPart2); 

	var ghostMoneyObj = $('#ghostMoney');
	var ghostXPObj = $('#ghostXP'); 
	
	
	if (ghostMode != 'monsterStart') {	
		// Geld/XP-Animationen nur, wenn kein Ghost-Monster begonnen wurde
		var moneyNumber = insertNumbers(ghostMoneyObj, gbp, true, 'gt_font_gbp.png');
		var xpNumber = insertNumbers(ghostXPObj, experience, true, 'gt_font_xp.png');
		
		
		ghostMoneyObj.css('left', (325 - moneyNumber * 14) + 'px' );
		
		ghostMoneyObj.delay(3500)
					 .animate({opacity:"1.0"}, 1)
					 .animate({top: "-=40px"}, 500)
					 .animate({top: "-=40px", opacity:"0.0"}, 500);
		
		
		
		ghostXPObj.css('left', (310 - xpNumber * 14) + 'px' );
		
		ghostXPObj.delay(4200)
				  .animate({opacity:"1.0"}, 1)
				  .animate({top: "-=45px"}, 600)
				  .animate({top: "-=45px", opacity:"0.0"}, 600);
		
		
		if (animationData['infernalEffect'] == true) {
			
			//var agent = navigator.userAgent.toLowerCase();  
			//alert (agent);
						
			$('#infernalAnimationBackground').css({opacity:0.0})
			$('#infernalAnimationBackground').show();
			
			
			$('#infernalAnimationBackground').delay(2300)
			   .animate({opacity:"0.8"}, 1300)
			   .delay(1000)
			   .animate({opacity:"0.0"}, 1700)
			   .animate({width:"1px",height:"1px"}, 100);	
			
			$('#infernalAnimation').show();
			
			var agent = navigator.userAgent.toUpperCase();  
			
			if (agent.indexOf('MSIE') > 0) {
				
				$('#infernalAnimation').css({width:"0px"});			
				
				$('#infernalAnimation').delay(3000)
						.animate({width:"626px"}, 0)
						.delay(1700)
						.animate({width:"0px"}, 0);
				
			} else {
				$('#infernalAnimation').css({opacity:0.0});			
				
				$('#infernalAnimation').delay(2500)
					   .animate({opacity:"1.0"}, 1300)
					   .animate({opacity:"0.6"}, 500)
					   .animate({opacity:"1.0"}, 400)
					   .animate({opacity:"0.0"}, 1700)
					   .animate({width:"1px",height:"1px"}, 100);				
			}
/*
			$('#infernalAnimationIE').css({opacity:0.0})
			$('#infernalAnimationIE').show();
			
			$('#infernalAnimationIE').delay(2500)
					   .animate({opacity:"0.8"}, 1300)
					   .animate({opacity:"0.6"}, 500)
					   .animate({opacity:"0.8"}, 400)
					   .animate({opacity:"0.0"}, 1700)
					   .animate({width:"1px",height:"1px"}, 100);
*/
		}
	}
		
}		

var waitLootImagesCounter = 0;

function showGhostCatchAnimationPart2() {
	

	
	var allLootImgs = $('.isLootImage');
	
	if (allLootImgs.length == 0) {
		return;
	}
	
	var i = 0;
	
	// Teste, ob alle Loot-Bilder schon geladen wurden, dann muss jedes Breiter als 0 sein
	var imagesLoaded = true;
	for (i = 0; i < allLootImgs.length; i++) {
		if (allLootImgs[i].width == 0) {
			imagesLoaded = false;
		}
	}
	
	if (imagesLoaded == false && waitLootImagesCounter < 16) {
		waitLootImagesCounter++;
		setTimeout('showGhostCatchAnimationPart2', 500);
		return;
	}
	
	$('.lootContainer').animate({opacity:"1.0"}, 1500)
					   .delay(2500)
					   .animate({left: "90px", top: "640px", width:"10px", height:"10px"}, 1000, 'swing', showGhostCatchAnimationPart3);
	
	var logElement = $('#animationLootText').parent();	
	
	if (logElement.length > 0)
	{
		var height = logElement.height();
		if (height == null) {
			return;
		}
		$(logElement).css('height', height.toString()+'px');
	
		height = height + $('#animationLootText br').length * 12 - 6;
		
		if ($('#animationVulnerability').length > 0 || $('#superBuff').length > 0 || $('#darkArt').length > 0 || $('#friendTextInAnimation').length > 0 || 
			$('#huntTimerResetInAnimation').length > 0 || $('#doubleCatchAnimation').length > 0 || $('#ignoreMysticImmunityAnimation').length > 0) {
			// Abstand für spezielle Proc-Effekte
			height = height + 12;
		}
		
		if ($('#friendTextInAnimation').length > 0) {
			height = height + 14;
		}
		if ($('#huntTimerResetInAnimation').length > 0) {
			height = height + 14;
		}	
		if ($('#doubleCatchAnimation').length > 0) {
			height = height + 14;
		}	
		if ($('#ignoreMysticImmunityAnimation').length > 0) {
			height = height + 14;
		}		
		
		$('#animationLootText br:first').remove()
		
		if ($('#animationVulnerability').length > 0) {
			height = height + 14;
		}	
		if ($('#darkArt').length > 0) {
			height = height +14;
		}		
		if ($('#superBuff').length > 0) {
			height = height +14;
		}			
		
		if (navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Chrome") == -1) {
			// im Safari Höhe Sofort ändern, der kriegt den Verlauf nicht hin			
			logElement.delay(3000)
					  .animate({height: height}, 1);
		} else {
			logElement.delay(3000)
			  		  .animate({height: height}, 2000);			
		}
		
		$('#animationLootPrefix').delay(4000)
		 						 .animate({opacity: "1.0"}, 1000);
		
		$('#animationLootText').show();
		$('#animationLootText').delay(4000)
							   .animate({opacity: "1.0"}, 1000);
		
		$('#friendTextInAnimation').show();
		$('#friendTextInAnimation').delay(4000)
		   						   .animate({opacity: "1.0"}, 2000);	
		
		$('#huntTimerResetInAnimation').show();
		$('#huntTimerResetInAnimation').delay(4000)
		   						       .animate({opacity: "1.0"}, 2000);
		
		$('#animationVulnerability').show();
		$('#animationVulnerability').delay(4000)
		   						    .animate({opacity: "1.0"}, 2000);
		
		$('#ignoreMysticImmunityAnimation').show();
		$('#ignoreMysticImmunityAnimation').delay(4000)
									   .animate({opacity: "1.0"}, 2000);
		
		
		$('#doubleCatchAnimation').show();
		$('#doubleCatchAnimation').delay(4000)
									.animate({opacity: "1.0"}, 2000);			
		
		$('#darkArt').show();
		$('#darkArt').delay(4000)
   				     .animate({opacity: "1.0"}, 2000);		
		
		$('#superBuff').show();
		$('#superBuff').delay(4000)
   				       .animate({opacity: "1.0"}, 2000);		
	}

	
}		


function tutorialStartAnimation() {

	$('#ghostAnimation').html('<img id="ghostImage" src="/fb/res/whitebg/4_transparent.png" width="100%" height="100%"></img>');
		
	//var yStart = -450 + Math.random()* 700;
	$('#ghostAnimation').css( {left: "500px", 'top': '-500px'} );	
	$('#ghostAnimation').animate({left: "800px", top: "0px"}, 3000)
						.animate({opacity: "0"}, 1)
						.animate({left: "-180px", top: "0px"}, 1)
						.animate({opacity: "1"}, 1)
						.animate({left: "-80px", top: "30px"}, 2000)
						.delay(1000)
						.animate({left: "-180px", top: "90px"}, 2000, 'swing', tutorialStartAnimation2);

	
}

function tutorialStartAnimation2() {
	$('#ghostAnimation').css( {left: "780px", top: "0px"} );	
	$('#ghostAnimation').html('<img id="ghostImage" src="/fb/res/whitebg/4_transparent_mirror.png" width="100%" height="100%"></img>');	
	$('#ghostAnimation').delay(1000)
						.animate({left: "640px", top: "30px"}, 2000)
						.animate({opacity: "0"}, 1000);	
}

function showGhostCatchAnimationPart3() {
	$('#lootAnimation').html('');
	$('#ghostAnimation').html('');
}

function headerAnimation() {
	
	if ($('#animationHeaderSnow').length > 0) {
	
		var params = {
			  	  "wmode":"transparent",
				  "swfbgcolor":"000000",
				  "allowscriptaccess":"always"};
	
		var attributes = {"id":"animationHeaderSnow"};		
	
		swfobject.embedSWF("/fb/res/snow_theme_760x313_1.0.swf", "animationHeaderSnow", "346", "288", "9.0.28", "expressInstall.swf", false, params, attributes);
	}
}

function onSelectTicketTradeIdChange(event) {
	
	var ticketId = $('#trade_ticket_id').attr('value');
	var amount = $('#ticketOption'+ticketId).attr('amount');
	
	$('#ticketAmount').html(amount);
	$('.ticketJuiceSelect').addClass('hidden');
	$('#ticketJuiceSelect' + ticketId).removeClass('hidden');
}

function onSelectUntradeableIdChange(event) {
	var untradeableId = $('#trade_untradeable_id').attr('value');
	var amount = $('#untradeableOption'+untradeableId).attr('amount');
	
	$('#untradeableAmount').html(amount);
}

function onSelectShreederIdChange(event) {
	var untradeableId = $('#document_id').attr('value');
	var amount = $('#shreederOption'+untradeableId).attr('amount');
	
	$('#shreederAmount').html(amount);
}


function installTickeTraderListeners() {
	
	$('#trade_ticket_id').bind('change', onSelectTicketTradeIdChange);
	$('#trade_ticket_id').bind('keyup', onSelectTicketTradeIdChange);
	
	$('#trade_untradeable_id').bind('change', onSelectUntradeableIdChange);
	$('#trade_untradeable_id').bind('keyup', onSelectUntradeableIdChange);

	
	$('#document_id').bind('change', onSelectShreederIdChange);
	$('#document_id').bind('keyup', onSelectShreederIdChange);	
}


function parseJson(json) {
	var data = null;
	
 	if (typeof (JSON) !== 'undefined' && 
		    typeof (JSON.parse) === 'function') {
	 		data = JSON.parse(json);
 	} else {
	    data = eval('(' + json + ')');
 	}
 	return data;
}


/* Comments-Javascript */

var commentTextEmpty = true;

var commentRelativeUrl = ''; // falls Url nicht auf oberster Ebene, manuell überschreiben

function showComments(showAll, parentType, parentId, width) {
	
	$('#commentTextArea').attr('showAll', showAll);
	
	$.ajax({
		type: "POST",
		url: commentRelativeUrl + 'ajax_comment.php',
		data: 'action=showComments&parentType='+parentType+'&parentId='+parentId+'&width='+width+'&showAll='+showAll,
		success: onCommentDataReceived
	});	
}

function postComment( parentType, parentId, width) {

	var commentText = $('#commentTextArea').attr('value');
	var showAll = $('#commentTextArea').attr('showAll');
	$('#commentErrorMessage').html('');	
	
	if (commentTextEmpty == false && commentText != '') {
		
		$('#commentPostbutton').addClass('hidden');
		$('#grayCommentPostbutton').removeClass('hidden');
		
		$.ajax({
			type: "POST",
			url: commentRelativeUrl + 'ajax_comment.php',
			data: 'action=createComment&parentType='+parentType+'&parentId='+parentId+'&width='+width+'&commentText='+commentText+'&showAll='+showAll,
			success: onCommentDataReceived
		});
		
	}	
}
	

function deleteComment(id, width) {
	
	var showAll = $('#commentTextArea').attr('showAll');
	$.ajax({
		type: "POST",
		url: commentRelativeUrl + 'ajax_comment.php',
		data: 'action=deleteComment&id='+id+'&width='+width+'&showAll='+showAll,
		success: onCommentDataReceived
	});
	
}

function onCommentDataReceived(json) {

	$('#commentPostbutton').removeClass('hidden');
	$('#grayCommentPostbutton').addClass('hidden');

	var data = parseJson(json);
	
	if (data.createResponse == true || data.errorMessage == '') {
		$('#commentsList').html(data.commentListHtml);
	}
	
	if (data.errorMessage != '') {
		$('#commentErrorMessage').html(data.errorMessage);
	} else {
		$('#commentErrorMessage').html('');
	}
	if (data.createResponse != false && data.errorMessage == '') {
		$('#commentTextArea').attr('value', 'Enter message');
		commentTextEmpty = true;				
	}
	
	reInit();	
}

function onCommentTextEnter() {

	if (commentTextEmpty) {
		
		$('#commentTextArea').attr('value', '');
		commentTextEmpty = false;
	}
}

tutorialFirstStep = '-1'; // Wird überschrieben mit Ausgabe im Quelltext

function installCommentEventListeners() {
	commentTextEmpty = true;
	$('#commentTextArea').click(onCommentTextEnter);
}





/* Wallpost-Boost code*/

function sendBoostWallpostConfirm(action) {

	$.ajax({
		type: "POST",
		url: 'ajax_boost_wallpost.php',
		data: 'action='+action
	});
	
}

function onBoostPopupClick() {
	$('.boostConfirmPopup').addClass('hidden'); 	  		
}



/* Startscript (Animationen) */

jQuery(document).ready(function() { 
	
	var agent = navigator.userAgent.toUpperCase();  
	if (agent.indexOf('OPERA') >= 0) {
		$('#recruitBar').remove();
	}
	
	headerAnimation();
	
	installTickeTraderListeners();
	installCommentEventListeners();
	
	if (tutorialFirstStep == '1') {
		tutorialStartAnimation();
	}
	
	if (animationData != null) {
		
		if (animationData['resultCode'] == 200) {
			showGhostCatchAnimationPart1(animationData['ghostId'], animationData['ghostMode'], animationData['gbp'], animationData['experience']);
		} else if (animationData['resultCode'] == 100) {
			showGhostEscapedAnimation(animationData['ghostId'], animationData['ghostMode']);
		} else if (animationData['resultCode'] == 0) {
			showNoGhostAttracted();
		}
		
	}

	if (document.cookie == '') {
		//alert(document.getElementById('mainframe').content Window.location.href);		
		$('.mainContainer').append('<div class="noCookiesWarning">Warning: No third party cookies enabled<br><br>' +
									    '<a target="_bank" href="' + location.href + '">TRY TO LOGIN WITHOUT THIRD PARTY COOKIES</a><br>' +
									    '(This link will open a new window.)<br><br>' +
									    '<iframe width="730" height="600" src="/fb/social-network/facebook_cookie_warning.php?noLoginLink=true"></iframe>' +
								   '</div>');
	}

});



function logoutOfApp(url) {
	startAjaxQueue();
	$.manageAjax.add('ajaxQueue', { 
		type:'POST',
		url: '/fb/logout.php',
		success:function(json,textStatus){setTimeout(function () {top.location.href=url;}, 2000);},
		error:function(XMLHttpRequest,textStatus,errorThrown){}
    });	
}

