$(document).ready(function(){	
	/* Shadowbox */
	var options = {flvPlayer:'inc/mediaplayer.swf', enableKeys:false};
	Shadowbox.init(options);

	/* recommend */
	
	$("#recommend").each(function() {
		var jobj=$(this);
		var pageid=$(this).attr('rel');
		var secode="";

		var recvalue = "<h2 id='recpanel'>Diese Seite weiterempfehlen ... <\/h2><div style='display:none'><form id='recform'><table><tr><td width='120'><label for='amail'>Ihre E-Mail:<\/label><\/td><td><input type='text' id='amail' name='amail' value='' size='30' maxlength='50' \/><\/td><\/tr><tr><td><label for='email'>Empf&auml;nger E-Mail:<\/label><\/td><td><input type='text' id='email' name='email' value='' size='60' maxlength='200' \/><\/td><\/tr><tr><td>&nbsp;<\/td><td>mehrere Empf&auml;nger werden durch Komma getrennt<\/td><\/tr><tr><td><label for='atext'>Text:<br />(optional)<\/label><\/td><td><textarea id='atext' name='atext' cols='60' rows='3' \/><\/textarea><\/td><\/tr><tr><td>&nbsp;<\/td><td><span id='msgbox'><input type='submit' value='absenden' \/><\span><\/td><\/table><\/form><\/div>";
		$(jobj).html(recvalue);	
		/* Slide-Panel */
		$('#recpanel').slidePanel();  

		$('#recform').submit(function()
		{
			//remove all the class add the messagebox classes and start fading
			$("#msgbox").removeClass().addClass('infobox').html('<img src="/images/loading_small.gif" /> ...').fadeIn(1000);
			
			// get secode
			$.post("estemp/functions/recommend.php", { p_pageid:pageid,p_secode:"getsecode"}, function (secode) 
			{
					
				// check data	
				$.post("estemp/functions/recommend.php",{ p_amail:$('#amail').val(),p_email:$('#email').val(),p_atext:$('#atext').val(),p_pageid:pageid,p_secode:secode }, function (data)
				{
					if(data=='OK') // if correct login detail
					{
						$("#msgbox").fadeTo(200,0.1,function()	//start fading the messagebox
						{
							//add message and change the class of the box and start fading
							$('#recpanel').trigger("click").unbind("click").html('Die Empfehlung wurde versendet. Vielen Dank!').css("cursor","default");
						});
					}
					else
					{
						if(data.indexOf("(#") != -1)
						{
							$("#msgbox").fadeTo(200,0.1,function()	//start fading the messagebox
							{
								//add message and change the class of the box and start fading
								$('#recpanel').trigger("click").unbind("click").html(data).css("cursor","default");
							});
						}
						else
						{
							$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
							{
								//add message and change the class of the box and start fading
								$(this).html("<input type='submit' value='absenden' \/>&nbsp;"+data).addClass('alertbox').fadeTo(900,1);
							});
						}
					}
				});
			});
			
			return false;//not to post the form physically
		});
	});
	
	/* login */

	$("#login").each(function(){
		var jobj=$(this);
		/* var pageid=$(this).attr('rel'); */
		
		/* Slide-Panel */
		$('#loginpanel').slidePanel();

		$('#loginpanel').click(function()
		{
			$("#log_name").focus();
		});


		$('#loginform').submit(function()
		{
			//remove all the class add the messagebox classes and start fading
			$("#logmsgbox").removeClass().addClass('infobox').html('<img src="/images/loading_small.gif" />').fadeIn(1000);

			// check data	
			$.post("index.php",{ page:'logincheck.txt',log_name:$('#log_name').val(),log_pass:$('#log_pass').val(),id:$('#log_id').val() }, function (data)
			{
				if(data!='') // if correct login detail
				{
					// &id='+$('#log_id').val()+'
					
					window.location.replace('http://www.literaturmachen.de/index.php?&id=1,0,626&sid='+data); 
				}
				else
				{
					$("#logmsgbox").fadeTo(200,0.1,function() //start fading the messagebox
					{
						//add message and change the class of the box and start fading
						$(this).html("<input type='submit' value='absenden' \/><br \/>Benutzer oder Passwort falsch").addClass('alertbox').fadeTo(900,1);

					});
				}
			});
			
			
			return false;//not to post the form physically
		});


	});
		
});
