try { console.debug('console init...'); } catch(e) { console = { debug: function(){}, log: function(){} };}

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

$(document).ready(function() {

	$(".zenit_button").button({
		icons: {}
	});

	// Tabs
	$('#anzeigetabs').tabs();
	$('#anzeigesubtabs').tabs();

	$('.header').cycle({
		fx: 'fade',
		timeout: 12000,
		speed: 800,
		cleartype: true,
		cleartypeNoBg: true
	});
	
	$('.newstickerlist').cycle({
		fx: 'scrollHorz',
		timeout: 5000,
		speed: 1200,
		cleartype: true,
		cleartypeNoBg: true,
		pause: true
	});

	$('.anzeigenbyregion_pfeil_sw').click(function () {
		if ($(this).parent().parent().find('.anzeigenbyregion').css('display') == "none") {
			$(this).css('backgroundImage','url(/images/pfeil_up.png)');
			$(this).parent().parent().find('.anzeigenbyregion').fadeIn(500);
		} else {
			$(this).css('backgroundImage','url(/images/pfeil.png)');
			$(this).parent().parent().find('.anzeigenbyregion').fadeOut(500);
		}
	});
	
	$('#services_pfeil_sw').click(function () {
		if ($('#services').css('display') == "none") {
			$('#services_pfeil_sw').css('backgroundImage','url(/images/pfeil_up.png)');
			$('#services').slideDown(500);
		} else {
			$('#services_pfeil_sw').css('backgroundImage','url(/images/pfeil.png)');
			$('#services').slideUp(500);
		}
	});
	
	
	$('.city_box_sw').click(function () {
		if ($('.cities_box').css('display') == "none") {
			$(this).css('backgroundImage','url(/images/pfeil_up.png)');
			$('.cities_box').slideDown();
		} else {
			$(this).css('backgroundImage','url(/images/pfeil.png)');
			$('.cities_box').slideUp();
		}
	});
	
	$('.city_box').hover(
		function () {
			$(this).css("zIndex","11");
			$(this).find("a").animate({
				color: 	"#fff"
			});
			$(this).animate({
				width: 	"+=12px",
				height: "+=12px",
				left: 	"-=6px",
				top: 	"-=6px",
				lineHeight: "38px",
				fontSize: "+=2px",
				color: 	"#fff",
				backgroundColor: "#390000"
			});
		},
		function () {
			$(this).css("zIndex","10");
			$(this).find("a").animate({
				color: 	"#000"
			});
			$(this).animate({
				width: "-=12px",
				height: "-=12px",
				left: 	"+=6px",
				top: 	"+=6px",
				lineHeight: "26px",
				fontSize: "-=2px",
				color: 	"#000",
				backgroundColor: "#ddd"
			});
		}
	);

	$('textarea.tinymce').tinymce({
		// Location of TinyMCE script
		script_url : '/js/tiny_mce/tiny_mce.js',

		// General options
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,forecolor,backcolor",
		//theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		//theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "/css/xxx.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
				username : "Some User",
				staffid : "991234"
		}
	});
	
});

function unlinkBild(file, id) {
	
	$.ajax({
		url: "/profile/unlinkbild/"+file,
		success: function(msg){
		$("#"+id).fadeOut(300);
		}
	});
		
}

function deleteProfile(id) {
	$.ajax({
		url: "/profile/deleteProfile/"+id,
		success: function(msg){
			window.location.href = "/overview/viewbyuser/";
		}
	});
		
}


