var $lastCategoryBox;
var browser=navigator.appName;
var usingIE=false;
if (browser=="Microsoft Internet Explorer")
	usingIE=true;

jQuery(document).ready(function($){
	
	$("div.main-nav > ul").addClass("sf-menu").superfish({
		onInit: function() { $('div.main-nav').fadeIn(); $('#home-page').show(); }
	}).find('ul').bgIframe({opacity:false});
	
	$("div.sub-page-nav > ul").addClass("sf-menu").superfish({
		onInit: function() { $('div.sub-page-nav').fadeIn(); }
	}).find('ul').bgIframe({opacity:false});
		
	$("div.quote").wrapInner('<div class="blockquote-content"></div>');	
	$('<div class="top-left"></div><div class="bottom-right"></div>')
		.prependTo($("div.quote"));	
	
	$("#translate-gadget").hoverIntent(showTranslate, hideTranslate);
	
	$("#google-translate-link").click(function(){
		$("#translate-gadget").fadeIn(1000);
		this.blur();
		return false;
	});

	$("#landing-page-container .tfp-category").bind("click", MinimizeContent);

});

function showTranslate() { }

function hideTranslate()
{
	jQuery(this).fadeOut();
}

function  MinimizeContent(e)
{	
	var $link;
	$link = jQuery(e.target);
		
	var $categoryBox = jQuery(this).closest('.tfp-category');
	jQuery('.tool-body').hide();
	
	if (jQuery('#selected-content').is(':visible')) {
		ShowToolContent($categoryBox);
	} else {	
		jQuery('.tfp-category').animate({
			height: "23px",
			marginTop: "2px",
			marginBottom: "0px"
		}, 250, "linear", function() { 				
				if (jQuery(this).attr('id') == $categoryBox.attr('id')) 
					ShowToolContent($categoryBox, $link);
			}
		);
			
	}
	
	return false;
}

function ShowToolContent($categoryBox, $link)
{		
	if (usingIE) {		
		ShowContent($categoryBox);
		jQuery('#selected-content').show();
		GotoSpecificContent($link);
	} else {
		if (jQuery('#selected-content').is(':visible')) {		
			jQuery('#selected-content').fadeTo(250,0.01, function(){
				ShowContent($categoryBox);		
				jQuery('#selected-content').fadeTo(250,1, function() {
					GotoSpecificContent($link);
				});
			});
		}	else {
			ShowContent($categoryBox);
			jQuery('#selected-content').fadeIn(250, function() {
				GotoSpecificContent($link);
			});		
		}
	}	
	return false;
}

function GotoSpecificContent($link)
{	
	if (!$link || $link.length <= 0) return false;
	if ($link.attr('href') && $link.attr('href').indexOf('#') >= 0) {
		jQuery.scrollTo('a[name='+$link.attr('href').replace('#','')+']');
	}
	return false;
}

function ShowContent($categoryBox) {
	var newColor = $categoryBox.css('background-color');
	if ($lastCategoryBox)
		$lastCategoryBox.append(jQuery('#selected-content-body .full-post'));
	$lastCategoryBox = $categoryBox;
	jQuery('#selected-content-title').css('background-color', newColor);
	jQuery('#selected-content-footer').css('background-color', newColor);	
	jQuery('#selected-content-body').css('border-color', newColor);
	jQuery('#selected-content-title h2').text($categoryBox.find('.tool-title').text());
	jQuery('#selected-content-body').append($categoryBox.find('.full-post'));
}