$(document).ready(function(){
	/*
		Code from (with slight modifications):
		http://www.pixeline.be/blog/2008/javascript-loading-external-urls-in-jqmodal-jquery-plugin/
	*/
	var loadInIframeModal = function(hash){
		var $trigger = $(hash.t);
		var $modal = $(hash.w);
		var myUrl = $trigger.attr('href');
		//var myTitle = $trigger.attr('title');
		var $modalContent = $("iframe", $modal);

		$modalContent.html('').attr('src', myUrl);
		//let's use the anchor "title" attribute as modal window title
		//$('#jqmTitleText').text(myTitle);
		//$modal.jqmShow();
		$modal.show();
	}

	// initialise jqModal
	$('#modalWindow').jqm({
		modal: true,
		trigger: 'a.training_module_link',
		target: '#jqmContent',
		onShow: loadInIframeModal
	});

	// Temporary fix for launching "Enlarge" links inside training modules
	$('.thickbox').click(
		function() {
			window.open(this.href, '', 'status=0,toolbar=0,location=0,menubar=0,directories=0');
			return false;
		}
	);

	$('#username').focus();
});

$(document).keydown( function( e ) {
 if( e.which == 27) {  // escape, close box
	 $("#modalWindow").jqmHide();
	 parent.$("#modalWindow").jqmHide();
 }
});

function load_modal(url) {
	var $modal = $('#modalWindow');
	var $modalContent = $("iframe", $modal);
	$modalContent.html('').attr('src', url);
	$modal.jqmShow();
}

function close_modal() {
	if (parent.location.href.match(/report_card.cfm/)) {
		parent.location.reload();
	}
	parent.$("#modalWindow").jqmHide();
}

function redirect_to(filepath) {
	var base_url = parent.location.href.replace(/\/nintendo\/.*$/, '/nintendo/');
	parent.location.href = base_url + filepath;
}
function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( parent.window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = parent.window.innerWidth;
    myHeight = parent.window.innerHeight;
  } else if( parent.document.documentElement && ( parent.document.documentElement.clientWidth || parent.document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = parent.document.documentElement.clientWidth;
    myHeight = parent.document.documentElement.clientHeight;
  } else if( parent.document.body && ( parent.document.body.clientWidth || parent.document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = parent.document.body.clientWidth;
    myHeight = parent.document.body.clientHeight;
  }
  // window.alert( 'Width = ' + myWidth );
  // window.alert( 'Height = ' + myHeight );
  if (myWidth < 800 || myHeight < 710) {
  	   $("#training_footer").css("height", "275px");
	  // window.alert( 'Too short Height is ' + myHeight );
	   // alert($('#training_footer').height());
	   };
}