$(function() {

	Cufon.replace('.replace', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#blog #main .post h1', {fontFamily: 'IReg', hover: true});
	Cufon.replace('#sidebar h2', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#corporate .block h3', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#advising .block h3', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#cognition .block h3', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#cognition .cogsource .block h3', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#cognition .cogread .block h3', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#main th', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#cognition .cogsub tr.last', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#connect .block h2', {fontFamily: 'IBold', hover: true});
	Cufon.replace('div.panes div h3', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#coglist h1.top', {fontFamily: 'IReg', hover: true});
	Cufon.replace('#corporate h1.top', {fontFamily: 'IReg', hover: true});
	Cufon.replace('#cognition h1.top', {fontFamily: 'IReg', hover: true});
	Cufon.replace('#cogfilters h3', {fontFamily: 'IBold', hover: true});
	Cufon.replace('#cogfilters a', {fontFamily: 'IBold', hover: true});

	$("a.stbutton").html("Share");
	$("#blog ul.nav a.stbutton").html("Share this post &raquo;");

	// CLEAR SEARCH BOXES
	$('.default').each(function() {
		var default_value = this.value;
		$(this).focus(function() {
			if(this.value == default_value) {
			this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
			this.value = default_value;
			}
		});
	});

	// MAIN NAV
	$('#header ul li').hover(function() {
		$(this).addClass('over');
	}, function() {
		$(this).removeClass('over');
	});

	$('#header li.false a.false').click(function() {
		$(this).parent('#header li.false').toggleClass('open');
		return false;
	});

// HOME PAGE SLIDESHOW
	$('#highlight .slideshow').before('<div id="hnav">').cycle({
		fx:     'scrollRight',
		timeout: 10000,
		pager:  '#hnav',
		before: function() { if (window.console) console.log(this.src); }
	});

	// SIDEBAR SLIDESHOW
	$('#quotes .slideshow').before('<div id="qnav">').cycle({
		fx:     'scrollRight',
		speed:  300,
		timeout: 10000,
		pager:  '#qnav',
		before: function() { if (window.console) console.log(this.src); }
	});

	// SIDEBAR ROLLOVERS
	$('#sidebar ul li').hover(function() {
		$(this).addClass('over');
	}, function() {
		$(this).removeClass('over');
	});

	// SIDEBAR REVEALS
	$('.cogbarnav li.false a.false').click(function() {
		$(this).parent('.cogbarnav li.false').toggleClass('open');
		return false;
	});
	$('ul.first li.all a').click(function() {
		$('ul.first li.hide').removeClass('hide');
		$('ul.first li.all').addClass('hide');
		return false;
	});
	$('ul.last li.all a').click(function() {
		$('ul.last li.hide').removeClass('hide');
		$('ul.last li.all').addClass('hide');
		return false;
	});
	$('.select').hover(function() {
		$(this).addClass('drop');
	}, function() {
		$(this).removeClass('drop');
	});

	// ALTERNATE ROW COLORS
  $("#main tr:even").addClass('even');
  $("#main tr:odd").addClass('odd');

	// BACK TO TOP LINK
	$("p.top a").click(function(){
		$.scrollTo(0, 400);
		return false;
	});

	// "FALSE" LINKS
	$("a.false").click(function(){
		return false;
	});

	// PRINT LINKS
	$('a.print').click(function() {
		window.print();
		return false;
	});

	// TABS
	$("ul.tabs").tabs("div.panes > div");
	$("ul.tabs li a").click(function(){
		Cufon.replace('.replace', {fontFamily: 'IBold', hover: true});
		return false;
	});

	// SHARING OVERLAY
	$(document).keyup(function(event){
		if (event.keyCode == 27) {
			try{
				$("#overlay").fadeOut("slow", function(){
					$(this).remove();
				});
				$("#share-overlay").fadeOut("slow", function(){
					$(this).remove();
				});
			}catch(e){}
		}
	});	
	$("a.close").live("click", function(){
			try{
				$("#overlay").fadeOut("slow", function(){
					$(this).remove();
				});
				$("#share-overlay").fadeOut("slow", function(){
					$(this).remove();
				});
			}catch(e){}
	});
	$("#overlay").live("click", function(){
			try{
				$("#overlay").fadeOut("slow", function(){
					$(this).remove();
				});
				$("#share-overlay").fadeOut("slow", function(){
					$(this).remove();
				});
			}catch(e){}
	});
	
	$("a.share").live("click", function(){
		var url = $(this).attr("href");
		$.ajax({
			type: "POST",
			url: url,
			data: "",
			success: function(data){
				var winW = $("#wrapper").width();
				$("#wrapper").append(data); //
				var w = $("#share-overlay").width();
				$("#share-overlay").addClass('receipt');
				$("#share-overlay").fadeIn("slow");
				$("#overlay").fadeIn("slow");
				Cufon.replace('#share-overlay form label', {hover: true});
				$.scrollTo('0', '400');
			}
		});
		return false;
	});
	
	$("a.news-sub").live("click", function(){
		var url = $(this).attr("href");
		$.ajax({
			type: "POST",
			url: url,
			data: "",
			success: function(data){
				var winW = $(window).width();
				var winH = $(window).height();
				var ph = $(this).parent().height();
				$("body").append(data);
				var w = $("#share-overlay").width();
				var h = $("#share-overlay").height();
				$("#share-overlay").css('left', winW/2-w/2).css('top', winH/2-h/2).fadeIn("slow");
				$("#overlay").fadeIn("slow");
				Cufon.replace('#share-overlay.newsletter h1', {fontFamily: 'IBold', hover: true});
				Cufon.replace('#share-overlay.newsletter label.heavy', {fontFamily: 'IBold', hover: true});
				$.scrollTo(0, 400);
			}
		});
		return false;
	});

});
