/* Author: 

*/
$(document).ready(function(){

    $("#emailinput").bind("keydown", function(event) {
      // track enter key
      var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
      if (keycode == 13) { // keycode for enter key
         // force the 'Enter Key' to implicitly click the Update button
         document.getElementById('emailsubmit').click();
         return false;
      } else  {
         return true;
      }
   }); // end of function
    $('#emailsubmit').click(function(){
        var email = "";
        email = $('#emailinput').val();
        $('#emailsubmit, #emailinput').addClass('submitted');
        $.post('/emailme/index.php', $('#ms_emailform').serialize(), function(data) {
        		
            if (data == 0) {
                
                $('#emailsubmit, #emailinput').removeClass('submitted');
                $('#ms_emaildupe').show().delay(2000).fadeOut('slow', function(){
                    $('#emailinput').val('My email address');
                });
                
            } else if (data == 1) {
                
                $('#emailsubmit, #emailinput').removeClass('submitted');
                $('#ms_emailgood').show().delay(2000).fadeOut('slow', function(){
                    $('#emailinput').val('My email address');
                });
                
            } else if (data == "error") {
            
                $('#emailsubmit, #emailinput').removeClass('submitted');
                $('#ms_emailerr').show().delay(2000).fadeOut('slow', function(){
                    $('#emailinput').val('My email address');
                });
            }
        });
        return false;
    });
	$('.user a.dropdown').click(function(e){
		if(!$(this).next().is(':visible')){
			$(this).next().show();
			$(this).css({'background':'url(/img/nav_arrow.png?killcache) bottom right no-repeat'});
		}
		else{
			$(this).next().hide();
			$(this).css({'background':'url(/img/nav_arrow.png?killcache) top right no-repeat'});
		}
		e.preventDefault();
	});
	$('.user a.dropdown').mouseout(function(){
		$(this).next().hide();
		$(this).css({'background':'url(/img/nav_arrow.png?killcache) top right no-repeat'});
	});
	$('#logout').mouseover(function(e){
		$(this).show();
		e.stopPropagation();
		$(this).prev().css({'background':'url(/img/nav_arrow.png?killcache) bottom right no-repeat'});
	});
	$('#logout').mouseout(function(){
		$(this).fadeOut();
		$(this).prev().css({'background':'url(/img/nav_arrow.png?killcache) top right no-repeat'});
	});
	//initialize carrousel states:
	activeTab='invites';
	$('#invites').css({'opacity':'1.0'});
	$('#plan').css({'opacity':'1.0'});
	$('#invites').css({'filter':'alpha(opacity=100)'});
	$('#plan').css({'filter':'alpha(opacity=100)'});
	$('#invites a').click(function(e){
		if(activeTab!='invites'){
		$('#features_box_text_all').animate({'left':'0px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('invites');
			}).fadeIn(200);
		activeTab = 'invites';
		}
		e.preventDefault();
	});
	$('#tickets a').click(function(e){
		if(activeTab!='tickets'){
		$('#features_box_text_all').animate({'left':'-920px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('tickets');
			}).fadeIn(200);
		activeTab = 'tickets';
		}
		e.preventDefault();
	});
	$('#check-in a').click(function(e){
		if(activeTab!='checkin'){
		$('#features_box_text_all').animate({'left':'-1840px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('checkin');
			}).fadeIn(200);
		activeTab = 'checkin';
		}
		e.preventDefault();
	});
	$('#plan a').click(function(e){
		if(activeTab!='plan'){
		$('#features_box_text_all').animate({'left':'0px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('plan');
			}).fadeIn(200);
		activeTab = 'plan';
		}
		e.preventDefault();
	});
	$('#organize a').click(function(e){
		if(activeTab!='organize'){
		$('#features_box_text_all').animate({'left':'-920px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('organize');
			}).fadeIn(200);
		activeTab = 'organize';
		}
		e.preventDefault();
	});
	$('#host a').click(function(e){
		if(activeTab!='host'){
		$('#features_box_text_all').animate({'left':'-1840px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('host');
			}).fadeIn(200);
		activeTab = 'host';
		}
		e.preventDefault();
	});

	$('#f_events a').click(function(e){
		if(activeTab!='invites'){
		$('#features_box_text_all').animate({'left':'0px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('f_events');
			}).fadeIn(200);
		activeTab = 'f_events';
		}
		e.preventDefault();
	});
	$('#f_tickets a').click(function(e){
		if(activeTab!='tickets'){
		$('#features_box_text_all').animate({'left':'-920px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('f_tickets');
			}).fadeIn(200);
		activeTab = 'f_tickets';
		}
		e.preventDefault();
	});
	$('#f_groups a').click(function(e){
		if(activeTab!='checkin'){
		$('#features_box_text_all').animate({'left':'-1840px'},300);
		$('#iphone_holder').fadeOut(200,function(){
				$(this).removeClass();
				$(this).addClass('f_groups');
			}).fadeIn(200);
		activeTab = 'f_groups';
		}
		e.preventDefault();
	});

	$('#features_subnav ul li a').click(function(e){
		$('#features_subnav ul li').css({'opacity':'0.5','filter':'alpha(opacity=50)'});
		$(this).parent().css({'opacity':'1.0'});
		$(this).parent().css({'filter':'alpha(opacity=100)'});
		e.preventDefault();
	});
	function resetScroll() {
		if($(window).width()<=480){
			$('#features_box_text_all').animate({'left':'0px'},300);
		}
	};
	var resizeTimer;
		$(window).resize(function() {
			clearTimeout(resizeTimer);
			resizeTimer = setTimeout(resetScroll, 100);
	});
});




















