// JavaScript Document for TT iBlog
// Author: Axinte Adrian
// Created: 23/06/2010
// Version: v.1.0.3
// Last Rev: 01/22/2011

Cufon.replace(".post h2, #respond, #comments", {hover:true, fontFamily:"Myriad Pro"});

$(document).ready(function() {
	$("#topbar").click(function(){ 
		$("html, body").animate({scrollTop:0}, "slow"); 
	});
	$("#topbar").css({cursor:"pointer"});
	
	$(".tabs li:last-child, .sectabs li:last-child, .trdtabs li:last-child").css({marginRight:"0"});
	$(".trdtab_container").css({margin:"0"});
	$(".post:last-child").css({margin:"0", border:"none"});
	$(".twitter-feed ul li:last-child").css({paddingRight:"0"});
	$(".twitter-feed ul li:first-child").css({marginLeft:"10px"});
	$("#footer li:last-child").css({background:"transparent"});
	$("#footer li:last-child a").css({paddingRight:"0"});
	$("#topnavigation li:first-child a").css({paddingLeft:"0"});
						   
	$(".tab_content, .sectab_content, .trdtab_content").hide();
	$("ul.tabs li:nth-child(1), ul.sectabs li:nth-child(1), ul.trdtabs li:nth-child(1)").addClass("active").show(); 
	$(".tab_content:first-child, .sectab_content:first-child, .trdtab_content:first-child").show();
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active"); 
		$(".tab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn(); 
		return false;
	});
	$("ul.sectabs li").click(function() {
		$("ul.sectabs li").removeClass("active");
		$(this).addClass("active"); 
		$(".sectab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn(); 
		return false;
	});
	$("ul.trdtabs li").click(function() {
		$("ul.trdtabs li").removeClass("active");
		$(this).addClass("active"); 
		$(".trdtab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn(); 
		return false;
	});
});

$(function() {
	var $el, leftPos, newWidth, $mainNav = $("#topnavigation");
	$mainNav.append("<li id='magic-line'></li>");
	var $magicLine = $("#magic-line");

	jQuery.fn.exists = function(){return this.length>0;}
	if ($('#topnavigation li.current-cat').exists()) {
		$magicLine
			.width($(".current-cat").width())
			.css("left", $(".current-cat a").position().left)
			.data("origLeft", $magicLine.position().left)
			.data("origWidth", $magicLine.width());
			
		$("#topnavigation li a").hover(function() {
			$el = $(this);
			leftPos = $el.position().left;
			newWidth = $el.parent().width();
			$magicLine.stop().animate({
				left: leftPos,
				width: newWidth
			});
		}, function() {
			$magicLine.stop().animate({
				left: $magicLine.data("origLeft"),
				width: $magicLine.data("origWidth")
			});
		});
	} else {
		$magicLine.css({width:"100%", left:"0"});
	}
});
