$(document).ready(function() {

// toggle slide-down client login
	$('#client_slider_btn').click(function(e) {
		e.preventDefault();
		$(this).children().toggleClass('expanded');
		$("#client_login").slideToggle('fast');
	});

// close May description box
	$('.close_description').click(function() {
		$("#description").fadeTo(100, 0.01, function() {
			$(this).slideUp(200, function() {
				$(this).remove();
			});
		});
	});


	
// block clickable for startups ad
	$('#startup_ad').click(function() {
		window.location="http://mayhq.com/startups/";
		return false;
	});


// form default values, clear on click
	$('.default_value').each(function() {
	    var the_default_value = this.value;
	    $(this).focus(function() {
	        if(this.value == the_default_value) {
	            this.value = '';
	        }
	    });
	    $(this).blur(function() {
	        if(this.value == '') {
	            this.value = the_default_value;
	        }
	    });
	});
	
// jCycle for services page
	$('#services_ss').cycle({
		fx: 'fade',
		speed: 500,
		timeout: 0
	});

	
// Services Sorting Functionality
$('.show_all').click(function() {
  $('#services_nav li.current').removeClass('current');
  $(this).addClass('current');
  $('#services_ss').cycle(0);
  $('#services_ss').cycle('pause');
  $('ul#services li').fadeOut();
  $('ul#services li').fadeIn();
  $('#services_ss').delay(1900).cycle('resume');
});

$('.show_identity').click(function() {
  $('#services_nav li.current').removeClass('current');
  $(this).addClass('current');
  $('#services_ss').cycle(1);
  $('#services_ss').cycle('pause');
  $('ul#services li').fadeOut();
  $('ul#services li.identity').fadeIn();
  $('#services_ss').delay(1900).cycle('resume');
});

$('.show_web').click(function() {
  $('#services_nav li.current').removeClass('current');
  $(this).addClass('current');
  $('#services_ss').cycle(2);
  $('#services_ss').cycle('pause');
  $('ul#services li').fadeOut();
  $('ul#services li.web').fadeIn();
  $('#services_ss').delay(1900).cycle('resume');
});

$('.show_print').click(function() {
  $('#services_nav li.current').removeClass('current');
  $(this).addClass('current');
  $('#services_ss').cycle(3);
  $('#services_ss').cycle('pause');
  $('ul#services li').fadeOut();
  $('ul#services li.print').fadeIn();
  $('#services_ss').delay(1900).cycle('resume');
});

$('.show_mobile').click(function() {
  $('#services_nav li.current').removeClass('current');
  $(this).addClass('current');
  $('#services_ss').cycle(4);
  $('#services_ss').cycle('pause');
  $('ul#services li').fadeOut();
  $('ul#services li.mobile').fadeIn();
  $('#services_ss').delay(1900).cycle('resume');
});

$('.show_social').click(function() {
  $('#services_nav li.current').removeClass('current');
  $(this).addClass('current');
  $('#services_ss').cycle(5);
  $('#services_ss').cycle('pause');
  $('ul#services li').fadeOut();
  $('ul#services li.social').fadeIn();
  $('#services_ss').delay(1900).cycle('resume');
});


	
// jCycle on company page
	$('#company_slideshow').cycle({
		fx: 'scrollHorz',
		speed: 500,
		timeout: 7000,
		next: '#company_ss_next'
	});
	
// company page top tabbing
	$('.tab_content').hide();
	$('#company_about').fadeIn();
    $('#company_intro h1 a').click(function(e) {
		$('#company_intro h1 a').removeClass('current');
		$(this).addClass('current');
		$('.tab_content').hide();

		var activeTab = $(this).attr('href');
		$(activeTab).fadeIn();
		e.preventDefault();

	});
	
// services page tooltips
	$('.services_tooltip').hide();
	$('#services li').hover(
		function() {
			$(this).find('span').stop(true, true).fadeIn();
		},
		function() {
			$(this).find('span').stop(true, true).fadeOut();			
		}
	);

// projects page client list button
	function toggleClientList() {
		$('#client_list').animate({
			height: 'toggle',
			opacity: 'toggle'
		}, 800, 'swing', function() {
			// animation complete
			$('#client_list_button span').toggleClass('expanded');
		});
	}
	

	$('#client_list_button').click(toggleClientList);
	$('#client_list').click(toggleClientList);

// projects page card hovers
	$('.project_detail_card').hide();
	$('#project_cards li').hover(
		function() {
			$(this).find('.project_detail_card').stop(true, true).fadeIn('fast');
		},
		function() {
			$(this).find('.project_detail_card').stop(true, true).fadeOut('fast');
		}
	);


	
// company page photo hovers (using same markup as projects page)
	$('#company_crew ul li').hover(
		function() {
			$(this).find('.profile_detail_card').stop(true, true).fadeIn('fast');
		},
		function() {
			$(this).find('.profile_detail_card').stop(true, true).fadeOut('fast');
		}
	);
	
// projects block click areas
	$('.project_detail_card').click(function() {
		window.location=$(this).find('h3 a').attr('href');
		return false;
	});


// projects filtering
	  $("a#sort_projects").click(function(e) {
		e.preventDefault();
	    $(this).find("span").toggleClass("concealed");
	    $("section#the_projects").toggleClass("active_sorting");
	    $("nav#sort_filter_bar").toggle('normal', function() {});
	  });

	// Reset nav items
	  $("#reset_filters a").click(function() {
	  $(".disabled").removeClass("disabled").removeClass("active_filter").addClass("enabled");
	    resetProjects();
	  });


	  $(".filter_wrapper ul li:not(.reset) a").click(function() { 
	    if ( $(this).parent().hasClass("enabled") && $(this).parent().hasClass("active_filter") ) { 
	      // If enabled & active_filter, remove active_filter and all siblings.
	      $(".filter_wrapper ul li.disabled").removeClass("disabled").addClass("enabled");
	      $(this).parent().removeClass("disabled").removeClass("active_filter");
	      resetProjects();
	    } else if ( $(this).parent().hasClass("disabled") ) {
	      // If disabled, enable & make active_filter while disabling all siblings.
	      $(".filter_wrapper ul li.enabled").removeClass("enabled").removeClass("active_filter").addClass("disabled");
	      $(this).parent().removeClass("disabled").addClass("enabled").addClass("active_filter");
	      var showThis = $(this).attr('class');
	      filterProjects(showThis);
	    } else {
	      // If if gets here it should be enabled & no active_filter. Add active_filter, disable siblings.
	      $(".filter_wrapper ul li.enabled").removeClass("enabled").removeClass("active_filter").addClass("disabled");
	      $(this).parent().removeClass("disabled").addClass("enabled").addClass("active_filter");
	      var showThis = $(this).attr('class');
	      filterProjects(showThis);
	    }

	  });

	  function filterProjects(showThis) { // Hide all projects, then show ones with the proper tags.
	    $("ul#project_cards li").fadeOut(400).delay(150);
	    $("ul#project_cards li."  + showThis).fadeIn(500);
	  }

	  function resetProjects() {
	    $("ul#project_cards li").fadeOut(400).delay(500).fadeIn(500);
	  }
	

// Project Info Box Nav/content swapper 
  $(".project_info ul li a").click(function() {
    $(".project_info ul li a").toggleClass("not_current");
    $(".project_info ul li a").toggleClass("current");
    $("div.project_info > div").toggleClass("current");
  });



// hide index description on click, check cookie to see if hidden


// method page hovers
	$(".method_detail").hide();
	
	$("#method_plan").hover(
		function() {
			$("#method_plan_detail").stop(true, true).fadeIn();
		},
		function() {
			$("#method_plan_detail").fadeOut();
		});

	$("#method_design").hover(
			function() {
				$("#method_design_detail").stop(true, true).fadeIn();
			},
			function() {
				$("#method_design_detail").fadeOut();
			});
			
	$("#method_build").hover(
			function() {
				$("#method_build_detail").stop(true, true).fadeIn();
			},
			function() {
				$("#method_build_detail").fadeOut();
			});
				
	$("#method_launch").hover(
			function() {
				$("#method_launch_detail").stop(true, true).fadeIn();
			},
			function() {
				$("#method_launch_detail").fadeOut();
			});
			
	$("#method_monitor").hover(
			function() {
				$("#method_monitor_detail").stop(true, true).fadeIn();
			},
			function() {
				$("#method_monitor_detail").fadeOut();
			});
	
	



// Load Latest Twitters

$.getJSON("http://search.twitter.com/search.json?callback=?&q=from:mayhq+OR+%40mayhq+-RT&rpp=6", function(data){ 
  $.each(data.results,function(i,tweet){
       // this is where we do what we want with each tweet
      $("#loadTweets").append('<li class="clearfix"><p>@'+tweet.from_user+':  '+tweet.text+' <a class="twitter_timestamp" href="http://twitter.com/'+tweet.from_user+'/status/'+tweet.id_str+'">'+timeSplit(tweet.created_at)+'</a></p><a href="http://twitter.com/'+tweet.from_user+'" target="_blank" ><img src="'+tweet.profile_image_url+'" width="48" height="48" /></a></li>');
  });
});

// Parse links in tweets

// Time Manip Function
function timeSplit(str) {
  var strArray = str.split(" "); // Split by spaces, convert to array
  var shortTime = strArray[2]+" "+strArray[1]+" "+strArray[3]; // Reformat, how we want, with what we want.
  return shortTime;
}


// startups sliding logo sheet
	$('.see_more_partners').click(function() {
		$('.see_more_partners').fadeOut(100);
		$('#partnered_with_logos').animate({
			height: 353
		}, function() {
			$('.see_less_partners').fadeIn(100);
		});
	});
	
	$('.see_less_partners').click(function() {
		$('.see_less_partners').fadeOut(100);
		$('#partnered_with_logos').animate({
			height: 100
		}, function() {
			$('.see_more_partners').fadeIn(100);
		});
	});


	
});
