/*
 * Variablen setzen
 */

var config = new Object();
config["pathSystem"] = 'http://www.kristinaschroeder.de/system/';



/*
 * Ziele ein- / ausblenden
 */

window.addEvent('load', function() {

	var configCounter = 0;

	$$('#ziele li h3').each(function(item) {

		var id = item.getProperty('id');

		var iconSlideIn = new Element('img', {'src': config["pathSystem"]+'images/icon_slidein.gif', 'class': 'icon', 'id': id+'Icon'});

		if (id != null) {

			item.setProperty('style', 'cursor:pointer;');

			iconSlideIn.inject(item, 'top');

			var elemShowFx = new Fx.Slide(id+'Details', {duration: 500});
			elemShowFx.hide();

			configCounter ++;

			item.addEvent('click', function(e) {

				elemShowFx.toggle();
				if ($(id+'Icon').get('src') == config["pathSystem"]+'images/icon_slideout.gif') {
					$(id+'Icon').set('src', config["pathSystem"]+'images/icon_slidein.gif');
				} else {
					$(id+'Icon').set('src', config["pathSystem"]+'images/icon_slideout.gif');
				}

			});

			item.addEvent('slideIn', function(e) {

				elemShowFx.slideIn();
				$(id+'Icon').set('src', config["pathSystem"]+'images/icon_slideout.gif');

			});

			item.addEvent('slideOut', function(e) {

				elemShowFx.slideOut();
				$(id+'Icon').set('src', config["pathSystem"]+'images/icon_slidein.gif');

			});
		}
	});
});





window.addEvent("load", function(){

	['left', 'center', 'right'].each(function(item, index) {

		container = new Element('span', { 'class': 'gupsi_imageSubtitle_'+item});

		$$('.align_'+item).each(function(img) {

			var subtitle = img.getProperty('title');

			if (subtitle != null) {

				imageContainer = container.clone();
				imageContainer.setStyle('width', img.offsetWidth);
				imageContainer.set('text', subtitle);
				img.setProperty('title', '');
				imageContainer.injectAfter(img);
				img.injectTop(imageContainer);

			}
		});
	});

});




/*
 * SqueezeBox fuer iFrames starten
 */
window.addEvent('domready', function() {

	SqueezeBox.assign($$('a[rel=boxed]'));


});




/*
 * Gaestebuch erweitern
 */

function guestbookAdd () {

	new Request.JSON({url: config["pathSystem"]+'ajax/guestbook_add.php', onComplete: function(response){

		//Formular zuruecksetzen
		if (response.status == "true") {

			$('guestbookName').value = '';
			$('guestbookEmail').value = '';
			$('guestbookContent').value = '';

		}

		//Hinweis ausgeben
		MessageBox.status(response.msg);

	}}).post({'name': $('guestbookName').value, 'email': $('guestbookEmail').value, 'content': $('guestbookContent').value});

}



/*
 * Frage stellen
 */

function questionsAdd () {

	var formElements = document.forms['questionsform'].elements;
	var questionsSexValue = 0;
	if (formElements['questions_sex'][0].checked == true) {
		questionsSexValue = 1;
	} else if (formElements['questions_sex'][1].checked == true) {
		questionsSexValue = 2;
	}

	new Request.JSON({url: config["pathSystem"]+'ajax/questions_add.php', onComplete: function(response){

		//Formular zuruecksetzen
		if (response.status == "true") {

			$('questionsFirstname').value = '';
			$('questionsLastname').value = '';
			$('questionsEmail').value = '';
			$('questionsPhone').value = '';
			$('questionsStreet').value = '';
			$('questionsCity').value = '';
			formElements['questions_sex'][0].checked = false;
			formElements['questions_sex'][1].checked = false;
			$('questionsNotify').checked = false;
			$('questionsContent').value = '';

		}

		//Hinweis ausgeben
		MessageBox.status(response.msg);

	}}).post({'firstname': $('questionsFirstname').value, 'lastname': $('questionsLastname').value, 'email': $('questionsEmail').value, 'phone': $('questionsPhone').value, 'notify': $('questionsNotify').checked, 'street': $('questionsStreet').value, 'city': $('questionsCity').value, 'sex': questionsSexValue, 'content': $('questionsContent').value});

}



/*
 * Leserbriefe ein- / ausblenden
 */

window.addEvent('load', function() {

	var configCounter = 0;

	$$('#comments li h3').each(function(item) {

		var id = item.getProperty('id');

		var iconSlideIn = new Element('img', {'src': config["pathSystem"]+'images/icon_slidein.gif', 'class': 'icon', 'id': id+'Icon'});

		if (id != null) {

			item.setProperty('style', 'cursor:pointer;');

			iconSlideIn.inject(item, 'top');

			var elemShowFx = new Fx.Slide(id+'Details', {duration: 500});
			elemShowFx.hide();

			configCounter ++;

			item.addEvent('click', function(e) {

				elemShowFx.toggle();
				if ($(id+'Icon').get('src') == config["pathSystem"]+'images/icon_slideout.gif') {
					$(id+'Icon').set('src', config["pathSystem"]+'images/icon_slidein.gif');
				} else {
					$(id+'Icon').set('src', config["pathSystem"]+'images/icon_slideout.gif');
				}

			});

			item.addEvent('slideIn', function(e) {

				elemShowFx.slideIn();
				$(id+'Icon').set('src', config["pathSystem"]+'images/icon_slideout.gif');

			});

			item.addEvent('slideOut', function(e) {

				elemShowFx.slideOut();
				$(id+'Icon').set('src', config["pathSystem"]+'images/icon_slidein.gif');

			});
		}
	});
});


/*
 * Leserbrief senden
 */

function commentsAdd (contentId) {

	new Request.JSON({url: config["pathSystem"]+'ajax/comments_add.php', onComplete: function(response){

		//Formular zuruecksetzen
		if (response.status == "true") {

			$('commentName').value = '';
			$('commentEmail').value = '';
			$('commentNotify').checked = false;
			$('commentContent').value = '';

		}

		//Hinweis ausgeben
		MessageBox.status(response.msg);

	}}).post({'name': $('commentName').value, 'email': $('commentEmail').value, 'notify': $('commentNotify').checked, 'content': $('commentContent').value, 'reference': window.location.href, 'id': contentId, 'spam': $('commentSpam').value});

}





/*
 * Abos bei Newsletter verwalten
 */

function newsletterAdd () {

	var newsletterForm = "";
	if ($('newsletterForm') != null) newsletterForm = $('newsletterForm').get("html");
	var newsletterStatus = 'true';
	if ($('newsletterDo')) {
		if ($('newsletterDo').checked == false) {
			newsletterStatus = 'false';
		}
	}

	new Request.JSON({url: config["pathSystem"]+'ajax/newsletter_add.php', onComplete: function(response){

		//Formular zuruecksetzen
		if (response.status == "true") {

			$('newsletterForm').set("html", newsletterForm);
			$('newsletterAddress').value = '';

		}

		//Hinweis ausgeben
		MessageBox.status(response.msg);

	}}).post({'email': $('newsletterAddress').value, 'do': newsletterStatus});

	if ($('newsletterForm') != null) {
		$('newsletterForm').set("html", "<p>Bitte warten...</p>");
	}

}


/*
 * Thumbnails anzeigen
 */

window.addEvent('domready', function(){

	ReMooz.assign();

	$$('a[rel=remooz]').each(function(element) {

		new ReMooz(element, {
			'origin': element.getElement('img'),
			'shadow': 'onOpenEnd',
			'resizeFactor': 0.8,
			'cutOut': false,
			'opacityResize': 0.4,
			'dragging': false,
			'centered': true
		});

	});

});



/*
 * Button fuer Fragen aktivieren
 */
window.addEvent('domready', function(){

	if ($('questionButton') != null) {

		$('questionButton').setProperty('type', 'button');

		$('questionButton').addEvent('click', function () {
			questionsAdd();
		});
	}

});


/*
 * Button fuer Kommentare aktivieren
 */
window.addEvent('domready', function(){

	if ($('commentButton') != null) {

		$('commentButton').setProperty('type', 'button');

		$('commentButton').addEvent('click', function () {
			commentsAdd($('commentButton').getProperty("rel"));
		});
	}

});



/*
 * Default-Wert fuer Massnahme gegen Spam anzeigen
 */

window.addEvent('domready', function(){

	if ($('commentSpam') != null) {

		if ($('commentSpam').value == "") {
			$('commentSpam').value = "dd.mm.yyyy";
			$('commentSpam').setProperty('class', 'spam');
		}

		$('commentSpam').addEvent('click', function () {

			if ($('commentSpam').value == "dd.mm.yyyy") {
				$('commentSpam').value = "";
				$('commentSpam').setProperty('class', 'text');
			}

		});
	}

});

//commentSpam