$.wptb = new Object();

$(document).ready( function () {
	
	/*if ( location.href.indexOf('gewinne-eines-von-50-free-tickets-fur-alle-5-housebar-tage') != -1 )
		 showLogin();*/
	
});

function showLogin() {
	
		if ( !$('#mo1').attr('id') ) {
			//location.href = 'http://www.housebar.de/kontakt/impressuma/gewinne-eines-von-50-free-tickets-fur-alle-5-housebar-tage/';	
		}
	
	
		if ($("#mo1:checked").val() == "1") {
			$('#register-form').hide();
		} else {
			$('#login-form').hide();
		}
		
		$('#mo1').bind("change", function(e) 
				{
					$('#register-form').slideUp("fast");
					$('#login-form').slideDown("fast");
				});
		
		$('#mo2').bind("change", function(e) 
				{
					$('#login-form').slideUp("fast");
					$('#register-form').slideDown("fast");
				});
		
		$("#wp-tb-login").bind('submit', function() {return false;});
		
		
		
		
		$('#wp-thickbox-login').hide();
		
		if ( $('#wp-thickbox-login').attr('id') ) {
			
			
			
			
			var tbArgs = '#TB_inline?inlineId=wp-thickbox-login&height=487&width=670';
			$('#wp-thickbox-login').show();
			tb_show( '', tbArgs , false );
			$('#TB_title').remove();
			
			$('#mo2').click().change();
			
			
			/*
			 * Ajax Form
			 */
			var options = { 
			        target:        '#wp-tb-response',   // target element(s) to be updated with server response 
			        beforeSubmit:  validateRequest,  // pre-submit callback 
			        success:       showResponse,
			        type: "POST",
			        dataType: "html"
			        
			        // other available options: 
			        //url:       url         // override for form's 'action' attribute 
			        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
			        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			        //clearForm: true        // clear all form fields after successful submit 
			        //resetForm: true        // reset the form after successful submit 
			 
			        // $.ajax options can be used here too, for example: 
			        //timeout:   3000 
			    }; 

			$( '#wp-tb-response' ).hide();
			$("#wp-tb-login").ajaxForm(options);
		}
	}

//pre-submit callback 
function validateRequest(formData, jqForm, options) { 
    //alert('val');
	// formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    //alert('About to submit: \n\n' + queryString); 
    $( '#wp-tb-response' ).hide();
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property
	if ( responseText == '1' || responseText == '2' ) {
		var rText = '<b>Vielen Dank f&uuml;r deine Anmeldung.</b>';
		if ( responseText == '1' ) {
			rText = 'Du wurdest erfolgreich eingeloggt.';
		}
		
		rText = rText + ' Weiterleitung erfolgt...';
		$( '#wp-tb-response' ).show();
		$( '#wp-tb-response' ).html( rText );
		$( '#wp-tb-response' ).animate({opacity: 1.0}, 2000).hide(1, $.wptb.tb_safe_remove);
	} else {
		$( '#wp-tb-response' ).show();
		$( '#wp-tb-response' ).html( responseText );
	}
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
} 


$.wptb.tb_safe_remove = function () {

	

	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	$('#wp-thickbox-login').hide();
	
	//location.href = 'http://www.housebar.de/kontakt/impressuma/gewinne-eines-von-50-free-tickets-fur-alle-5-housebar-tage/';	
	
	return false;
}