var dropDown = function(id){
	var $thisZona = id;
	$("#" + $thisZona).slideToggle(500, 'easeOutBounce');
};

var setValueZona = function(value){
	$('html, body').animate({scrollTop: '600px'}, 300);
	$("#i-zona").highlightFade({color:'#7193c6',speed:1200,iterator:'exponential'});
	$("#i-zona").val(value);
	return false;
};

var ajaxRequest = function(){
	// get params
	var zona = $("#i-zona").val();
	var suprafata = $("#i-suprafata").val();
	var nume = $("#i-nume").val();
	var email = $("#i-email").val();
	var capcha = $("#i-capcha").val();
	
	$.ajax({
		type: "post",
		url: "request.php",
		dataType: "text",
		data: "zona=" + zona +"&suprafata="+ suprafata + "&nume=" + nume + "&email=" + email + "&capcha=" + capcha,
		success: function(response){
			var thisResponse = response;
			thisResponse = thisResponse.split("@@!");
			if(thisResponse[0] == 'error'){
				alert(thisResponse[1]);
			}else if(thisResponse[0] == 'OK'){
				redirectLink = thisResponse[1] + ".html";
				window.location = redirectLink;
			}
		},error: function(){
			alert("Error occured during Ajax request...");
		}
	});

};

$(document).ready(function() {

	//test
	//spaceship // top: 88px;
	$("#spaceship").css('opacity', 0).css('width', '0%').css('height', '0%');
	$("#spaceship").animate({ 
        width: "230px",
        height: "312",
        opacity: 1
      }, 1200, 'easeOutElastic');

	
	
	// drowdown value change
	$("#dropdown-zona li").click(function(){
		$("#i-zona").highlightFade({color:'#7193c6',speed:1200,iterator:'exponential'});
		$("#i-zona").val($(this).text());
		$("#dropdown-zona").slideToggle(300);
		return false;
	});
	$("#dropdown-suprafata li").click(function(){
		$("#i-suprafata").highlightFade({color:'#7193c6',speed:1200,iterator:'exponential'});
		$("#i-suprafata").val($(this).text());
		$("#dropdown-suprafata").slideToggle(300);
		return false;
	});

	
	$("#trimiteFormular").click(function(){
		ajaxRequest();
		return false;
	});
	
	// "Planeta" very custom script
	$(".ora-2").css('opacity', 0);
	$(".ora-5").css('opacity', 0);
	$(".ora-10").css('opacity', 0);
	$(".ora-12").css('opacity', 0);
	$(".ora-8").css('opacity', 0);
	$(".ora-9").css('opacity', 0);
	$(".ora-3").css('opacity', 0);
	
    $(".planeta .oraBtn").bind("mouseenter",function(){
		var thisNr = $(this).attr('id');
		var nr = thisNr.split('-');
		nr = nr[1];

		if(nr == 2){
			$(".ora-" +nr).animate({
			   	height: '230px',
			   	top: '-78px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}else if(nr == '8'){
			$(".ora-" + nr).animate({
			   	width: '240px',
			   	left: '155px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}else if(nr == '10'){
			$(".ora-" + nr).animate({
			   	height: '240px',
			   	top: '5px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}else if(nr == '12'){
			$(".ora-" + nr).animate({
			   	height: '230px',
			   	top: '-4px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}else if(nr == '9'){
			$(".ora-" + nr).animate({
			   	height: '230px',
			   	top: '103px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}else if(nr == '3'){
			$(".ora-" + nr).animate({
			   	height: '220px',
			   	top: '100px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}else if(nr == '5'){
			$(".ora-" + nr).animate({
			   	height: '159px',
			   	top: '375px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}else if(nr == '6'){
			$(".ora-" + nr).animate({
			   	height: '220px',
			   	top: '414px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}

    }).bind("mouseleave",function(){
    	var thisNr = $(this).attr('id');
    	var nr = thisNr.split('-');
    	nr = nr[1];
    	
    	if(nr == '2'){
	    	$(".ora-" + nr).animate({
	    	   	height: '0px',
	    	   	top: '134px',
	    	   	opacity: 0
	        }, 200);
    	}else if(nr == '8'){
    		$(".ora-" + nr).animate({
	    	   	width: '0px',
	    	   	left: '388px',
	    	   	opacity: 0
	        }, 200);
        }else if(nr == '10'){
    		$(".ora-" + nr).animate({
	    	   	height: '0px',
	    	   	top: '197px',
	    	   	opacity: 0
	        }, 200);
        }else if(nr == '12'){
    		$(".ora-" + nr).animate({
	    	   	height: '0px',
	    	   	top: '197px',
	    	   	opacity: 0
	        }, 200);
        }else if(nr == '9'){
    		$(".ora-" + nr).animate({
	    	   	height: '0px',
	    	   	top: '315px',
	    	   	opacity: 0
	        }, 200);
        }else if(nr == '3'){
    		$(".ora-" + nr).animate({
	    	   	height: '0px',
	    	   	top: '313px',
	    	   	opacity: 0
	        }, 200);
        }else if(nr == '5'){
    		$(".ora-" + nr).animate({
	    	   	height: '0px',
			   	top: '535px',
	    	   	opacity: 0
	        }, 200);
        }else if(nr == '6'){
			$(".ora-" + nr).animate({
			   	height: '0px',
			   	top: '642px',
			   	opacity: 1
		    }, {duration: 400, easing: 'easeOutBack'});
		}
    });
    
    $("#butonSubmit").css('opacity', 0.7);
    $("#butonSubmit").bind("mouseenter",function(){
    	$(this).animate({
    		opacity: 1
    	}, 200);
    	
    }).bind("mouseleave",function(){
    	$(this).animate({
    		opacity: 0.7
    	}, 200);
    });
});	 