// JavaScript Document

$(document).ready(function(){

	/** JS HIDE **/
	$('.newsBlockTextMore').css('display', 'none');
	$('#contentSmallinfo').css('display', 'none');

	/** GENERAL TOGGLE FUNCTION **/
	$('.toggleNext').click(function () {
		if($(this).next().css('display') == 'none') {
			$(this).find('img').attr('src', 'pictures/minus.png');
			$(this).find('img').attr('alt', 'Minimieren');
			$(this).find('span').replaceWith('<span>Read less...</span>');
			$(this).next().slideDown();
		} else {
			$(this).find('img').attr('src', 'pictures/plus.png');
			$(this).find('img').attr('alt', 'Maximieren');
			$(this).find('span').replaceWith('<span>Read more...</span>');
			$(this).next().slideUp();
		}
	});
	
	/** DELETE NEWS **/
	$(function() {
		$('.newsBlockDeleteNewsText').dialog({
			bgiframe: true,
			height: 140,
			modal: true,
			autoOpen: false, 
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				Ok: function() {
					alert('123');
					$(this).dialog('close');
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			}
		});
	});
	
	/** NEWS DELETE BUTTON **/
	$('.newsBlockDeleteNewsHref').click(function () {
		//$(this).next('.newsBlockDeleteNewsText').dialog('open');
		$.post('ajax.html', { action: 'delnews', newsid: $(this).attr('name') },
		function(data){
			if (data == 'true'){
				alert('true');
			} else {
				alert('false');
			}
		});
	});
	
	/** SHOUTBOX POST ADD **/
	$('#sbSubmit').click(function () {
		var varName = $('#sbName').attr('value');
		var varText = $('#sbText').attr('value');
		var varRegistered = null;
		
		$.post('ajax.html', { action: 'addshoutboxpost', name: varName, text: varText},
		function(data){
			if (data == 'true'){
				$('#sbText').attr('value', '');
				$('#modShoutboxFrame').prepend('<div class="modShoutboxItem modShoutboxItemNew">' + '<div class="modShoutboxItemName">' + varName + '</div>' + '<div class="modShoutboxItemText">' + varText + '</div>' + '</div>');
			} else {
				alert('mistake in the shoutbox');
			}
		});
	});
						   
	/** PROFIL - ADD **/
	$('.userBlockLinkAdd').click(function () {
		alert('add something');
	});

	/** TUTORIALS - OPEN (1) **/
	
	$('.tutorialsBlockOpen').click(function () {
		if($(this).next('.tutorialsSubBlock').css('display') == 'none') {
			$(this).find('img').attr('src', 'pictures/minus.png');
			$(this).find('img').attr('alt', 'Minimieren');
			$(this).next('.tutorialsSubBlock').slideDown();
		} else {
			$(this).find('img').attr('src', 'pictures/plus.png');
			$(this).find('img').attr('alt', 'Maximieren');
			$(this).next('.tutorialsSubBlock').slideUp();
		}
	});
	
	/** TUTORIALS - OPEN (2) **/
	
	$('.tutorialsSubBlockOpen').click(function () {
		if($(this).next('.tutorialsSubBlockText').css('display') == 'none') {
			$(this).find('img').attr('src', 'pictures/minus.png');
			$(this).find('img').attr('alt', 'Minimieren');
			$(this).next('.tutorialsSubBlockText').slideDown();
		} else {
			$(this).find('img').attr('src', 'pictures/plus.png');
			$(this).find('img').attr('alt', 'Maximieren');
			$(this).next('.tutorialsSubBlockText').slideUp();
		}
	});	
	
	
	/** DOWNLOADS - OPEN **/
	
	$('.downloadsBlockOpen').click(function () {
		if($(this).next('.downloadsSubBlock').css('display') == 'none') {
			$(this).find('img').attr('src', 'pictures/minus.png');
			$(this).find('img').attr('alt', 'Minimieren');
			$(this).next('.downloadsSubBlock').slideDown();
		} else {
			$(this).find('img').attr('src', 'pictures/plus.png');
			$(this).find('img').attr('alt', 'Maximieren');
			$(this).next('.downloadsSubBlock').slideUp();
		}
	});
	
	
	//$('#exampleRange').datepicker({dateFormat: 'dd.mm.yy', rangeSelect: false, firstDay: 1});
	
});

/** Redirects the user to a specific url with JavaScript **/
function redirect(url){
	window.location.replace(url);
}