$(document).ready(function(){
// Add width to .caption (makes it possible to center images width caption)
$(window).load(function(){
	var capWith = $('.caption');
	for (var i = 0;i<capWith.length;i++){
		var children = $(capWith[i]).children();
		if(children.length>0){
			var curWidth = $(children[0]).not('br').width();
		}else{
			var curWidth = $(capWith[i]).width();
		}
		$(capWith[i]).css('width', curWidth);			
	}	
	if($('.placeholderContainer').length>0){
		loadPlaceholders(); 
	}
	
});
// Loginform animation	
	$("#einloggen, #ausloggen").click(function(){
		$("#loginform").slideToggle();
	});

// Slides
	$(window).load(function () {
		$('slide_container').show();
	});
	$(".slides").hide(); 
	$("ul.slidenav li:first").addClass("active").show(); 
	$(".slides:first").show(); 

	$("ul.slidenav li").click(function() {

		$("ul.slidenav li").removeClass("active"); 
		$(this).addClass("active"); 
		$(".slides").hide(); 

		var activeTab = $(this).find("a").attr("href"); 
		$(activeTab).fadeIn(); 
		return false;
	});
// Tabs
	$(".tab_content").hide(); 
	$("ul.tabs li:first").addClass("active").show(); 
	$(".tab_content:first").show(); 

	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); 
		$(this).addClass("active"); 
		$(".tab_content").hide(); 

		var activeTab = $(this).find("a").attr("href"); 
		$(activeTab).fadeIn(); 
		return false;
	});
// Carousel
	var carousel = '#carousel ul li';
	var carouselActive = '#carousel ul li.active';
	var navNext = '#carousel_nav_next';
	var navPrev = '#carousel_nav_prev';
	var itemWidth = $(carousel).outerWidth(true); 
	var itemCount = $(carousel).length;
	var listWidth = itemWidth*itemCount;
	
	$('#carousel ul').css('width',listWidth); 
	$('#carousel ul li:first').addClass('active');
	$(navNext).click(function() { 
		if($(carouselActive).next().next().next().next().length === 0) {
			$(navNext).die('click', aClick);
			}
			$('#carousel ul li').animate({'left': '-=' + itemWidth + 'px'}, '500');
		$(carouselActive).next().addClass('active');
		$(carouselActive).prev().removeClass('active');
		
		$(navPrev).removeClass('inactive');
		
		if($(carouselActive).next().next().next().next().length === 0) {
			$(navNext).addClass('inactive');
			}
	}); 
	if($(carouselActive).prev().length === 0) {
			$(navPrev).addClass('inactive');
			}
	$(navPrev).click(function() { 
		if($(carouselActive).prev().length === 0) {
			$(navPrev).die('click', aClick);
			}
			$('#carousel ul li').animate({'left': '+=' + itemWidth + 'px'}, '500');
		$(carouselActive).prev().addClass('active');
		$(carouselActive).next().removeClass('active');
		$(navNext).removeClass('inactive');
		if($(carouselActive).prev().length === 0) {
			$(navPrev).addClass('inactive');
			}
	});
// Overlay	
	var browserWidth = $(window).width();
	var browserHeight = $(window).height();
	var PCOcontentWidth = $('#PCOcontent').outerWidth(true);
	var PCOcontentHeight = $('#PCOcontent').outerHeight(true);
	var PCOcontentLeft = ([browserWidth - PCOcontentWidth]/2);
	var PCOcontentTop = ([browserHeight - PCOcontentHeight]/2);
	var PCOid	= '#PCO';
	$('#PCOcontent').css({'left' : PCOcontentLeft, 'top' : PCOcontentTop});
	$(window).resize(function() {	
		var browserWidth2 = $(window).width();
		var browserHeight2 = $(window).height();
		var PCOcontentWidth2 = $('#PCOcontent').outerWidth(true);
		var PCOcontentHeight2 = $('#PCOcontent').outerHeight(true);
		var PCOcontentLeft2 = ([browserWidth2 - PCOcontentWidth2]/2);
		var PCOcontentTop2 = ([browserHeight2 - PCOcontentHeight2]/2);
		$('#PCOcontent').css({'left' : PCOcontentLeft2, 'top' : PCOcontentTop2});
	});
	$('a[onclick="pco"]').click(function() { 
		$(PCOid).fadeIn().next().fadeIn();
	});
	$(PCOid).click(function() { 
		$(this).fadeOut().next().fadeOut();
	});
	$('#PCOclose').click(function() { 
		$(PCOid).fadeOut().next().fadeOut();
	});
// Equal Column Height
	$(window).load(function () {
	if($('div.boxColumns').length){
		makeEqualColumns();
	}
	function makeEqualColumns(){
	var boxWrappers = $('div.boxColumns');
	for(var i=0;i<boxWrappers.length;i++){
		var leftContent = $(boxWrappers[i]).children('div.contentLeft');
		var leftHeight = $(leftContent).height();
		var leftElements = $(leftContent).children();
		var leftElementsNum = leftElements.length;
		
		var rightContent = $(boxWrappers[i]).children('div.contentRight');
		var rightHeight = $(rightContent).height();
		var rightElements = $(rightContent).children();
		var rightElementsNum = rightElements.length;
		
		if(leftHeight > rightHeight){
			var lastBox = rightElements[rightElements.length-1];
			var lastBoxCurrentHeight = $(lastBox).height();
			var lastBoxNewHeight = leftHeight - rightHeight;
			$(lastBox).height(lastBoxCurrentHeight+lastBoxNewHeight);			
		}else if(leftHeight < rightHeight){
			var lastBox = leftElements[leftElements.length-1];
			var lastBoxCurrentHeight = $(lastBox).height();
			var lastBoxNewHeight = rightHeight - leftHeight;
			$(lastBox).height(lastBoxCurrentHeight+lastBoxNewHeight);
		}
	}
	};
	});
	
// ExpertenPanel Hide Show
	if($('div.rezensionContainer').length > 0){
		var answers = $('div.rezensionContent'); 
		$('div.showRezension').show();
		for(var i=0;i<answers.length;i++){
			var dl = $(answers[i]).children('dl.rezensionAnswers');
			$(dl[1]).css('padding-top', '0.5px');
			var ident = $(dl[1]).attr('class');
			$(dl[1]).attr('class', ident+' clear');
			$(dl[1]).hide();
		}
		
		$('a.showRezension').click(function(){
			var button = this;
			var div = $(button).parent('div')
			var imgSrc = $(button).children('img').attr('src');
			if(imgSrc.search('slideDown') != -1){
				var newSrc = imgSrc.replace('slideDown', 'slideUp');
			}else{
				var newSrc = imgSrc.replace('slideUp', 'slideDown');
			}
			$(div).prev('dl.rezensionAnswers').slideToggle(1000, function(){
				$(button).children('img').attr('src', newSrc);
			});	
			return false;
		});
	}
	
// Hide/Show embed script
var embedText = $('textarea.embedCode');
$(embedText).hide();
var embedDesc = $('p.embedDesc');
var embedDescSpans = $(embedDesc).children('span');
$(embedDescSpans[0]).show();
$(embedDescSpans[1]).hide();
var embedButton = $('a.showEmbedCode');
$(embedDescSpans[0]).children('a.showEmbedCode').click(function(){
	$(embedText).slideToggle();		
	return false;
});	

// Sharebutton animation
	$('#share').hover(
  		function () {
    		$(this).animate({'left': '+=64px'}, 'slow');
  		},
  		function () {
    		$(this).animate({'left': '-=64px'}, 'slow');
  		}
	);
	
// Tooltip
{$.fn.tipTip=function(options){var defaults={activation:"hover",keepAlive:false,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:false,enter:function(){},exit:function(){}};var opts=$.extend(defaults,options);if($("#tiptip_holder").length<=0){var tiptip_holder=$('<div id="tiptip_holder" style="max-width:'+opts.maxWidth+';"></div>');var tiptip_content=$('<div id="tiptip_content"></div>');var tiptip_arrow=$('<div id="tiptip_arrow"></div>');$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')))}else{var tiptip_holder=$("#tiptip_holder");var tiptip_content=$("#tiptip_content");var tiptip_arrow=$("#tiptip_arrow")}return this.each(function(){var org_elem=$(this);if(opts.content){var org_title=opts.content}else{var org_title=org_elem.attr(opts.attribute)}if(org_title!=""){if(!opts.content){org_elem.removeAttr(opts.attribute)}var timeout=false;if(opts.activation=="hover"){org_elem.hover(function(){active_tiptip()},function(){if(!opts.keepAlive){deactive_tiptip()}});if(opts.keepAlive){tiptip_holder.hover(function(){},function(){deactive_tiptip()})}}else if(opts.activation=="focus"){org_elem.focus(function(){active_tiptip()}).blur(function(){deactive_tiptip()})}else if(opts.activation=="click"){org_elem.click(function(){active_tiptip();return false}).hover(function(){},function(){if(!opts.keepAlive){deactive_tiptip()}});if(opts.keepAlive){tiptip_holder.hover(function(){},function(){deactive_tiptip()})}}function active_tiptip(){opts.enter.call(this);tiptip_content.html(org_title);tiptip_holder.hide().removeAttr("class").css("margin","0");tiptip_arrow.removeAttr("style");var top=parseInt(org_elem.offset()['top']);var left=parseInt(org_elem.offset()['left']);var org_width=parseInt(org_elem.outerWidth());var org_height=parseInt(org_elem.outerHeight());var tip_w=tiptip_holder.outerWidth();var tip_h=tiptip_holder.outerHeight();var w_compare=Math.round((org_width-tip_w)/2);var h_compare=Math.round((org_height-tip_h)/2);var marg_left=Math.round(left+w_compare);var marg_top=Math.round(top+org_height+opts.edgeOffset);var t_class="";var arrow_top="";var arrow_left=Math.round(tip_w-12)/2;if(opts.defaultPosition=="bottom"){t_class="_bottom"}else if(opts.defaultPosition=="top"){t_class="_top"}else if(opts.defaultPosition=="left"){t_class="_left"}else if(opts.defaultPosition=="right"){t_class="_right"}var right_compare=(w_compare+left)<parseInt($(window).scrollLeft());var left_compare=(tip_w+left)>parseInt($(window).width());if((right_compare&&w_compare<0)||(t_class=="_right"&&!left_compare)||(t_class=="_left"&&left<(tip_w+opts.edgeOffset+5))){t_class="_right";arrow_top=Math.round(tip_h-13)/2;arrow_left=-12;marg_left=Math.round(left+org_width+opts.edgeOffset);marg_top=Math.round(top+h_compare)}else if((left_compare&&w_compare<0)||(t_class=="_left"&&!right_compare)){t_class="_left";arrow_top=Math.round(tip_h-13)/2;arrow_left=Math.round(tip_w);marg_left=Math.round(left-(tip_w+opts.edgeOffset+5));marg_top=Math.round(top+h_compare)}var top_compare=(top+org_height+opts.edgeOffset+tip_h+8)>parseInt($(window).height()+$(window).scrollTop());var bottom_compare=((top+org_height)-(opts.edgeOffset+tip_h+8))<0;if(top_compare||(t_class=="_bottom"&&top_compare)||(t_class=="_top"&&!bottom_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_top"}else{t_class=t_class+"_top"}arrow_top=tip_h;marg_top=Math.round(top-(tip_h+5+opts.edgeOffset))}else if(bottom_compare|(t_class=="_top"&&bottom_compare)||(t_class=="_bottom"&&!top_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_bottom"}else{t_class=t_class+"_bottom"}arrow_top=-12;marg_top=Math.round(top+org_height+opts.edgeOffset)}if(t_class=="_right_top"||t_class=="_left_top"){marg_top=marg_top+5}else if(t_class=="_right_bottom"||t_class=="_left_bottom"){marg_top=marg_top-5}if(t_class=="_left_top"||t_class=="_left_bottom"){marg_left=marg_left+5}tiptip_arrow.css({"margin-left":arrow_left+"px","margin-top":arrow_top+"px"});tiptip_holder.css({"margin-left":marg_left+"px","margin-top":marg_top+"px"}).attr("class","tip"+t_class);if(timeout){clearTimeout(timeout)}timeout=setTimeout(function(){tiptip_holder.stop(true,true).fadeIn(opts.fadeIn)},opts.delay)}function deactive_tiptip(){opts.exit.call(this);if(timeout){clearTimeout(timeout)}tiptip_holder.fadeOut(opts.fadeOut)}}})}}

// Screenshot slider + counter (screenshot.php)
	var cite = '#screenshots ul li';
	var citeActive = '#screenshots ul li.active';
	var citeNext = '#screenshots_cite_next';
	var citePrev = '#screenshots_cite_prev';
	var citeWidth = $(cite).outerWidth(true); 
	var citeCount = $(cite).length;
	var cistListWidth = citeWidth*citeCount;
	
	$('#screenshots ul').css('width',cistListWidth); 
	$('#screenshots ul li:first').addClass('active');
	$(citeNext).click(function() { 
		if($(citeActive).next().length === 0) {
			$(citeNext).die('click', aClick);
			}
			$('#screenshots ul li').animate({'left': '-=' + citeWidth + 'px'}, '500');
		$(citeActive).next().addClass('active');
		$(citeActive).prev().removeClass('active');
		
		$(citePrev).removeClass('inactive');
		
		if($(citeActive).next().length === 0) {
			$(citeNext).addClass('inactive');
			}
	}); 
	if($(citeActive).prev().length === 0) {
			$(citePrev).addClass('inactive');
			}
	$(citePrev).click(function() { 
		if($(citeActive).prev().length === 0) {
			$(citePrev).die('click', aClick);
			}
			$('#screenshots ul li').animate({'left': '+=' + citeWidth + 'px'}, '500');
		$(citeActive).prev().addClass('active');
		$(citeActive).next().removeClass('active');
		$(citeNext).removeClass('inactive');
		if($(citeActive).prev().length === 0) {
			$(citePrev).addClass('inactive');
			}
	});
	
	
	
	var citeActiveLength = $(citeActive).nextAll('li').length;
	$('#screenshot_current').text(citeCount - citeActiveLength);
	
	$(citeNext).click(function () {
		var citeActiveLength = $(citeActive).nextAll('li').length;
      $('#screenshot_current').text(citeCount - citeActiveLength);
    });
	
	$(citePrev).click(function () {
		var citeActiveLength = $(citeActive).nextAll('li').length;
      $('#screenshot_current').text(citeCount - citeActiveLength);
    });
	
	$('#screenshot_all').text(citeCount);


// ----------------------------------------New Frontpage Scripts 15-09-2011
$(window).load(function () {
// FP TopSlideshow	
	$(".FPslideshowTopSlides").hide(); 
	$(".FPslideshowTopSlides:first").show().addClass('active_slide'); 
	$("ul.FPslideshowTopNav li img.slide_circle").click(function() {
		$("ul.FPslideshowTopNav li img").removeClass("slide_circle_active"); 
		$(this).addClass("slide_circle_active"); 
		$(".FPslideshowTopSlides").hide().removeClass('active_slide'); 
		var activeTab = $(this).parents().find("a").attr("href"); 
		$(activeTab).fadeIn().addClass('active_slide'); 
		return false;
	});
	var stopSlideShow = false;
	var delayTimer = 8;
	var hndFPSlider = setInterval(function () {
		if(delayTimer>8){stopSlideShow=false;delayTimer=0;}
		if(stopSlideShow && delayTimer<10){delayTimer++; return;}
		var lastActiveCircle = $('ul.FPslideshowTopNav').find('.slide_circle_active');
		var nextActiveCircle = $(lastActiveCircle).parents().nextUntil().find('.slide_circle').first();
		var slideNum = $(nextActiveCircle).parents().find('a').attr('href');
		if(!slideNum){
			var nextActiveCircle = $(lastActiveCircle).parents('ul.FPslideshowTopNav').children('li').find('.slide_circle').first();
		}
		$(lastActiveCircle).removeClass('slide_circle_active');
		$(nextActiveCircle).addClass('slide_circle_active');
		
		$(".FPslideshowTopSlides").hide().removeClass('active_slide');
		var activeTab = $('.slide_circle_active').parents().find("a").attr("href"); 
			$(activeTab).fadeIn().addClass('active_slide');
		return false;
	}, 6500);
	$('.slide_circle, #FP_top_next, #FP_top_prev').click(function() {
			stopSlideShow = true;
			delayTimer = 0;
			});
	$('#FP_top_next').click(function(){
		var lastActiveCircle = $('ul.FPslideshowTopNav').find('.slide_circle_active');
		var nextActiveCircle = $(lastActiveCircle).parents().nextUntil().find('.slide_circle').first();
		var slideNum = $(nextActiveCircle).parents().find('a').attr('href');
		if(!slideNum){
			var nextActiveCircle = $(lastActiveCircle).parents('ul.FPslideshowTopNav').children('li').find('.slide_circle').first();
		}
		$(lastActiveCircle).removeClass('slide_circle_active');
		$(nextActiveCircle).addClass('slide_circle_active');
		
		$(".FPslideshowTopSlides").hide().removeClass('active_slide');
		var activeTab = $('.slide_circle_active').parents().find("a").attr("href"); 
	        $(activeTab).fadeIn().addClass('active_slide'); 
/*
	     if ($(".active_slide").next().length === 0) {
			$('#FP_top_next').die('click', aClick);
	     }
    	     if ($('.slide_circle').hasClass('slide_circle_active')) {
        	     $('.slide_circle_active').removeClass('slide_circle_active').parents().nextUntil().find('.slide_circle').first().addClass('slide_circle_active');
		     $(".FPslideshowTopSlides").hide().removeClass('active_slide');
		     var activeTab = $('.slide_circle_active').parents().find("a").attr("href"); 
		     $(activeTab).fadeIn().addClass('active_slide'); 
		     return false;
             }
*/
	});
	$('#FP_top_prev').click(function(){
                var lastActiveCircle = $('ul.FPslideshowTopNav').find('.slide_circle_active');
		var nextActiveCircle = $(lastActiveCircle).parents().prevUntil().find('.slide_circle').first();
		var slideNum = $(nextActiveCircle).parents().find('a').attr('href');
		if(!slideNum){
			var nextActiveCircle = $(lastActiveCircle).parents('ul.FPslideshowTopNav').children('li').find('.slide_circle').last();
		}
		$(lastActiveCircle).removeClass('slide_circle_active');
		$(nextActiveCircle).addClass('slide_circle_active');
		
		$(".FPslideshowTopSlides").hide().removeClass('active_slide');
		var activeTab = $('.slide_circle_active').parents().find("a").attr("href"); 
	        $(activeTab).fadeIn().addClass('active_slide');
/*
		if ($("#slide1").hasClass('active_slide')) {
			$('#FP_top_prev').die('click', aClick);
			}
    	if ($('.slide_circle').hasClass('slide_circle_active')) {
        	$('.slide_circle_active').removeClass('slide_circle_active').parents().prevUntil().find('.slide_circle').first().addClass('slide_circle_active');
			$(".FPslideshowTopSlides").hide().removeClass('active_slide');
			var activeTab = $('.slide_circle_active').parents().find("a").attr("href"); 
				$(activeTab).fadeIn().addClass('active_slide');
			return false;
        }
*/
	});

}); /* window load function end */

// FP Boxes	
	$(".boxes").hide(); 
	$(".boxes:first").show(); 
	$("ul.boxesNav li img.box_circle").click(function() {
		$("ul.boxesNav li img").removeClass("boxes_active"); 
		$(this).addClass("boxes_active"); 
		$(".boxes").hide(); 
		var activeBox = $(this).parents().find("a").attr("href"); 
		$(activeBox).fadeIn(); 
		$('#cite1, #cite2, #cite3, #cite4,  #cite5').hide();
		return false;
	});

// FPCarousel
	var FPcarousel = '#FPcarousel ul li';
	var FPcarouselActive = '#FPcarousel ul li.active';
	var FPnavNext = '#FPnav_next';
	var FPnavPrev = '#FPnav_prev';
	var FPitemWidth = $(FPcarousel).outerWidth(true); 
	var FPitemCount = $(FPcarousel).length;
	var FPlistWidth = FPitemWidth*FPitemCount;
	
	$('#FPcarousel ul').css('width',FPlistWidth); 
	$('#FPcarousel ul li:first').addClass('active');
	$(FPnavNext).click(function() { 
		if($(FPcarouselActive).next().next().next().next().next().length === 0) {
			$(FPnavNext).die('click', aClick);
			}
			$('#FPcarousel ul li').animate({'left': '-=' + FPitemWidth + 'px'}, '500');
		$(FPcarouselActive).next().addClass('active');
		$(FPcarouselActive).prev().removeClass('active');
		
		$(FPnavPrev).removeClass('inactive');
		
		if($(FPcarouselActive).next().next().next().next().next().length === 0) {
			$(FPnavNext).addClass('inactive');
			}
	}); 
	if($(FPcarouselActive).prev().length === 0) {
			$(FPnavPrev).addClass('inactive');
			}
	$(FPnavPrev).click(function() { 
		if($(FPcarouselActive).prev().length === 0) {
			$(FPnavPrev).die('click', aClick);
			}
			$('#FPcarousel ul li').animate({'left': '+=' + FPitemWidth + 'px'}, '500');
		$(FPcarouselActive).prev().addClass('active');
		$(FPcarouselActive).next().removeClass('active');
		$(FPnavNext).removeClass('inactive');
		if($(FPcarouselActive).prev().length === 0) {
			$(FPnavPrev).addClass('inactive');
			}
	});	
	
// FP Cites-show
	function citeshow() {
	$('#cite1').fadeIn(1500).delay(3000).fadeOut(1500).next('#cite2').delay(6000).fadeIn(1500).delay(3000).fadeOut(1500).next('#cite3').delay(12000).fadeIn(1500).delay(3000).fadeOut(1500).next('#cite4').delay(18000).fadeIn(1500).delay(3000).fadeOut(1500).next('#cite5').delay(24000).fadeIn(1500).delay(3000).fadeOut(1500, citeshow);
	}
    citeshow()	
	
});

// Language placeholders
var objPhContainer;
var strSelType;
var strSelCategory;
var objCurSaveFeedback;
var strCurPhSaveName;

function ucwords(str) {
	return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
        return $1.toUpperCase();
    });
}

function loadPlaceholders(){
	//console.log("Container found!");
	objPhContainer = $('.placeholderContainer');
	var objSearch = $('#placeholderSelectors a');
	var objPhTypes = $('#placeholderSelectors select#placeholdersTypes');
	var objPhCategories = $('#placeholderSelectors select#placeholdersCategories');
	var objFeedbackBox = $('#placeholderSelectors .feedback');
	
	$(objSearch).click(function(){
		strSelType = $(objPhTypes).val();
		strSelCategory = $(objPhCategories).val();
		if(strSelType=='' || strSelCategory==''){
			$(objFeedbackBox).hide().html('Please select both a TYPE and a CATEGORY!').fadeIn();
		}else{
			$(objPhContainer).fadeOut(function(){
				console.log("Asking for data");
				dataLookUp(strSelType, strSelCategory);	
				$(objFeedbackBox).fadeOut(function(){
					$(objFeedbackBox).html('');
				});
			});
		}
	});	
}

function dataLookUp(strType, strCategory, intStart, intEnd) {
	if(!intStart) intStart = 0;
	if(!intEnd) intEnd = 1000;
	var strInput = ({
		type: strType,
		category: strCategory,
		action: 'get',
		start: intStart,
		end: intEnd
	});
	$.ajax({
		type: "POST",
		url: "http://www.casinoverdiener.com/language_placeholders_script",
		data: strInput,
		success: dataFetched,
		error: dataError
	});
}

function dataFetched(result){
	console.log("Data retrieved");
	$(objPhContainer).html(result).fadeIn();	
	//console.log("Data displayed");
}

function savePlaceholder(e){
	strCurPhSaveName = $(e).attr('phname');
	if(strCurPhSaveName==''||strCurPhSaveName==' '){
		showFeedback($(e).next('.feedback'), 'Please enter a placeholder-name!');
		return;
	}
	
	// Get the content of the input fields related to the placeholder:
	var arrTranslations = new Object();
	var objTdPhContent = $(e).parents('tr.phName').next('tr.phContent').find('td');
	var objInputFieldsContent = $(objTdPhContent).find('input');
	for(var i=0;i<objInputFieldsContent.length;i++){
		var strKey = $(objInputFieldsContent[i]).attr('phlang');
		var strValue = $(objInputFieldsContent[i]).val();
		arrTranslations[strKey] = strValue;
	}
	
	if(arrTranslations['en']==''||arrTranslations['en']==' '){
		showFeedback($(e).next('.feedback'), 'Please enter the english content');
		return;
	}
	
	var strExampleText = $(objTdPhContent).find('textarea.phContentExample').val();
	
	console.log("Asking to save "+strCurPhSaveName);
	dataSave(strSelType, strSelCategory, strCurPhSaveName, strExampleText, arrTranslations);
}

function dataSave(strType, strCategory, strName, strExample, arrTranslations) {
	console.log(arrTranslations);
	var strInput = ({
		type: strType,
		category: strCategory,
		phName: strName,
		example: strExample,
		phTranslations: arrTranslations,
		action: 'save'
	});
	$.ajax({
		type: "POST",
		url: "http://www.casinoverdiener.com/language_placeholders_script",
		data: strInput,
		success: dataSaved,
		error: dataError
	});
}

function dataSaved(result){
	console.log("Data saved");
	/*
	var objCurSavedFeedbackBox = $('.feedback.'+strCurPhSaveName);
	$(objCurSavedFeedbackBox).hide().html(result).fadeIn(function(){
		$(objCurSavedFeedbackBox).delay(2000).fadeOut();
	});
	*/
	showFeedback($('.feedback.'+strCurPhSaveName), result);
	
	// Remove the placeholdername-input field if a new placeholder was created:
	if(result.search("Placeholder was created")!=-1){
		$('.feedback.'+strCurPhSaveName).parents('td.phSave').prev('td.phName').html('[+'+strSelType+'.'+strCurPhSaveName+'+]');
		var objCancelBtn = $('.feedback.'+strCurPhSaveName).parents('td.phSave').find('.cancel');
		$(objCancelBtn).slideUp(function(){$(objCancelBtn).remove();});
	}
}

function dataError(result){
	console.log("Error when fetching AJAX data: "+result)
}

function showFeedback(obj, string){
	$(obj).hide().html(string).fadeIn(function(){
		$(obj).delay(2000).fadeOut();
	});
}

function addExtraLanguageVars(e){
	console.log("Add new placeholder");
	var objPhMainRow = $('<tr>').attr('class', 'phName').css('display', 'none').append(
		$('<td>').attr('class', 'phName').append('[+'+strSelType+'.').append(
			$('<input />')
			.attr('type','text')
			.attr('id','ph_name')
			.keypress(function(){updatePhName(this);})
		).append('+]')
	).append(
		$('<td>').attr('class', 'phSave').append(
				$('<a>').attr('class', 'cancel').attr('onclick', 'removePlaceholder(this); return false;').html('Cancel')
			).append(
			$('<div>').append(
				$('<a>').attr('class', 'ButtonYellowSmall right').attr('phname', '').attr('phcategory', strSelCategory).attr('phtype', strSelType).attr('onclick', 'savePlaceholder(this); return false;').html('Save')
			).append(
				$('<span>').attr('class', 'feedback').html('&nbsp;')
			)
		)
	)
	$(e).parents('tr.addPlaceholderWord').before(objPhMainRow);
	console.log("Main row inserted!");
	
	var objPhContentRow = $('<tr>').attr('class', 'phContent').css('display', 'none');
	var objPhContentCell = $('<td>').attr('class', 'phContent').attr('colspan', '2').append(
		$('<div>').append(
			$('<label>').attr('class', 'bold').attr('for', 'ph__example').html('Context example:')
		).append(
			$('<textarea>').attr('id', 'ph__example').attr('class', 'phContentExample')
		)
	).appendTo(objPhContentRow);
	var arrLanguages = new Object({
		'de':'german',
		'da':'danish'
	});
	$.each(arrLanguages, function(key, value){
		$(objPhContentCell).append(
			$('<label>').attr('for', 'ph__'+key).append(
				$('<img />').attr('height', 15).attr('alt', value).attr('src', 'assets/sysimages/flags/'+value+'.png')
			)
		).append(
			$('<input />').attr('id', 'ph__'+key).attr('type', 'text').attr('phlang', key)
		).append('<br/>');
	});
	$(e).parents('tr.addPlaceholderWord').before(objPhContentRow);
	
	$(objPhMainRow).fadeIn('slow');
	$(objPhContentRow).fadeIn('slow');
	
	console.log("Content row inserted!");
}

function removePlaceholder(e){
	console.log("Remove placeholder");
	var objPhMainRow = $(e).parents('tr.phName');
	var objPhContentRow = $(objPhMainRow).next('tr.phContent');
	$(objPhMainRow).fadeOut(function(){
		$(objPhContentRow).fadeOut(function(){
			$(objPhMainRow).remove();
			$(objPhContentRow).remove();
		});
	});
	
	console.log("Placeholder removed!");
}

var keyDownTimer;
function updatePhName(e){
	clearTimeout(keyDownTimer);
	keyDownTimer = setTimeout(function(){
		console.log("Timer has ended!");
		var strMyValue = $(e).val();
		strMyValue = ucwords(strMyValue);
		strMyValue = strMyValue.replace(/ /gi,"");
		var objSaveButton = $(e).parents('td').next('td.phSave').find('a');
		var objFeedbackbox = $(e).parents('td').next('td.phSave').find('span.feedback');
		$(objSaveButton).attr('phname', strMyValue);
		$(objFeedbackbox).attr('class', 'feedback '+strMyValue);
	}, 1000);
}
