/**
 * @author jasonroy
 */

var leftNavArray = [];
var currentSection = -1;
$(document).ready(function()
{
	if (typeof document.body.style.maxHeight == "undefined") 
	{
		fixForIE();
	}
    fixHeights();
	if($('.subNav').length > 0)
	{
		setupBackAndNext();
	}
	setupQuiz();
	$('.home .homeLink').addClass("active");
	$('.thickbox').prepend('<a href="" class="previewButton" id="clickToPlay">Click To Play</a>');
	$('.thickbox').prepend('<a href="" class="previewButton" id="clickNext">Next Chapter</a>');
	var clickURL = $('a.thickbox').attr('href')
	$('.thickbox #clickToPlay').click(function(e){
		
		tb_show("Scan Acquisition", clickURL, false);
		return false;
	})
	$('.thickbox #clickNext').click(function(e){
		moveForward();
		return false;
	})
	$('.thickbox').unbind().css('cursor', 'default')
	$('.thickbox').click(function(e){
		return false;
	})
	$('.questions').click(function(){
		
		tb_show("Questions?", '#TB_inline?inlineId=questionContentInline', false);
		return false;
	})
    
})

function fixHeights()
{
    if ($('#subContent').height() < ($('body').height() - $('#header').height())) 
    {
        $('#subContent').height($(document).height() - $('#header').height() + 30);
    }
}

function fixForIE()
{
    jQuery('input[type=text]').addClass('text');
    jQuery('input[type=password]').addClass('password');
	jQuery('input[type=password]').attr('width', jQuery('input[type=password]').width())
    jQuery('input[type=button]').addClass('button');
    jQuery('input[type=submit]').addClass('button');
}

function setupBackAndNext()
{
	leftNavArray = [];
	$('#backAndForward .back').click(moveBack);
	$('#backAndForward .next').click(moveForward);
	$('.subNav a').each(function(i, element)
	{
		leftNavArray.push(element);
		if ($(element).hasClass('active')) 
		{
			currentSection = i;
		}
	})
	if(currentSection == 0)
	{
		$('#backAndForward .back').hide();
	}
	if(currentSection == (leftNavArray.length - 1))
	{
		$('#backAndForward .next').hide();
	}
}
function moveForward(event)
{
	if($('body').hasClass('introduction'))
	{
		window.location = "/quiz/1/";
	}
	else 
	{
		window.location = $(leftNavArray[currentSection + 1]).attr('href')
	}
	return false;
}
function moveBack(event)
{
	if ($('body').hasClass('save-or-try-again')) 
	{
		window.location="/cirrus-hd-oct/scan-acquisition/"
	}
	else 
	{
		window.location = $(leftNavArray[currentSection - 1]).attr('href')
	}
	return false;
}

function setupQuiz()
{
	$('.quiz ol li ul li input').wrap('<div class="inputHolder"></div>');
	$('.quiz ol li ul li label').addClass('mod');
}
