jQuery(document).ready(function()
{
	$("body").addClass("js-enabled");
	InitNav();
	InitTabs();
	$('div.rotatepics').cycle('fade');
  var flag = 0;  
  $('h1').each(function(){
    if($(this).text() == 'Search Results') {
      flag = 1;
    }
  });
  
  if( flag == 0) {
    $('.BlogRecentPost').after( $('#news-articles') ).after( $('#books-and-media') );
    $('#books-and-media, #news-articles').show();
  } else {
    $('.BlogRecentPost').hide();  
    $('#news-articles').hide();  
    $('.sidebar-gallery').hide();  
    $('#books-and-media').hide();  
  };

// Swap value text form

    var swapValues = [];
    $(".swap-value").each(function(i){
        swapValues[i] = $(this).val();
        $(this).focus(function(){
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function(){
            if ($.trim($(this).val()) == '') {
                $(this).val(swapValues[i]);
            }
        });
    }); 

  if( $('#atff').length > 0 ) { $('#atff').hide(); };

});

function mailpage(){
  mail_str = "mailto:?subject=Check out the " + document.title;
  mail_str += "&body=I thought you might be interested in the " + document.title;
  mail_str += ". You can view it at, " + location.href;
  location.href = mail_str;
}
	
function InitNav(){
	$('#navigation a')
	.css( {backgroundPosition: "0 0"} )
	.mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0px -50px)"},
			{duration:400})
		$(this).parent().stop().animate(
			{backgroundPosition:"(-130px 0px)"},
			{duration:800})
		})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0px 0px)"}, 
			{duration:400})
		$(this).parent().stop().animate(
			{backgroundPosition:"(-300px 0px)"},
			{duration:800})
		})
}

function InitTabs(){
	
	// set width on container
	var w = 0;
	var h = 0;
	$('.tabbed-items .section').each(function(){
		w += $(this).width();
		if( $(this).outerHeight() > h ) h = $(this).outerHeight();
	})
	$('.tabbed-items').width(w);
	$('.tab-window').height(h + 20);
	
	// setup nav
	/*
	$('.tab-nav a')
	.css( {backgroundPosition: "-300px 0"} )
	.mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0px 0px)"},
			{duration:600})
		})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(-300px 0px)"}, 
			{duration:600})
		})*/
	$('.tab-nav a').click(SelectTab);
	
}

function SelectTab(){	
	var left = 0 - ( $('#' + $(this).attr('rel')).offset().left - $('.tabbed-items').offset().left );
	$('.tabbed-items').animate({
		left: left
	}, 600 );
	$('.tab-nav a').removeClass("selected");
	$(this).addClass("selected");
	return false;
}

