var minWidth = 1100;
var minHeight = 750;
var missed = 0;

function closeTestAnswerPane() {
	$('testModulePane').setHTML( '' );
	$('testAnswerPane').setStyle( 'display', 'none' );
}

function checkAnswer( q ) {
	var status = $(q).getProperty('value');
	var result = "";
	if( status == 0 ) {
		result = "<span class='correct'>Correct!</span>";
		missed = 0;
	} else {
		missed++;
		if( missed == 2 ) {
			window.location.href = window.location.href;
		} else {
			$('testModulePane').setHTML( '<iframe src="' + status + '"></iframe>' );
			$('testAnswerPane').setStyle( 'display', 'block' );
			$('testAnswerPane').setStyle( 'top', window.getScrollTop() );
			result = "<span class='wrong'>Incorrect</span>";
		}
		// Sorry, that's the wrong answer. <a href='" + status + "' title='Answer Page'>Refresh your memory here</a> and try again.
	}
	$('result'+q).innerHTML = result;
	return;
}

function addAnswerEvents() {
	$$('input.answer').each( function( el ) {
		el.addEvent( 'click', function() {
			checkAnswer( el.id );
		},this);
	});
	return;
}

function addAccordion( container, handle, el ) {
	var accordion = new Accordion( 'h2.' + handle, 'div.' + el, {
		opacity: false
	}, $(container));
}

/* for admin panels */
function addEditEvents( className, updatePane ) {
	$ES( 'a.' +  className ).each( function( el ) {
		if( updatePane == 'moduleEditPane' ) {
			alert( 'here' );
		}
		el.addEvent( 'click', function() {
			var qs = el.getProperty( 'href' );
			el.setProperty( 'href', '#' );
			new Ajax( qs, {
				method: 'get',
				evalScripts: true,
				update:$(updatePane)
			}).request();
			$( updatePane ).setStyle('display','block');
		});
	});
	return;
}

function closeEditWindow( pane ) {
	$(pane).setHTML( '' );
	$(pane).setStyle('display', 'none' );
	window.location.reload( false );
}

/*function addFormSubmit( formName, updateBlock ) {
	$( 'adminEditForm' ).addEvent('submit', function( e ) {
		new Event(e).stop();
		$( updateBlock ).setHTML( '<p>Saving...</p>' );
		this.send({
			update: $( updateBlock )
		});
	});
}*/

function addFormSubmit( formName, updateBlock ) {
	$( 'adminEditForm' ).addEvent('submit', function( e ) {
		new Event(e).stop();
		//$( updateBlock ).setHTML( "<p>Saving...</p>" );
		this.send({
			update: $( updateBlock )
		});
	});
}


function logCompletion( videoName ) {
	
	var matchTag = /<(?:.|\s)*?>/g;

	if( videoName != '' ) {
		videoName = videoName.replace( matchTag, '' );
		var uri = 'logger.php?log=' + videoName + ' Completed';
		new Ajax( uri, {
			method: 'get'
		} ).request();
	}
}


/*
function addAccordion( container, handle, el ) {
	var accordion = new Accordion( '.'+handle, '.'+el, {
		opacity: false
	}, $(container));
}
window.addEvent( 'domready', function() {
	//addAnswerEvents();
	//checkResolution();
} );
window.addEvent( 'resize', function() {
	checkResolution();
});

$(document).ready( function() { 
	$(window).bind( 'resize', function() { 
		checkResolution(); 
	});
	checkResolution();
});
*/
/*function checkResolution() {
	if( window.getWidth() <= minWidth ) {
		$E( 'body' ).setStyle( 'width', minWidth + 'px' );
	} else {
		$E( 'body' ).setStyle( 'width', '100%' );
	}
}*/

