/*

(C) Copyright 2011 p-share.net

*/

$(function(){

if (document.cookie.length > 0 && document.cookie.indexOf('closedbeta' + '=') != -1) {
            $('#closedbeta').css('display','block');
    }

	// url

var url = document.location.toString();
	if (url.match('#')) {
    	var anchorurl = url.split('#')[1];
	}
	
	/*if(anchorurl != 'notify') {
		
		window.location = '#';
		
	}*/

	// check anchor

if(anchorurl != 'notify') {
	
	$('#comingsoon').css('display','none');
	$('#notify_me').css('display','none');
	$('#comingsoon').delay(500).fadeIn(1000);
	$('#notify_me').show("slide", 500);
	$('#notify_done').show("slide", 500);
	
} else {

	$('#comingsoon').css('display','none');
	$('#notify_me').css('display','none');
	
}
	
	
	// trick no-js browsers
	
	$('#notify_me').html('<span id="notify_text">Notify me on release date!</span>');
	
	
	// open notify panel
	
	$('#notify_me').click(function(){
        
        window.location = '#notify';
        
        $('#comingsoon').hide("slide", 500);
        $('#notify_done').hide("slide", 500);
        $('#notify_me').hide("slide", 500);
        $('#notify_error').css('display','none');
        
        setTimeout(function() { 
			$('#notify').show("slide", 500);
			$('#notify_title').show("slide", 500);
			 $('#cancel').delay(500).fadeIn(500);
		}, 800);
		
		setTimeout(function() { 
			$('#form_input').focus();
		}, 1000);
        
       /* $('#comingsoon').fadeOut(400);
        $('#notify_me').delay(200).fadeOut(200);
        $('#notify').delay(401).fadeIn(500);
        $('#cancel').delay(900).fadeIn(200);
        $('#notify_error').css('display','none');
        $('#notify_title').css('display','block');*/
        
        
        });
        
        
        // submit email
        
	$('#form_submit').click(function(){
        
		var notify_mail = $('#form_input').val();
		var error = false;


		if(notify_mail.length == 0 || notify_mail.indexOf('@') == '-1' || notify_mail.indexOf('.') == '-1'){
			
			var error = true; // error email format

			setTimeout(function() { 
			$('#notify_error').addClass('visible');
			}, 300);
			
			if ($('#notify_error').hasClass("visible")) {
				
				$('#notify_error').effect('bounce', { times:3 }, 150);
				
			} else {
			
				$('#notify_error').html('Please enter a valid Email Adress!');
				$('#notify_title').fadeOut(300);
				$('#notify_error').delay(300).fadeIn(300);
			
			}
                
		}
		
	
	// email format ok - save email
	
	if(error == false){
    
    	$.post("/save_email.php", $("#notify_data").serialize(),function(){
    
		$('#notify_form').animate({
		opacity: 0.5,
		}, 200, function() {
	});
    	
    	
    	var theDate = new Date();
		var oneYearLater = new Date( theDate.getTime() + 31536000000 ); // one year
		var expiryDate = oneYearLater.toGMTString();
		document.cookie = "psharenotifyme" + "=1; expires="+expiryDate+"";
    	
    	
    	$('#notify_error').removeClass('visible');
    	$('#form_submit').css('background', '#9EC984');
    	$('#form_submit').css('border', '#9EC984 1px solid');
    	$('#form_submit').css('cursor', 'default');
    	$('#form_submit').attr('disabled', 'disabled');
    	$('#form_input').attr('disabled', 'disabled');
    
        $('#notify_error').fadeOut(300);
		$('#notify_title').delay(301).fadeIn(300);
        
        $('#cancel').delay(200).fadeOut(200);
        $('#notify_subtext').fadeOut(250);
		$('#notify_loader').delay(251).fadeIn(200);
		
		$('#notify_loader').delay(1600).fadeOut(290);
		$('#notify').delay(2500).fadeOut(400);
		
		$('#notify_complete').delay(3000).fadeIn(900).delay(4000).fadeOut(900);
		
		$('#comingsoon').delay(10000).fadeIn(1200);
		$('#notify_done_finished').delay(10500).fadeIn(500);
		
		window.setTimeout("window.location = '#';",9000);
		
				});
		
		     }      
		
		});  
	
	
	// cancel
	
		$('#cancel').click(function(){
        
        window.location = '#';
        
         if (!$('#notify_error').hasClass("visible")) {
			$('#notify_title').hide("slide", 800);
		}
		
		if ($('#notify_error').hasClass("visible")) {
			$('#notify_error').hide("slide", 800);
		}
        
        $('#notify_error').removeClass('visible');
        
        
        $('#notify').hide("slide", 800);
		$('#cancel').delay(500).fadeOut(500);
        
        setTimeout(function() { 
			$('#comingsoon').delay(500).fadeIn(1000);
       		$('#notify_done').show("slide", 800);
        	$('#notify_me').show("slide", 800);
        	$('#notify_error').css('display','none');
		}, 800);
		
        

        
        
        });
        
        
        // anchor
	
	if(anchorurl == 'notify') {
	
        $('#notify').show("slide", 500);
        $('#cancel').show("slide", 500);
        $('#notify_error').css('display','none');
        $('#notify_title').css('display','block');
		
	}
     
     
		// return
		
	$("form input").keypress(function (enter) {  
        if ((enter.which && enter.which == 13) || (enter.keyCode && enter.keyCode == 13)) {  
            $('#form_submit').click();
        
            return false;
        }
    });  

});
