
$(document).ready(function() {
	
	// cufon
	
	Cufon.replace('h3');
	Cufon.replace('#sidebar a', {hover: true}); 
	Cufon.replace('.thingsWeLike a', {hover: true}); 
	Cufon.replace('.thingsWeLike span');
  
	/* resize dropdown links to fit their containers (which has stretched to accomodate the longest link)*/
	$('ul.sub').each(function() {
		this_sub = $(this);
		this_width = ($(this_sub).width()-30);
		$(this_sub).children("li").children("a").css("width",this_width);
	});
	
	$('ul.sub li:first-child a').css("padding-top","15px");
	$('ul.sub li:last-child a').css("padding-bottom","15px");
	$('ul.sub .tour').prev("li").children("a").css("padding-bottom","12px");
	

	/* the dashboard */
	$(".dashboard_tab a").click(function() {
		$(".dashboard_container").slideToggle();
		return false;
	});


	/* main nav animation action */

	$('.navHover').mouseenter(function () {
		var this_here = $(this);
		var next_sub = $(this_here).next('ul.sub');
		$(next_sub).addClass('keep_menu_open_saysnav');
		$(this_here).stop().animate({backgroundColor:"#413E3C"}, 'fast');	
		$(next_sub).stop().fadeTo("fast",1);		
		
		$('ul.sub').not(next_sub).stop().fadeOut('fast');
		$('.navHover').not(this).stop().animate({ backgroundColor: "#5B5653" }, 'fast');
				
		return false;  
    });

	$('ul.sub').mouseenter(function () {
        $(this).addClass('keep_menu_open_sayssub');
		return false;  
    });

	$('.navHover').mouseleave(function () {
		the_hover = $(this);
		$(the_hover).next('ul.sub').removeClass('keep_menu_open_saysnav');
		setTimeout(function(){
			if (!$(the_hover).next('ul.sub').hasClass('keep_menu_open_sayssub')) {
				$(the_hover).next('ul.sub').stop().fadeOut('fast');
				$(the_hover).stop().animate({ backgroundColor: "#5B5653" }, 'fast');
			}
		}, 30);
		clearTimeout();
    });

	$('ul.sub').mouseleave(function() {
		the_sub = $(this);
		$(the_sub).removeClass('keep_menu_open_sayssub');
		setTimeout(function(){
			if (!$(the_sub).hasClass('keep_menu_open_saysnav')) {
				$(the_sub).stop().fadeOut('fast');
				$(the_sub).siblings(".navHover").stop().animate({ backgroundColor: "#5B5653" }, 'fast');
			}
		}, 30);
		clearTimeout();
	});
	
	/* end main nav */


    // email submit label

	$('#email[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));
		}

		$(this).focus(function() {
			if($(this).val() === $(this).attr('title')) {
				$(this).val('').addClass('focused');
			}
		});

		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');
			}
		});
	});  


	// initialize portfolio scrollable 
	
	$("div.scrollable").scrollable({
	//	circular: true,
		mousewheel: true,
		items: ".panels"
	});
	
	$(".back_to_start").click(function() {
		$("div.scrollable").scrollable().seekTo(0);
	});
	
	$(".scrollable img").click(function() {
		$("div.scrollable").scrollable().next();
	});


	// tooltip
	
	$(".tipTrigger").tooltip({
		position: 'top center', 
		offset: [18, 0],
		effect: 'slide'
	});

	$(".siteCreditTip").tooltip({
		position: 'top center', 
		offset: [10, 70],
		effect: 'slide'
	});


	// portfolioTout hovers

/*
	$('.portfolioTout img').mouseenter(function(){
		$(this).next('a').fadeIn('fast');
	});
	
	$('.portfolioTout img').mouseleave(function(){
		$(this).parent(".portfolioTout").addClass('fade_this');
		setTimeout(function(){ 
			$(".fade_this a").fadeOut('fast');
		}, 1000);
	});
*/
	
	$('.portfolioTout img').live('mouseover mouseout', function(event) {
    if (event.type == 'mouseover') {
      $(this).next('a').fadeIn('fast');
    } else {
      $(this).parent(".portfolioTout").addClass('fade_this');
        setTimeout(function(){ 
          $(".fade_this a").fadeOut('fast');
      }, 1000);
    }
  });

	$('.portfolioTout a').mouseenter(function() {
		$(this).parent(".portfolioTout").removeClass('fade_this');
	});
	
	$('.portfolioTout a').mouseleave(function() {
		$('.portfolioTout a').fadeOut('fast');
	});
	
	$('.next_category_link span').mouseenter(function(){
		$(this).next('a').fadeIn('fast');
	});
	
	$('.next_category_link img').mouseleave(function(){
		$(this).parent(".next_category_link").addClass('fade_this');
		setTimeout(function(){ 
			$(".fade_this a").fadeOut('fast');
		}, 1000);

	});

	$('.next_category_link a').mouseenter(function() {
		$(this).parent(".next_category_link").removeClass('fade_this');
	});
	
	$('.next_category_link a').mouseleave(function() {
		$('.next_category_link a').fadeOut('fast');
	});

});      





		
		
