// JavaScript Document
document.createElement('header');document.createElement('footer');document.createElement('section');document.createElement('aside');document.createElement('nav');document.createElement('article');document.createElement('figure');document.createElement('time');

$().ready(function() {	
	//
   	$('nav ul li').hover(function(){
		$(".child",this).show();;
		}, function(){
		$(".child",this).hide();
   	});
	
	//
	$(".accordian h3:first").addClass("current");
	$(".accordian div:not(:first)").hide();

	$(".accordian h3").click(function(){
		$(this).next("div").slideToggle("slow");
		$(this).toggleClass("current");
		$(this).siblings("h3").removeClass("current");
	});
	
	
	//
	$('.work-image').hover(function(){
		$(".overlay-caption-content",this).fadeIn(300);
		}, function(){
		$(".overlay-caption-content",this).fadeOut(300);
   	});
	
	
	//
	$(".leftnav h3:first").addClass("current");
	$(".leftnav ul:not(:first)").hide();

	$(".leftnav h3").click(function(){
		$(this).next("ul").slideToggle("slow"); //.siblings("ul:visible").slideUp("slow");
		$(this).toggleClass("current");
		$(this).siblings("h3").removeClass("current");
	});
	
	//
	$('.media').each(function () {
		var distance = 10;
		var time = 250;
		var hideDelay = 500;

		var hideDelayTimer = null;

		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		var info = $('.popup', this).css('opacity', 0);


		$([trigger.get(0), info.get(0)]).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				// don't trigger the animation again
				return;
			} else {
				// reset position of info box
				beingShown = true;

				info.css({
					top: -18,
					left: -30,
					display: 'block'
				}).animate({
					top: '-=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					beingShown = false;
					shown = true;
				});
			}

			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					shown = false;
					info.css('display', 'none');
				});

			}, hideDelay);

			return false;
		});
	});
	
	/*
	$(".navlink .close").click(function(){
		$(".foliodesc").slideUp("slow");
		$(".navlink").animate({right:-92},"slow");
		$(".navlink li.close").hide("slow");
		$(".navlink li.open").show("slow");
	});
	$(".navlink .open").click(function(){
		$(".foliodesc").slideDown("slow");
		$(".navlink").animate({right:-60},"slow");
		$(".navlink li.close").show("slow");
		$(".navlink li.open").hide("slow");
	});
	*/
	
	$(".navlink .close").click(function(){
		$(".foliodesc").hide("slow");
		$("#navlink2").hide("slow");
		$("#navlink1").show("slow");
	});
	$(".navlink .open").click(function(){
		$(".foliodesc").show("slow");
		$("#navlink2").show("slow");
		$("#navlink1").hide("slow");
	});
	
	
	//	
	$('.portfolio').addClass('three');
	$('a#three').addClass('current');
	
	$('a#one').click(function() {
		$('.portfolio').addClass('one');
		$('.portfolio').removeClass('two');
		$('.portfolio').removeClass('three');
		$('a#one').addClass('current');
		$('a#two').removeClass('current');
		$('a#three').removeClass('current');
	});
	
	$('a#two').click(function() {
		$('.portfolio').addClass('two');
		$('.portfolio').removeClass('one');
		$('.portfolio').removeClass('three');
		$('a#two').addClass('current');
		$('a#three').removeClass('current');
		$('a#one').removeClass('current');
	});
	
	$('a#three').click(function() {
		$('.portfolio').addClass('three');
		$('.portfolio').removeClass('two');
		$('.portfolio').removeClass('one');
		$('a#three').addClass('current');
		$('a#two').removeClass('current');
		$('a#one').removeClass('current');
	});
	
	//	
	$('ul.filter a').click(function() {
		$(this).css('outline','none');
		$('ul.filter .current').removeClass('current');
		$(this).parent().addClass('current');
		
		var filterVal = $(this).text().toLowerCase().replace(' ','-');
				
		if(filterVal == 'all') {
			$('.portfolio div.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			
			$('.portfolio .p_item').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		
		return false;
	});

	//	
	$('ul.testimonial li').hover(function(){
		$("div.callout",this).fadeIn('slow');
		}, function(){
		$("div.callout",this).fadeOut('slow');
   	});
	
	//
	$("img.a").hover(
	function() {
	$(this).stop().animate({"opacity": "0"}, "slow");
	},
	function() {
	$(this).stop().animate({"opacity": "1"}, "slow");
	});
	
	//
	$('.share').hover(function(){
		$(".sharebox").fadeIn();
		}, function(){
		$(".sharebox").fadeOut();
   	});
	
	//
	$('.career-wrapper .career').hover(function(){
		$(".career-overlay",this).fadeIn(300);
		$(this).attr('style', 'z-index:2');
		}, function(){
		$(".career-overlay",this).hide(300);
		$(this).attr('style', 'z-index:0');
   	});
	
	//
	$('#passwordlink').click(function(){
		$("#loginarea").fadeOut(300);
		$("#passwordarea").fadeIn(300);
   	});
	$('#loginlink').click(function(){
		$("#passwordarea").fadeOut(300);
		$("#loginarea").fadeIn(300);
   	});
	
	//

});

$(document).ready(function(){
	
	$('.sponsorFlip').bind("click",function(){		
		var elem = $(this);		
		if(elem.data('flipped'))
		{
			elem.revertFlip();
			elem.data('flipped',false)
		}
		else
		{	
			elem.flip({
				direction:'lr',
				speed: 350,
				onBefore: function(){					
					elem.html(elem.siblings('.sponsorData').html());
				}
			});
			elem.data('flipped',true);
		}
	});
	
});

