$(document).ready(function()
{
	$('html').addClass('js'); //add 'js' class to html element

	$('.navigation ul + ul').remove(); // Remove ie6 DOM phantom

	var config = {
		 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		 interval: 100, // number = milliseconds for onMouseOver polling interval
		 over: addHover, // function = onMouseOver callback (REQUIRED)
		 timeout: 350, // number = milliseconds delay before onMouseOut
		 out: removeHover // function = onMouseOut callback (REQUIRED)
	};
	$('.navigation ul ul li').hoverIntent(config);
	function addHover(){
		$(this).children('ul').slideDown(250);
	}
	function removeHover(){
		$(this).children('ul').slideUp(100);
	}


	$('form.signup label+input') // placed label over inputs
	.wrap('<div class=\"hover-wrap\"></div>')
	.focus(function(){$(this).prev().hide();})
	.blur(function(){if ( !this.value ) $(this).prev().show()})
	.each(function(){$(this).before( $(this).parent().prev() );
	if ( this.value ) $(this).prev().hide();});
	
	// pullout buttons
	$('.highlightBox a em').each(function (i)
	{
		var iHeadingHeight = $(this).siblings('strong').get(0).clientHeight;
		//alert('strong height is ' + iHeadingHeight);
		var iDescriptionHeight = $(this).get(0).clientHeight;
		//alert('em height is ' + iDescriptionHeight);
		var iDescriptionOffset = iHeadingHeight - iDescriptionHeight; // top = (strong.height - em.height)
		//alert('offset is ' + iDescriptionOffset)
		$(this).css('top',  iDescriptionOffset + 'px')
	})

	$('.highlightBox a').hover(
	function ()
	{
		$(this).children('em').animate(
		{
			top: $(this).children('strong').get(0).clientHeight + 'px' // put description right under the heading
		}, 250 );
	},
	function ()
	{
		var iHeadingHeight = $(this).children('strong').get(0).clientHeight;
		var iDescriptionHeight = $(this).children('em').get(0).clientHeight;

		$(this).children('em').animate(
		{
			top: iHeadingHeight - iDescriptionHeight + 'px' // hide description right behind the heading
		}, 250 );
	});

	// Set specific variable to represent all iframe tags.
	var iFrames = document.getElementsByTagName('iframe');

	// Resize heights.
	function iResize()
	{
		// Iterate through all iframes in the page.
		for (var i = 0, j = iFrames.length; i < j; i++)
		{
			// Set inline style to equal the body height of the iframed content.
			iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';
		}
		window.scrollTo(0,0);
	}

	// Check if browser is Safari or Opera.
	if ($.browser.safari || $.browser.opera)
	{
		// Start timer when loaded.
		$('iframe').load(function()
			{
				setTimeout(iResize, 0);
			}
		);

		// Safari and Opera need a kick-start.
		for (var i = 0, j = iFrames.length; i < j; i++)
		{
			var iSource = iFrames[i].src;
			iFrames[i].src = '';
			iFrames[i].src = iSource;
		}
		window.scrollTo(0,0);
	}
	else
	{
		// For other good browsers.
		$('iframe').load(function()
			{
				// Set inline style to equal the body height of the iframed content.
				this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
				window.scrollTo(0,0);
			}
		);
	}
	
});
