// method to show sidebar
function fadeSidebarNow( gSide, gPage, gParameters, gWidth )
{
	// check if we have simple sidebars
	if( gPage == "sidebar" && gSide != null )
	{
		// remove old content
		jQuery( ".neo-sidebar-content" ).html( "" );
		
		// set arrangement
		jQuery( "#sidebar" ).removeClass( gSide == "left" ? "right" : "left" );
		jQuery( "#sidebar" ).addClass( gSide );
		
		// set new content
		jQuery( ".neo-sidebar-content" ).html( jQuery( "#neo-sidebar-hidden-content-" + gSide ).html() );
		
		// show layer
		jQuery( ".neo-sidebar" ).fadeIn();
		jQuery( ".neo-sidebar-content" ).fadeIn().css("width", gWidth != null ? gWidth : 300);
	}
	else
	{
		// build url
		var sUrl = "php/ajax/" + gPage + ".ajax.php?t=" + Date.now() + "&side=" + gSide;
		if( jQuery( "#wp_plugin_dir" ).val() != null && jQuery( "#wp_plugin_dir" ).val().length > 0 )
		{
			// get new url
			sUrl = jQuery( "#wp_plugin_dir" ).val() + "/ajax/" + gPage + ".ajax.php?t=" + Date.now() + "&side=" + gSide;
		}
		
		// if parameters are set
		if( gParameters != null )
		{
			// for all properties
			for( var property in gParameters ) 
			{
				// check for won property
			    if( gParameters.hasOwnProperty( property ) ) 
			    {
			        // do stuff
			    	sUrl += "&" + property + "=" + gParameters[ property ];
			    }
			}
		}
		
		// load content
		jQuery( ".neo-sidebar-content" ).load
		( 
			sUrl, 
			function( text, status, xhr ) 
			{
				// add class
				jQuery( "#sidebar" ).removeClass( gSide == "left" ? "right" : "left" );
				jQuery( "#sidebar" ).addClass( gSide );
				
				// show layer
				jQuery( ".neo-sidebar" ).show();
				
				// animate
				jQuery( ".neo-sidebar-content" ).animate
				(
					{
						width: 300
					}, "fast"
				);
			}
		);
	}
}

//method to show sidebar
function showSidebar( gSide, gPage, gParameters )
{
	// show
	showSidebarNow( gSide, gPage, gParameters, null );
}

// method to show sidebar
function showSidebarNow( gSide, gPage, gParameters, gWidth )
{
	// check if we have simple sidebars
	if( gPage == "sidebar" && gSide != null )
	{
		// remove old content
		jQuery( ".neo-sidebar-content" ).html( "" );
		
		// set arrangement
		jQuery( "#sidebar" ).removeClass( gSide == "left" ? "right" : "left" );
		jQuery( "#sidebar" ).addClass( gSide );
		
		// set new content
		jQuery( ".neo-sidebar-content" ).html( jQuery( "#neo-sidebar-hidden-content-" + gSide ).html() );
		
		// animate		
		if( gWidth == null )
		{
			jQuery( ".neo-sidebar" ).show().css( {'width':'200%' , 'opacity':'0'} ).animate({ 'width':'100%' , 'opacity':'1' }, 300);
			jQuery( ".neo-sidebar-content" ).css( { marginRight:-300, opacity:0 } ).show().animate({ marginRight: 0, width: 300, opacity:1 }, "fast");
		}
		else 
		{
			jQuery( ".neo-sidebar" ).show().css( "width","0" ).animate({ width: gWidth }, 300);
			jQuery( ".neo-sidebar-content" ).css( "width","0" ).animate({ width: gWidth }, 300);
		}

	}
	else
	{
		// build url
		var sUrl = "php/ajax/" + gPage + ".ajax.php?t=" + Date.now() + "&side=" + gSide;
		if( jQuery( "#wp_plugin_dir" ).val() != null && jQuery( "#wp_plugin_dir" ).val().length > 0 )
		{
			// get new url
			sUrl = jQuery( "#wp_plugin_dir" ).val() + "/ajax/" + gPage + ".ajax.php?t=" + Date.now() + "&side=" + gSide;
		}
		
		// if parameters are set
		if( gParameters != null )
		{
			// for all properties
			for( var property in gParameters ) 
			{
				// check for won property
			    if( gParameters.hasOwnProperty( property ) ) 
			    {
			        // do stuff
			    	sUrl += "&" + property + "=" + gParameters[ property ];
			    }
			}
		}
		
		// load content
		jQuery( ".neo-sidebar-content" ).load
		( 
			sUrl, 
			function( text, status, xhr ) 
			{
				// add class
				jQuery( "#sidebar" ).removeClass( gSide == "left" ? "right" : "left" );
				jQuery( "#sidebar" ).addClass( gSide );
				
				// show layer
				jQuery( ".neo-sidebar" ).show();
				
				// animate
				jQuery( ".neo-sidebar-content" ).animate
				(
					{
						width: 300
					}, "fast"
				);
			}
		);
	}
}

//method to show sidebar
function hideSidebar()
{
	// show layer
	jQuery( ".neo-sidebar" ).fadeOut();
	jQuery( ".neo-sidebar-content" ).width( 0 );
}

//method to show next content
function loadParameters( gTarget, page, parameters, gWaitingMessageMenu, gWaitingMessageContent, gCallback )
{
	// check if individual ajax preparation exists
	if( typeof _ajax == "function" )
	{
		// call me
		_ajax();
	}
	
	// first, remove all layers
	jQuery( ".neo-layer" ).hide();
	
	// hide footer
	if( gTarget == "#content" ) 
	{
		// hide footer while loading
		jQuery( "#global_page_footer" ).hide();
	}
	
	// check if we have ticketvoucher
	var nTvo = null;
	if( jQuery( "INPUT#tvo" ).length > 0 && jQuery( "INPUT#tvo" ).val() != null )
	{
		// append
		nTvo = jQuery( "#tvo" ).val();
	}
	
	// paste in the content
	if( gWaitingMessageMenu != null && gWaitingMessageContent != null ) 
	{
		// scrolltop
		scrollContentTop();
		
		// show message
		jQuery( gTarget ).html( "<div class=\"row\"><div class=\"col\" style=\"padding: 0 0 80px 0; height: " + jQuery( gTarget ).height() + "px; text-align: center; color: white;\"><h1 class=\"bold colored ajax mar-0\">" + gWaitingMessageMenu + "</h1><h3 class=\"ajax\">" + gWaitingMessageContent + "</h3><div style='margin: auto;' class=\"" + jQuery( "#indicator_32_leaf" ).attr( "class" ) + "\"></div></div></div>" );
	}
	else
	{
		// empty target
		jQuery( gTarget ).html( "" );
	}
	
	// build url
	var sUrl = "php/ajax/" + page + ".ajax.php?t=" + Date.now();
	if( jQuery( "#wp_plugin_dir" ).val() != null && jQuery( "#wp_plugin_dir" ).val().length > 0 )
	{
		// get new url
		sUrl = jQuery( "#wp_plugin_dir" ).val() + "/ajax/" + page + ".ajax.php?t=" + Date.now();
	}
	
	// if tvo exists
	if( nTvo != null )
	{
		// append
		sUrl += "&tvo=" + encodeURI( nTvo );
	}
	
	// console
	console.log( sUrl );
	
	// if parameters are set
	if( parameters != null )
	{
		// for all properties
		for( var property in parameters ) 
		{
		    if( parameters.hasOwnProperty( property ) ) 
		    {
		        // do stuff
		    	sUrl += "&" + property + "=" + parameters[ property ];
		    }
		}
	}
	
	// load content
	jQuery( gTarget ).load
	( 
		sUrl, 
		function( text, status, xhr ) 
		{
			// show global footer
			jQuery( "#global_page_footer" ).show();
			
			// show new content
			var sFooterElement = jQuery( gTarget ).find( ".neo-footer" );
			if( sFooterElement.size() == 1 )
			{
				// check if we have a content
				if( sFooterElement.html() != null && sFooterElement.html().length > 0 )
				{
					// set content and show
					jQuery( "body" ).css( "margin-bottom", "60px" );
					jQuery( "#neo-footer" ).html( sFooterElement.html() );
					jQuery( "#neo-footer" ).show
					(
						100,
						function()
						{
							// arrange it
							arrange( null, "load" )
						}
					);
				}
				else
				{
					// set content and show
					jQuery( "body" ).css( "margin-bottom", "0" );
					jQuery( "#neo-footer" ).html( "" );
					jQuery( "#neo-footer" ).hide
					(
						100,
						function()
						{
							// arrange it
							arrange( null, "load" )
						}
					);
				}
			}
			
			// show new content
			var sCustomerHiddenSidebarElement = jQuery( gTarget ).find( "#neo-sidebar-hidden-content-right-updated" );
			if( sCustomerHiddenSidebarElement.size() == 1 && sCustomerHiddenSidebarElement.html() != null && sCustomerHiddenSidebarElement.html().length > 0 )
			{
				// set content and show
				jQuery( "#neo-sidebar-hidden-content-right" ).html( sCustomerHiddenSidebarElement.html() );
			}
			
			// make it asynchrone
			setTimeout( initMasonry, 0 );
			
			// check qr codes
			checkQrCodes();
			
			// set height by ratio
			setHeightByRatio();
			
			// show mandatory errors if exists
			showMandatories( jQuery( "<div/>" ).html( text ) );
			
			// add drop event to loader
			checkUpload();
			
			// check paypal
			checkPayPal();
			
			// if callback was set
			if( gCallback != null ) 
			{
				// fire callback function
				gCallback();
			}
		}
	);
} 

//method to show layer
function showPopUpLoadParameters( gPage, gParameters, gWaitingMessageMenu, gWaitingMessageContent, gCallback )
{
	// check if individual ajax preparation exists
	if( typeof _ajax == "function" )
	{
		// call me
		_ajax();
	}
	
	// show new content
	jQuery( ".neo-popup-menu" ).html( "" );
	
	// paste in the content
	jQuery( ".neo-popup-content" ).html( "<div class=\"row\"><div class=\"col\" style=\"padding: 50px; text-align: center; color: white;\"><h1 class=\"bold colored ajax mar-0\">" + gWaitingMessageMenu + "</h1><h3 class=\"ajax\">" + gWaitingMessageContent + "</h3><div style='margin: auto;' class=\"" + jQuery( "#indicator_32_leaf" ).attr( "class" ) + "\"></div></div></div>" );
	
	// show new content
	jQuery( ".neo-popup-footer" ).html( "" );
	
	// first, show layer
	jQuery( ".neo-popup" ).fadeIn
	( 
		300,
		function()
		{
			// disable temporarly scrollbar in body
			jQuery( ".content" ).css( "display", "none" );
			
			// var menu load content
			var sTempContentElement = jQuery( "<div />" );
			
			// check if we have an individual wordpress plugin path
			var sUrl = "php/ajax/" + gPage + ".ajax.php?t=" + Date.now();
			if( jQuery( "#wp_plugin_dir" ).val() != null && jQuery( "#wp_plugin_dir" ).val().length > 0 )
			{
				// get new url
				sUrl = jQuery( "#wp_plugin_dir" ).val() + "/ajax/" + gPage + ".ajax.php?t=" + Date.now();
			}
			
			// if parameters are set
			if( gParameters != null )
			{
				// for all properties
				for( var property in gParameters ) 
				{
					// check for won property
				    if( gParameters.hasOwnProperty( property ) ) 
				    {
				        // do stuff
				    	sUrl += "&" + property + "=" + gParameters[ property ];
				    }
				}
			}
			
			// load content
			sTempContentElement.load
			( 
				sUrl, 
				function( text, status, xhr ) 
				{
					// debug
					// alert( "Load was performed ( url: " + sUrl + ", " + text + ", " + status + ", " + xhr );
					
					// show new content
					jQuery( ".neo-popup-menu" ).html( sTempContentElement.find( ".neo-popup-menu" ).html() );
					
					// paste in the content
					jQuery( ".neo-popup-content" ).html( sTempContentElement.html() );
					
					// show new content
					jQuery( ".neo-popup-footer" ).html( sTempContentElement.find( ".neo-popup-footer" ).html() );
					
					// check for displaying qr codes
					checkQrCodes();
					
					// set height by ratio
					setHeightByRatio();
					
					// check paypal
					checkPayPal();
					
					// if callback exists
					if( gCallback != null )
					{
						// fire it
						gCallback();
					}
					
					// make it asynchrone
					setTimeout( initMasonry, 0 );
				}
			);
		}
	);
}

//method to show layer
function postPopUpLoadParameters( gForm, gPage, gWaitingMessageMenu, gWaitingMessageContent, gCallback )
{
	// check if individual ajax preparation exists
	if( typeof _ajax == "function" )
	{
		// call me
		_ajax();
	}
	
	// get serialized form data
	var sFormLoadSerialized = jQuery( gForm ).serialize();
	
	// show new content
	jQuery( ".neo-popup-menu" ).html( "" );
	
	// paste in the content
	jQuery( ".neo-popup-content" ).html( "<div class=\"row\"><div class=\"col\" style=\"padding: 50px; text-align: center; color: white;\"><h1 class=\"bold colored ajax mar-0\">" + gWaitingMessageMenu + "</h1><h3 class=\"ajax\">" + gWaitingMessageContent + "</h3><div style='margin: auto;' class=\"" + jQuery( "#indicator_32_leaf" ).attr( "class" ) + "\"></div></div></div>" );
	
	// show new content
	jQuery( ".neo-popup-footer" ).html( "" );
	
	// first, show layer
	jQuery( ".neo-popup" ).fadeIn
	( 
		300,
		function()
		{
			// disable temporarly scrollbar in body
			jQuery( ".content" ).css( "display", "none" );
			
			// build url
			var sUrl = "php/ajax/" + gPage + ".ajax.php?t=" + Date.now();
			if( jQuery( "#wp_plugin_dir" ).val() != null && jQuery( "#wp_plugin_dir" ).val().length > 0 )
			{
				// get new url
				sUrl = jQuery( "#wp_plugin_dir" ).val() + "/ajax/" + gPage + ".ajax.php?t=" + Date.now();
			}
			
			//this is the id of the form
			jQuery.ajax
		    (
	    		{
	    			type: "POST",
	    			url: sUrl,
	    			data: sFormLoadSerialized, 
	    			success: function( data )
	    			{
	    				// debug
						// alert( "Load was performed ( url: " + sUrl + ", data: " + data );
						
						// show new content
						jQuery( ".neo-popup-menu" ).html( jQuery( data ).find( ".neo-popup-menu" ).html() );
						
						// paste in the content
						jQuery( ".neo-popup-content" ).html( data );
						
						// show new content
						jQuery( ".neo-popup-footer" ).html( jQuery( data ).find( ".neo-popup-footer" ).html() );
						
						// make it asynchrone
						setTimeout( initMasonry, 0 );
						
						// check qr code
						checkQrCodes();
						
						// set height by ratio
						setHeightByRatio();
						
						// show mandatory errors if exists
						showMandatories( jQuery( data ) );
						
						// add drop event to loader
						checkUpload();
						
						// check paypal
						checkPayPal();
						
						// if callback exists
						if( gCallback != null )
						{
							// fire it
							gCallback();
						}
	    			}
	    		}
    		);
		}
	);
}

//method to show layer
function postLoadParameters( gForm, gTarget, gPage, gWaitingMessageMenu, gWaitingMessageContent, gCallback )
{
	// check if individual ajax preparation exists
	if( typeof _ajax == "function" )
	{
		// call me
		_ajax();
	}
	
	// hide footer
	if( gTarget == "#content" ) 
	{
		// hide footer while loading
		jQuery( "#global_page_footer" ).hide();
	}
	
	// get serialized form data
	var sFormLoadSerialized = jQuery( gForm ).serialize();
	
	// scrolltop
	scrollContentTop();
	
	// paste in the content
	jQuery( gTarget ).html( "<div class=\"row\"><div class=\"col\" style=\"padding: 50px; height: " + jQuery( gTarget ).height() + "px; text-align: center; color: white;\"><h1 class=\"bold colored ajax mar-0\">" + gWaitingMessageMenu + "</h1><h3 class=\"ajax\">" + gWaitingMessageContent + "</h3><div style='margin: auto;' class=\"" + jQuery( "#indicator_32_leaf" ).attr( "class" ) + "\"></div></div></div>" );
	
	// build url
	var sUrl = "php/ajax/" + gPage + ".ajax.php?t=" + Date.now();
	if( jQuery( "#wp_plugin_dir" ).val() != null && jQuery( "#wp_plugin_dir" ).val().length > 0 )
	{
		// get new url
		sUrl = jQuery( "#wp_plugin_dir" ).val() + "/ajax/" + gPage + ".ajax.php?t=" + Date.now();
	}
	
	//this is the id of the form
	jQuery.ajax
    (
		{
			type: "POST",
			url: sUrl,
			data: sFormLoadSerialized, 
			success: function( data )
			{
				// show footer
				jQuery( "#global_page_footer" ).show();
				
				// paste in the content
				jQuery( gTarget ).html( data );
				
				// show new content
				var sFooterElement = jQuery( gTarget ).find( ".neo-footer" );
				if( sFooterElement.size() == 1 )
				{
					// check if we have a content
					if( sFooterElement.html() != null && sFooterElement.html().length > 0 )
					{
						// set content and show
						jQuery( "#neo-footer" ).html( sFooterElement.html() );
						jQuery( "#neo-footer" ).show
						(
							100,
							function()
							{
								// arrange it
								arrange( null, "load" )
							}
						);
					}
					else
					{
						// set content and show
						jQuery( "#neo-footer" ).html( "" );
						jQuery( "#neo-footer" ).hide
						(
							100,
							function()
							{
								// arrange it
								arrange( null, "load" )
							}
						);
					}
				}
				
				// show new content
				var sCustomerHiddenSidebarElement = jQuery( gTarget ).find( "#neo-sidebar-hidden-content-right-updated" );
				if( sCustomerHiddenSidebarElement.size() == 1 && sCustomerHiddenSidebarElement.html() != null && sCustomerHiddenSidebarElement.html().length > 0 )
				{
					// set content and show
					jQuery( "#neo-sidebar-hidden-content-right" ).html( sCustomerHiddenSidebarElement.html() );
				}
				
				// check qr codes
				checkQrCodes();
				
				// set height by ratio
				setHeightByRatio();
				
				// make it asynchrone
				setTimeout( initMasonry, 0 );
				
				// show mandatory errors if exists
				showMandatories( jQuery( data ) );
				
				// add drop event to loader
				checkUpload();
				
				// check paypal
				checkPayPal();
				
				// if callback exists
				if( gCallback != null )
				{
					// fire it
					gCallback();
				}
			}, 
			error: function( err )
			{
				// show message
				console.log( "Neo App, INFO, postLoadParameters, error occured: " + JSON.stringify( err, null, 4 ) );
			}
		}
	);
}

//show window
function doFacebookCallback( source, gUrl, gWaitingMessageMenu, gWaitingMessageContent )
{
	// hide member sidebar
	hideSidebar();
	
	// make it asynchrone
	setTimeout
	( 
		function()
		{
			// check if we have a direct redirect instruction
			var rInstruction = jQuery( "div[data-neo-hidden-facebook-redirect-instruction]").data( "neo-hidden-facebook-redirect-instruction" );
			
			// if instrcution was set and exiasts
			if( rInstruction != null && rInstruction.length > 0 )
			{
				// set source
				source = rInstruction;
			}
			
			// switch for source
			if( source == "reservation.login.default" )
			{
				// show popup
				showPopUpLoadParameters( "reservation.login", { doAction: 'loginFacebook', login_type: 'default' }, gWaitingMessageMenu, gWaitingMessageContent, null );
			}
			else if( source == "reservation.login.registration" )
			{
				// show popup
				showPopUpLoadParameters( "reservation.login", { doAction: 'loginFacebook', login_type: 'registration' }, gWaitingMessageMenu, gWaitingMessageContent, null );
			}
			else if( source == "basket.login.default" )
			{
				// show popup
				showPopUpLoadParameters( "basket.login", { doAction: 'loginFacebook', login_type: 'default' }, gWaitingMessageMenu, gWaitingMessageContent, null );
			}
			else if( source == "basket.login.registration" )
			{
				// show popup
				showPopUpLoadParameters( "basket.login", { doAction: 'loginFacebook', login_type: 'registration' }, gWaitingMessageMenu, gWaitingMessageContent, null );
			}
			else if( source == "reservation.login.default.page" )
			{
				// show popup
				loadParameters( "#content", "reservation.login", { doAction: 'loginFacebook', login_type: 'default' }, gWaitingMessageMenu, gWaitingMessageContent, null );
			}
			else if( source == "reservation.login.registration.page" )
			{
				// show popup
				loadParameters( "#content", "reservation.login", { doAction: 'loginFacebook', login_type: 'registration' }, gWaitingMessageMenu, gWaitingMessageContent, null );
			}
			else if( source == "basket.login.default.page" )
			{
				// show popup
				loadParameters( "#content", "basket.login", { doAction: 'loginFacebook', login_type: 'default' }, gWaitingMessageMenu, gWaitingMessageContent, null );
			}
			else if( source == "basket.login.registration.page" )
			{
				// show popup
				loadParameters( "#content", "basket.login", { doAction: 'loginFacebook', login_type: 'registration' }, gWaitingMessageMenu, gWaitingMessageContent, null );
			}
			else if( source == "forward" && gUrl != null )
			{
				// paste in the content
				jQuery( "#content" ).html( "<div class=\"row\"><div class=\"col\" style=\"padding: 50px; text-align: center; color: white;\"><h1 class=\"bold colored mar-0\">" + gWaitingMessageMenu + "</h1><h3>" + gWaitingMessageContent + "</h3><div style='margin: auto;' class=\"" + jQuery( "#indicator_32_leaf" ).attr( "class" ) + "\"></div></div></div>" );
				
				// show url
				document.location.href = gUrl;
			}
			else
			{	
				// show url
				document.location.href = "my-data";
			}
		}, 100 
	);
	
	// return true;
	return true;
}

function showSplash()
{
	jQuery('#splashScreen').fadeIn();
} showSplash();

function hideSplash()
{	
	jQuery('#splashScreen').fadeOut();
	
	setTimeout
	(
		function() 
		{
			jQuery('#splashScreen').remove();
		},500
	);
}

function hideParent()
{
	//don't load excessed blocks
	jQuery('.hide-parent').parent().remove();
} hideParent();
