/**************************************
 * Wrestling's Future Athletes
 * resizeIframe.js
 * 
 * Code written by http://sonspring.com/journal/jquery-iframe-sizing
 * Modified by Nephtali Rodriguez
 * 
 */

$(document).ready(function()
	{	
		
		//This gets the url sent by the child iframe and then splits the string to find the height
		function getIframeHeight()
		{
			var url = window.location + "";
			var urlArray = url.split("#");//how about return url.substr(indexOf("#")+ 1);
			return urlArray[1];
		}
		
		// 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++)
			{
				//Quick hack added in to just get the gear frame as it is throwing
				//the permission denied error.
				if(iFrames[i].attr("id") == "gearFrame"){
					// Set inline style to equal the body height of the iframed content.
						//iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';	
					iFrames[i].style.height = getIframeHeight() + "px";
				}
				
			}
		}

		// 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;
			}
		}
		else
		{
			// For other good browsers.
			$('iframe').load(function()
				{
					//Quick hack added in to just get the gear frame as it is throwing
					//the permission denied error.
					if($(this).attr("id") == "gearFrame"){
						// Set inline style to equal the body height of the iframed content.
							//this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
						this.style.height = getIframeHeight()+ "px";
					}
				}
			);
		}
	});