$("document").ready(function() {
	//$("body").css("display", "none");
	//$("body").fadeIn(200);


				

	
	

	$("#register_a").click(function() {
		$(this).animate({ left: "-260px", opacity: "0" }, {duration: 500, specialEasing: { width: 'easeInBounce', height: 'easeInBounce'}});
		$("#register_b").animate({ left: "20px", opacity: "1"}, {duration: 500, specialEasing: { width: 'easeInBounce', height: 'easeInBounce'}});
	});
	var loginbar = false;
	$('#login_off').click(function() {
		$('#login_bar_off').animate({ marginTop: '50px'}, 400 );
		$('#login_off').animate({ top: '-30px' }, 200 );
		/*$('#login_on').animate({ top: '0px' }, 200 );*/
		$("#header_cont").css({ opacity: "1" }, {duration: 100});
		$("#logged_options").animate({ right: '80px' }, 200 );
		loginbar = true;
	}); 
	$('#login_on').click(function() {
		$('#login_bar_off').animate({marginTop: '-400px'}, 400 );
		$('#login_off').animate({top: '0px'}, 200 );
		$('#login_on').animate({top: '30px'}, 200 );
		$("#logged_options").animate({ right: '150px' }, 200 );
		loginbar = false;
	});  
    $(window).scroll(function () {
	 	if ($(this).scrollTop() == 0 || loginbar) {
	 		$("#header_cont").css({ opacity: "1" }, {duration: 100});
	 	} else {
      		$("#header_cont").css({ opacity: "0.80" }, {duration: 100});
	  	}
	});
	
    $(".register_header").click( function () {
		$("#register_header_a").animate({ top: '53px' }, 200 ).delay(20000).animate({ top: '0px' }, 200 );
		$("#register_header_b").animate({ top: '-53px' }, 200 ).delay(20000).animate({ top: '0px' }, 200 );
		$(".register_header_text_a").animate({ top: '-90px' }, 200 ).delay(20000).animate({ top: '0px' }, 200 );
		$(".register_header_text_b").animate({ top: '-87px' }, 200 ).delay(20000).animate({ top: '0px' }, 200 );
	});
    
	$(".forgotto").click( function () {
		$(".login2").animate({ left: '0px' }, 200 );
		$(".login1").animate({ left: '-320px' }, 200 );
	});
	$(".forgotto_back").click( function () {
		$(".login1").animate({ left: '0px' }, 200 );
		$(".login2").animate({ left: '300px' }, 200 );
	});
	
	$("#sketch_big").hover( function () {
		$(".click_vote").animate({ opacity: '1' }, 200 );
	});
	$("#sketch_big").mouseleave( function () {
		$(".click_vote").animate({ opacity: '0' }, 200 );
	});
	$(".click_vote").click( function () {
		$(this).css("display", "none");
		$("#score_circle_big").css("backgroundColor", "#D74C30");
	});
	
	$("#sketch_big").hover( function () {
      $("#score_circle_big").animate({ opacity: '1' }, 100 );
      $("#socials").animate({ opacity: '1' }, 100 );
      $("#preorder_circle_big").animate({ opacity: '1' }, 100 );
     });
    $("#sketch_big").mouseleave( function () {
    	$("#score_circle_big").animate({ opacity: '0.5' }, 100 );
    	$("#socials").animate({ opacity: '0' }, 100 );
    	$("#preorder_circle_big").animate({ opacity: '0.5' }, 100 );
    });

	
	
	$(".more_butt").click( function () {
		$("#user_about").css( "height", "100%");
		$(".more_butt").css("display", "none");
		$(".more_butt2").css("display", "inline-block");
	});
	$(".more_butt2").click( function () {
		$("#user_about").css( "height", "150px");
		$(".more_butt2").css("display", "none");
		$(".more_butt").css("display", "inline-block");
	});
	
	
	$(".filter_button").click( function () {
		$(this).addClass("filter_button_active");
		$(this).removeClass("filter_button");
	});	

	$(".thumb").hover(
		function () {
		   $(this).animate({opacity: "0.50"}, {duration: 100});
	       }, 
 		 function () {
		$(this).animate({opacity: "1"}, {duration: 100});
		});

	$(".sketch").hover(
		function () {
			$(".button_quick_vote").animate({opacity: "1"}, {duration: 100});
			}, 
		function () {
			$(".button_quick_vote").animate({opacity: "0"}, {duration: 100});
	  }
	);

    $('.shop_menu').bind('mousemove', function(e){
	    $('.coming_soon').css({
	       left:  e.pageX,
	       top:   e.pageY,
	       opacity: 0.8
	    });
	});
	$('.shop_menu').bind('mouseleave', function(e){
	    $('.coming_soon').css({
	       left:  e.pageX,
	       top:   e.pageY,
	       opacity: 0
	    });
	});

	$("#user_avatar").hover( function () {
		$(".upload_avatar_button").animate({ opacity: '1' }, 100 );
	});
	$("#user_avatar").mouseleave( function () {
		$(".upload_avatar_button").animate({ opacity: '0' }, 100 );
	});
    
    
    // FEEDBACK

	var feedbackss = false;
    $('#feedback h6').click(function() {
        feedbackss = !feedbackss;
        if(feedbackss) {
            $('#feedback').animate({right: "300px"}, {duration: 300});
        }
        $('#feedback h6').click(function() {
            if(!feedbackss) {
                $('#feedback').animate({right: "0px"}, {duration: 300});
            }
        });
    });
    
	// The relative URL of the submit.php script.
	// You will probably have to change	it.
	var submitURL = '/ajax/feedback_submit.php';

	// Caching the feedback object:	
	var feedback = $('#feedback');

	// Caching the feedback object:	

	
	$('#feedback a.submit').live('click',function(){
		var button = $(this);
		var textarea = feedback.find('textarea');
		
		// We use the working class not only for styling the submit button,
		// but also as kind of a "lock" to prevent multiple submissions.
		
		if(button.hasClass('working') || textarea.val().length < 5){
			return false;
		}

		// Locking the form and changing the button style:
		button.addClass('working');
		
		
		$.ajax({
			url		: submitURL,
			type	: 'post',
			data	: { message : textarea.val()},
			complete	: function(xhr){
				
				var text = xhr.responseText;
				
				// This will help users troubleshoot their form:
				if(xhr.status == 404){
					text = 'Your path to feedback_submit.php is incorrect.';
				}

				// Hiding the button and the textarea, after which
				// we are showing the received response from submit.php
				button.fadeOut();
				
				textarea.fadeOut(function(){
					var span = $('<span>',{
						className	: 'response',
						html		: text
					})
					.hide()
					.appendTo(feedback.find('.section'))
					.show();
				}).val('');
			}
		});
		
		return false;
	});
	// FEEDBACK end
    
    //Richiesta i_code
   
    $("#show_icode_form").click( function () {
		var toshow    = $("#toshow_icode").val();
        if(parseInt(toshow) == 0){
            $("#icode").css("display", "inline-block");
            $("#toshow_icode").val("1");   
        }
        else{
            $("#icode").css("display", "none");
            $("#toshow_icode").val("0");
        }
        
	});
   
    
    //Trigger Upload avatar
    $("#phantom_upload").click(function(event){
        $("#avatar").click();
    });

    //Trigger Upload Sketch 1
    $("#btn_sketch1").click(function(event){
        $("#app1").click();
    });
    $("#sketch_1").click(function(event){
        $("#app1").click();
    });
    
    //Trigger Upload Sketch 2
    $("#btn_sketch2").click(function(event){
        $("#app2").click();
    });
    $("#sketch_2").click(function(event){
        $("#app2").click();
    });
    
    //Trigger Upload Sketch 3
    $("#btn_sketch3").click(function(event){
        $("#app3").click();
    });
    $("#sketch_3").click(function(event){
        $("#app3").click();
    });
    
    //Private MEssages
    $("#btn_pm").click(function(event){
        $("#pm_text").toggle(200);
    });
});
