/**
 * COWIS
 * main jquery manipulation
 *
 * (c) Timo Besenreuther
 *     EZdesign
 *
 * Created:       2008-09-25
 * Last modified: 2008-09-25
 */

$(document).ready(function() {
	// forms
	$('#check2').attr('value', 'imhuman');
	
	// buttons
	$('#rule_links a').hover(function() {
		$('#rule_links_text').html($(this).find('img').eq(0).attr('alt'));
	}, function() {
		$('#rule_links_text').html('');
	});
	
	// flash intro
	if (window.location.href.indexOf('changeview=edit') == -1) {
		var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="200" height="329">'
		         + '<param name="movie" value="includes/intro.swf" />'
		         + '<param name="quality" value="high" />'
		         + '<embed src="includes/intro.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="200" height="329"></embed>'
		         + '</object>';
		$('#homeflash').html(html);
	}
	
	if (window.location.href.indexOf('changeview=edit') == -1) {
		// akkordeon
		$('#center .akkordeon_text').hide()/*.eq(0).show()*/;
		$('#center .akkordeon_head').click(function() {
			var nextContent = $(this).next('.akkordeon_text');
			$('#center .akkordeon_on').removeClass('akkordeon_on');
			if (!nextContent.is(':visible')) {
				$('#center .akkordeon_text:visible').hide('blind', {}, 800);
				nextContent.show('blind', {}, 500);
				$(this).addClass('akkordeon_on');
			} else {
				nextContent.hide('blind', {}, 500);
			}
		}).hover(function() {
			$(this).addClass('akkordeon_hover');
		}, function() {
			$(this).removeClass('akkordeon_hover');
		})/*.eq(0).addClass('akkordeon_on')*/;
		if (typeof(akkordeonOpenFirst) != 'undefined') {
			$('#center .akkordeon_head').eq(0).triggerHandler('click');
		}
		
		// home table
		$('#home_table .home_table_text').append('<div class="spacer" style="display:none">&nbsp;</div>').hover(function() {
			var el = $(this);
			el.find('*').hide();
			el.find('.spacer').show();
			el.stop(true).animate({backgroundPosition: '45px 5px'}, 'fast');
		}, function() {
			var el = $(this);
			el.stop(true).animate({backgroundPosition: '-85px 5px'}, 'fast');
			el.find('.spacer').hide();
			el.find('*:not(.spacer)').show();
		});
		$('#home_table .home_table_head').hover(function() {
			var id = $(this).attr('class').substr(16);
			var el = $('#'+id);
			el.find('*').hide();
			el.find('.spacer').show();
			el.stop(true).animate({backgroundPosition: '45px 5px'}, 'fast');
		}, function() {
			var id = $(this).attr('class').substr(16);
			var el = $('#'+id);
			el.stop(true).animate({backgroundPosition: '-85px 5px'}, 'fast');
			el.find('.spacer').hide();
			el.find('*:not(.spacer)').show();
		});
	}
});


/**
 * newsletter subscription form
 */

var newsletterSubscribe = {
	error: 'newsletter_subscribe_error',
	custom: {
		email: {
			fn: function() {
				mail = document.getElementById('newsletter_email').value;
				return (mail.length > 6 && mail.indexOf('@') != -1);
			},
			error: 'Bitte geben Sie eine gültige E-Mail Adresse an.'
		}
	}
};


/**
 * infomaterial box
 */

function checkformInfomaterialSmall() {
	var infoBox = {
		error: 'error_klein',
		mandatory: {
			name_klein: 'Name',
			mail_klein: 'E-Mail',
			tel_klein: 'Telefon'
		},
		text: {
			mandatoryError: 'Sie haben folgende Pflichtfelder nicht ausgef&uuml;llt:'
		}
	};
	
	if ($('#send_infomat_per_mail_small').is(':checked')) {
		infoBox.mandatory["str_klein"] = "Stra&szlig;e";
		infoBox.mandatory["ort_klein"] = "Ort";
	}
	
	formchecker(document.getElementById('infomaterial_klein'), '', infoBox);
}

function infoboxShow(check, id) {
	document.getElementById(id).style.display = (check ? "block" : "none");
	if (id == "postinfo_klein") {
		document.getElementById("infoklein_addinfo").style.display = (check ? "" : "none");
	}
}


/**
  * contact form
  */
 
function checkformContact() {
	err = new Array;
	if (document.getElementById("name").value == "")
		err.push("Name");
	if (document.getElementById("mail").value == "")
		err.push("E-Mail");
	if (!(document.getElementById("tel_vor").value != "" && document.getElementById("tel_nr").value != ""))
		err.push("Telefon");
	if (document.getElementById("anfrage").value == "")
		err.push("Nachricht");
	if (err.length > 0) {
		document.getElementById("error_kontakt").innerHTML = "<b>Bitte f&uuml;llen Sie folgende Felder aus:</b><br />"+err.join(", ")+".";
		document.getElementById("error_kontakt").style.display = "block";
		return false;
	}
	return true;
}


/**
 * infomaterial
 */

function checkformInfomaterial() {
	var felder = {
		"name": "Name",
		"mail": "E-Mail Adresse",
		"tel_nr": "Telefon"
	};
	if ($('#send_infomat_per_mail_big').is(':checked')) {
		felder["str"] = "Stra&szlig;e";
		felder["ort"] = "Wohnort";
	}
	
	var error  = new Array();
	var values = new Array();
	for (key in felder) {
		var val = document.getElementById(key).value;
		if (val == "" || val == " ") {
			error.push(felder[key]);
		}
	}
	
	var errorHTML = new Array();
		if (error.length > 0) {
		document.getElementById("error").innerHTML = "<b>Sie haben folgende Pflichtfelder nicht ausgef&uuml;llt:</b><br /> "+error.join(", ")+".";
		document.getElementById("error").style.display = "block";
	} else {
		document.getElementById("conf").value = "conf";
		document.getElementById("infomaterial").action = "front_content.php?idart=58";
		document.getElementById("infomaterial").submit();
	}
}

function showInfomaterialInfo(check, id) {
	if (check) {
		document.getElementById(id).style.display = "block";
	} else {
		document.getElementById(id).style.display = "none";
	}
}