$(function(){

	//
	var menuContainer	= $('.footerContent .bottomMenu_01');
	var slideCurve		= $('.footerBgShadow .Curve');
	var menuLink		= $('.footerContent .bottomMenu_01 a');

	//
	menuLink.mouseenter(function() {
		if ( menuContainer.find('#Active').length == 0 ) {
			var thisLeftPos	= $(this).offset().left;
			var thisCenter	= $(this).width() / 2;
			var curveCenter	= slideCurve.width() / 2;
			var contentPos	= menuContainer.offset().left;
			var curvePos	= Math.round( (thisLeftPos + thisCenter - curveCenter) - contentPos );

			slideCurve.promise().done(function() {
				slideCurve.animate( {marginLeft: curvePos + 'px'}, {queue: false, duration: 350} );
			});
		}
	});

	//
	menuContainer.mouseleave(function() {
		if ( menuContainer.find('#Active').length == 0 ) {
			slideCurve.promise().done(function() {
				slideCurve.animate( {marginLeft: '0px'}, {queue: false, duration: 350} );
			});
		}
	});

	//
	menuLink.click(function() {
		var thisRel = $(this).attr('rel');
		var thisId = $(this).attr('id');

		if ( thisId != 'Disabled' ) {
			if ( thisRel ) {
				var relOptions	= thisRel.replace(/\s+/g, '').split(',');
				var objName		= relOptions[1]; //formXxx
				var objAction	= relOptions[0]; //show

				slideCurve.css( {backgroundPosition: '0% 0%', cursor: 'pointer'} ).attr('id', 'Active');
				menuLink.css( {backgroundPosition: '0% 50%', cursor: 'default'} ).attr('id', 'Disabled');
				$(this).css( {backgroundPosition: '0% 0%'} ).attr('id', 'Active');
				$('.hiddenForm form[name='+objName+']').slideDown(450).attr('id', objAction);
			}
		} else {
			return false;
		}
	});

	//
	slideCurve.click(function() {
		if ( $(this).attr('id') == 'Active' ) {
			$(this).css( {backgroundPosition: '0% 100%', cursor: 'auto'} ).removeAttr('id').animate( {marginLeft: '0px'}, {queue: false, duration: 350} );
			menuLink.css( {backgroundPosition: '0% 100%', cursor: 'pointer'} ).removeAttr('id');

			var findVisible = $('.hiddenForm #show');
			resetForm(findVisible.attr('name'));
			findVisible.slideUp(450).removeAttr('id');
			inputDefault();
		}
	});


	// dla linkow spoza 'bottomMenu_01' --------------------------------------------------------------------------------------------------------------------- //
	//
	getSlideForm = function(_str) {
		if ( menuContainer.find('#Active').length == 0 ) {
			if ( _str == 'formNewsletter' ) { linkClass = 'btn_03'; }
			if ( _str == 'formDodajOpinie' ) { linkClass = 'btn_04'; }

			var findLink	= menuContainer.find('.'+linkClass);
			var linkLeftPos	= findLink.offset().left;
			var linkCenter	= findLink.width() / 2;
			var curveCenter	= slideCurve.width() / 2;
			var contentPos	= menuContainer.offset().left;
			var curvePos	= Math.round( (linkLeftPos + linkCenter - curveCenter) - contentPos );

			slideCurve.css( {backgroundPosition: '0% 0%', cursor: 'pointer'} ).attr('id', 'Active');
			menuLink.css( {backgroundPosition: '0% 50%', cursor: 'default'} ).attr('id', 'Disabled');
			findLink.css( {backgroundPosition: '0% 0%'} ).attr('id', 'Active');

			$.when( scrollHtml() ).done(function() {
				$('.hiddenForm form[name='+_str+']').slideDown(450).attr('id', 'show');
				slideCurve.animate( {marginLeft: curvePos + 'px'}, {queue: false, duration: 350} );

				$('.hiddenForm form[name='+_str+']').promise().done(function() {
					scrollHtml();
				});
			});
		}
	}

	//
	scrollHtml = function() {
		return $('html, body').animate( {scrollTop: $(document).height()+'px'}, {queue: false, duration: 450} );
	}

});
