/*
call all onload functions here
 */

$(document).ready(function(){
	if (!$("body").hasClass("noRound"))
	{
		var color = $("#wrapper").css("background-color");
		$("#quiz").css("background-color",color);
		$(".question").corner();
		$("#result").corner();
	}
    if ($.browser.safari) {
        $("#quizForm").attr({
            action: document.location.href
        });
    }

	$("ul.answers li").hover(aClick, aClick);
	
	$("ul.answers li input").css("display",'none');
	function aClick() {
       $(this).toggleClass("highlight");
    }

    $("ul.answers li").click(function(){
        inputs = $(this).find("input");
        finalInput = inputs[0];

		$(this).siblings().hover(aClick, aClick)
		$(this).siblings().removeClass("highlight"); 
		$(this).unbind('mouseenter').unbind('mouseleave') ;
		$(this).addClass('highlight'); 
		
		
	
		
        if (finalInput) {
            if (finalInput.type != "radio" && finalInput.checked) {
                finalInput.checked = false;
            }
            else {
				
                finalInput.checked = true;
				$(this).parent().fadeTo("fast", 0.60);
				if ( $(finalInput).hasClass("scroll"))
				{
					$.scrollTo({
                    top: '+=220px',
                    left: '+=0'
                	}, 850);
				}
            }
        }
    });
    if ($('input[name=step]').val() > 3 && $('input[name=step]').val() < 6) {
    
        var base_href = $('base')[0].href;
        var quiz = $('input[name=quiz]').val();
        var answers = $('input[name=answers]').val();
        var gender = $('input[name=gender]').val();
        if (base_href) {
        
            var doOnUnload = 1;
            window.onbeforeunload = function(){
                if (doOnUnload) {
                    document.location = '/quizzes/' + quiz + '.php?step=6&answers=' + answers + '&g=' + gender + '&close=1';
                    return 'Your Quiz Results have finished calculating. Click "Cancel" to be taken directly to the results page.';
                }
            }
            $('form').submit(function(){
                doOnUnload = 0;
            });
            $('a').click(function(){
                doOnUnload = 0;
            });
        }
    }
	if (top.location != location) //frame breaker
	{
    	top.doOnUnload = 0;
        top.location.href = document.location.href;
    } 
	
	
}); //close ready()

