﻿function extraTableStyles()
{
	$('tbody tr').hover(
      function () {
        $(this).addClass('mouseOver');
      }, 
      function () {
        $(this).removeClass('mouseOver');
      }
    );
	
	$('tr:odd').addClass('odd');
}

function navigationSelection()
{
   var path = location.pathname;
   var pathArray = path.split("/");
   var fileName = pathArray[pathArray.length-1];
   if (fileName)
     $('#navigation a[@href$="' + fileName + '"]').attr('class', 'active');
}

function expandTable()
{
	
	$('.expand-all').click(function()
	{
		$(this).parent().parent().parent().parent().find('.extra-content').show(200);
		$('.expand').css('backgroundImage','url("img/icon_contract.png")');
	});
	
	$('.contract-all').click(function()
	{
		$(this).parent().parent().parent().parent().find('.extra-content').hide(200);
		$('.expand').css('backgroundImage','url("img/icon_expand.png")');
	});
	
	$('.expand').click(function()
	{
		$(this).css('backgroundImage','url("img/icon_expand.png")');
		if($(this).parent().find('.extra-content').css('display') == 'none')
		{
			$(this).parent().find('.extra-content').show(200);
			$(this).css('backgroundImage','url("img/icon_contract.png")');
		}
		else
			$(this).parent().find('.extra-content').hide(200);
	});
}

function focusForms()
{
	$('input[type=file]').css('size','50');
	
	$('input[type=text]').focus(function()
	{
		$('form').find('.focus').removeClass('focus');
		$(this).addClass('focus');
	});
	$('textarea').focus(function()
	{
		$('form').find('.focus').removeClass('focus');
		$(this).addClass('focus');
	});
	$('button').focus(function()
	{
		$('form').find('.focus').removeClass('focus');
	});
}

function toggleTinyMCE()
{
	$('.toggleTinyMCE').click(function()
	{
		if(tinyMCE.get('text').isHidden())
			tinyMCE.get('text').show();
		else
			tinyMCE.get('text').hide();
	});
}

function tooltip()
{
	// Position the tooltip.
	var positionTooltip = function(event) 
	{
		var tPosX = event.pageX - 5;
		var tPosY = event.pageY + 22;
		$('div.tooltip').css({top: tPosY, left: tPosX});
	};
	
	// Show (create) the tooltip.
	var showTooltip = function(event) 
	{
		$('div.tooltip').remove();   
		var text = $(this).text();
		$('<div class="tooltip">' + text + '</div>').appendTo('body');
		positionTooltip(event);
	};
	
	// Hide (remove) the tooltip.
	var hideTooltip = function() 
	{
		$('div.tooltip').remove();
	};

	$('.has-tooltip').hover(showTooltip, hideTooltip).mousemove(positionTooltip);
}

function fileForm()
{
	$('input#image').css('opacity','0');
	$('input#image').change(function()
	{					
		var filename = $(this).attr('value');
		$('.file-input-replacer').attr('value',filename);
	});
	$('input#image').mouseover(function()
	{
		$('.file-input-container button').addClass('hover');
	}).mouseout(function()
	{
		$('.file-input-container button').removeClass('hover');
	});
}

function extraIE6Styles()
{
	$('#masthead h1').css('height','2.5em');
	$('#navigation').css('height','2.9em');
	$('input[type=radio]').css({width:'auto',border:'none'});
	$('input[type=checkbox]').css({width:'auto',border:'none'});
	$('ol li ol li label').css('width','10%');
}

$(document).ready(function()
{
	extraTableStyles();
	navigationSelection();
	expandTable();
	toggleTinyMCE();
	tooltip();
	fileForm();
	
	if(($.browser.msie ) && ($.browser.version < 7)) 
	{
		extraIE6Styles();
	}
	
	if(($.browser.msie ) && ($.browser.version < 8)) 
	{
		focusForms();
	}
	
});