// JavaScript Document
$(document).ready(function(){
// Bouncy login form
$('#login form').hide();
  $('#login #show, #ShowLogin2').toggle(function() {
    $('#show')
      .addClass('active')
      .next('form')
      .animate({'height':'show'}, {
        duration:'slow'
      });
  }, function() {
    $('#show')
      .removeClass('active')
      .next('form')
      .slideUp();
  });
  $('#login form :submit').click(function() {
    $('#show')
      .parent()
      .prev('a')
      .click();
  });
// Search submit
$('#searchSubmit').click(function() {
  $('#searchform').submit();
});
// Performance Charts
    $('#data').html('loading...').load('/lib/funds/spy.php');
  $('#ETFdropdown').change(function(e) {
    var url = '/lib/funds/' + $(this).attr('value') + '.php';
	$('#data').hide('fast',loadContent);
    //$('#load').remove();
   // $('#data').prepend('<span id="load">LOADING...</span>');
    $('#load').fadeIn('normal');
    e.preventDefault();
    function loadContent() {
    	$('#data').load(url,'',showNewContent())
    }
    function showNewContent() {
    	$('#data').show('normal');
    }
   // function hideLoader() {
   // 	$('#load').fadeOut('normal');
   // }
	return false;
  })
// Tabs
  $( '#tabs div.stat_tab:not(:first)' ).hide();
  $('#tab-nav li').click(function(e) {
    $('#tabs div.stat_tab').hide();
    $('#tab-nav .current').removeClass("current");
    $(this).addClass('current');
	
var clicked = $(this).find('a:first').attr('href');
    $('#tabs ' + clicked).fadeIn('fast');
    e.preventDefault();
	return false;
  }).eq(0).addClass('current');

	var openTab = $(location.hash).filter("#tabs div.stat_tab");
	if(openTab.length){
		$("a[href='"+location.hash+"']").click();
	}


// Trade by Trade rows
  $('#performancetable tr.funddata:even, #performancetable2 tr.funddata:even').addClass('grey');
  $('#performancetable tr.funddata, #performancetable2 tr.funddata').mouseover(function() {
	   $(this).addClass('mouseover');
	});
  $('#performancetable tr.funddata, #performancetable2 tr.funddata').mouseout(function() {
	  $(this).removeClass('mouseover');
	});
  $('#yeartable tr.yeardata').mouseover(function() {
	   $(this).addClass('mouseover');
	});
  $('#yeartable tr.yeardata').mouseout(function() {
	  $(this).removeClass('mouseover');
	});

});
// dropdown menu
$(document).ready(function(){
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	$("ul.topnav li a") .mouseover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('medium'); //When the mouse hovers out of the subnav, move it back up
		});
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
 
});

