/*
* Job Test Data
*/
//# QUESTIONS
q1 = {'career_type':'R', 'question':'I am athletic.'};
q2 = {'career_type':'R', 'question':'I am a nature lover.'};
q3 = {'career_type':'R', 'question':'I am independent.'};
q4 = {'career_type':'R', 'question':'I like excercising.'};

q5 = {'career_type':'I', 'question':'I like complex calculations.'};
q6 = {'career_type':'I', 'question':'I am curious about everything.'};
q7 = {'career_type':'I', 'question':'I like to be challenged.'};
q8 = {'career_type':'I', 'question':'I like to solve math problems.'};

q9 = {'career_type':'A', 'question':'I am creative.'};
q10 = {'career_type':'A', 'question':'I attend a lot of movies.'};
q11 = {'career_type':'A', 'question':'I like to sing, act or dance.'};
q12 = {'career_type':'A', 'question':'I like arts and crafts.'};

q13 = {'career_type':'S', 'question':'I am very friendly.'};
q14 = {'career_type':'S', 'question':'I play team sports.'};
q15 = {'career_type':'S', 'question':'I like to go to parties.'};
q16 = {'career_type':'S', 'question':'I like making new friends.'};

q17 = {'career_type':'E', 'question':'I like learning about money.'};
q18 = {'career_type':'E', 'question':'I want to own a small business.'};
q19 = {'career_type':'E', 'question':'I like being a leader.'};
q20 = {'career_type':'E', 'question':'I consider myself popular.'};

q21 = {'career_type':'C', 'question':'I am very organized.'};
q22 = {'career_type':'C', 'question':'I like keeping lists.'};
q23 = {'career_type':'C', 'question':'I like writing letters.'};
q24 = {'career_type':'C', 'question':'I like using the computer.'};

questions = [q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24];

//# TYPES
tR = {'type':'Realistic','description':'People who are realistic have athletic or mechanical ability, prefer to work with objects, machines, tools, plants or animals, or to be outdoors.'};
tI = {'type':'Investigative','description':'People who are invetigative like to observe,learn, investigate, analyze, evaluate, or solve problems'};
tA = {'type':'Artistic','description':'People who are artistic have innovating, or intuitional ability and like to work in unstructured situations using their imagination or creativity.'};
tS = {'type':'Social','description':'People who are social like to work with people to inform, enlighten, help, train, develop, or cure them, or are skilled with words'};
tE = {'type':'Enterprising','description':'People who are enterprising like to work with people, influencing, persuading, performing, leading or managing for organizational goals or for economic gains.'};
tC = {'type':'Conventional','description':'People who are conventional like to work with data, have clerical or numerical ability, carry out tasks in detail or follow through on others instructions.'};
profile_types = {'R':tR, 'I':tI, 'A':tA, 'S': tS, 'E': tE, 'C': tC };

//# JOBS

jR = [{'name':'Medical Assistant','slug':'medical-assistant'}, {'name':'Aviation Tech','slug':'aviation-maintenance-technician'}, {'name':'Culinary Arts','slug':'culinary-arts'},{'name':'Computer Engineer','slug':'computer-engineering'}, {'name':'Dental Assistant','slug':'dental-assistant'}]
jI = [{'name':'Pharmacy Techician','slug':'pharmacy-technician'}, {'name':'Security Guard','slug':'security-guard'}, {'name':'Dental Assistant','slug':'dental-assistant'}, {'name':'Medical Assistant','slug':'medical-assistant'}];
jA = [{'name':'Advertising','slug':'advertising'}, {'name':'Graphic Design','slug':'graphic-design'}, {'name':'Desktop Publishing','slug':'desktop-and-web-publishing'},{'name':'Interior Designer','slug':'interior-design'}];
jS = [{'name':'Travel &amp; Tourism','slug':'travel-and-tourism'}, {'name':'Human Resources','slug':'human-resources'}, {'name':'Massage Therapy','slug':'massage-therapy'}, {'name':'Hospitality','slug':'hospitality-management'}];
jE = [{'name':'Global Manager','slug':'global-management'}, {'name':'IT Manager','slug':'it-management'}, {'name':'Office Manager','slug':'office-administration-management'},{'name':'Restaurant Management','slug':'restaurant-management'}];
jC = [{'name':'Automotive Tech','slug':'automotive-technician'}, {'name':'Auditor','slug':'auditor'}, {'name':'Database Administrator','slug':'database-admin-management'}, {'name':'Accountant','slug':'accountant'}];

//{'name':'','slug':''}
profile_jobs = [{'letter':'R','jobs':jR}, {'letter':'I','jobs':jI}, {'letter':'A','jobs':jA}, {'letter':'S','jobs':jS}, {'letter':'E','jobs':jE}, {'letter':'C','jobs':jC},];

/*
* Question Object
*
*/	
function Question(career_type, text)
{
	var self = this;
	var text = text;
	var career_type;
	var response;
	//#
	 self.get = function()
	{
		return text;
	}
	//#
	self.answer = function(user_response)
	{
		response = user_response;
		return true;
	}
	//#
	self.get_response = function()
	{
		return response;
	}
	
	self.get_response_type = function()
	{
		return career_type;
	}
}

/*
*
* Career Test Manager.
* Manages the start, flow, and results of a Career Test.
* load -> start -> show questions.
*/
var CareerTest = {
	qpos : 0,
	question_bucket : new Array(),
	profile_letters : {'R':0, 'I':0, 'A':0, 'S':0, 'E':0, 'C':0},
	load_questions: function(questions)
	{
		for(var i in questions)
		{
			q = new Question(questions[i]['career_type'], questions[i]['question'])
			CareerTest.question_bucket.push(q);
		}
		
		CareerTest.question_bucket = shuffle(CareerTest.question_bucket);
		
	},
	start : function()
	{
	    
		//#activate google analytics
	    if(window.pageTracker) {
            pageTracker._trackEvent("CareerFinder", "Questions", "Start");
        }

	    $('#begin-finder-btn').fadeOut();
	    $('#finder-intro').fadeOut(function(){
	        
	        CareerTest.show_question();
	    })
		
	},
	finish : function()
	{
		
		//#activate google analytics
	    if(window.pageTracker) {
            pageTracker._trackEvent("CareerFinder", "Questions", "Finish");
        }

	    out = '<div id="results-finder-btn" style="margin: 30px 0 0 0; text-align: center; display: none;"><a href="#"><img src="/images/careerfinder/btn_results.png" class="show-my-results" /></a></div>';
		$('#bottom').html(out);
		
		
		$('.question').hide();
		$('#finder-intro').hide();
		$('#finder-results').show();
		$('#results-finder-btn').show();
		
		//# because of IE5 I have to shove the image in . . .
		
		
		for(var i in CareerTest.question_bucket)
		{
			CareerTest.question_bucket[i].get_response()
			r = CareerTest.question_bucket[i].get_response()
			if(r == 1)
			{
				t =  CareerTest.question_bucket[i].get_response_type();
				CareerTest.profile_letters[t]++
				letter = CareerTest.profile_letters[t];
			}
		}
		
		CareerTest.do_assessment();
		
		return true;
	},
	do_assessment : function(response)
	{
		//# show processing notice
		//#calculate.
		var high_letter = 0;
		var high_number = 0;
		for(var i in CareerTest.profile_letters)
		{
			l = CareerTest.profile_letters[i];
			if(l > high_number)
			{
				high_letter = i;
				high_number = l;
			}
		}
		
		//#delay for realism!
		$('#results-finder-btn').click(function(){
		    $('#results-display').show();
		    $('#bottom').hide();
		    
		    CareerTest.display_results(high_letter)
		})
		
	},
	display_results : function(profile_letter)
	{
		//#activate google analytics
	    if(window.pageTracker) {
            pageTracker._trackEvent("CareerFinder", "Questions", "Show Results");
        }
		
		for( var i in profile_jobs)
		{
		    if(profile_jobs[i]['letter'] == profile_letter)
		    {
		        jobs = profile_jobs[i]['jobs']
		    }
	    }
	    
		$(jobs).each(function(i, v){
		    if(i == 0)
		    {
		       $('#best-match-name').html(this['name'])
		       CareerTest.top_career_id =  this['programID'];
		    }
		    
		    out += '<div class="career"><a href="/careers/'+this['slug']+'" target="_blank">'+this['name']+'</a></div>'; 
		    
			//out += '<div class="career"><a href="/careers/school-search/?programID='+this['programID']+'&zipCode='+CareerTest.zipcode+'" target="_blank">'+this['name']+'</a></div>'; 
			//out += '<div class="career"><a href="/careers/school-search/?programID='+this['programID']+'" target="_blank">'+this['name']+'</a></div>'; 
		});
		
		$('#career-options').html(out);
		pT = profile_types[profile_letter];
		$('#finder-results').fadeOut(function(){
		    $('#finder-results').html("<h2>You are "+profile_types[profile_letter]["type"]+"</h2>");
		    $('#finder-results').fadeIn(function(){
    		$('#type-profile').html(profile_types[profile_letter]["description"])
    		$('#results').slideDown()
		    });
		});
		
	},
	show_question : function()
	{
		//#activate google analytics
	    if(window.pageTracker) {
            pageTracker._trackEvent("CareerFinder", "Questions", "View Question : "+CareerTest.qpos);
        }

		$('#spinner').hide();
		$('.question').fadeIn();
		bucket_len = CareerTest.question_bucket.length;
		if(bucket_len > CareerTest.qpos) {
			q = CareerTest.question_bucket[CareerTest.qpos];
			$('#question_text').html(q.get());
		
		    r = '<a href="#"><img src="/images/careerfinder/yes.png" alt="yes" width="108" height="39" class="yes-btn" id="yes-btn-'+CareerTest.qpos+'"/></a>';
    		r += '<a href="#" ><img src="/images/careerfinder/no.png" alt="no" width="90" height="39" class="no-btn" id="no-btn-'+CareerTest.qpos+'" class="no"/></a>';
    		
    		$('#question_number').html(CareerTest.qpos + 1)
			$('#answers').html(r);
			$('#yes-btn-'+CareerTest.qpos).hover( 
              function() { $(this).attr('src', '/images/careerfinder/yes_active.png'); },
              function() { $(this).attr('src', '/images/careerfinder/yes.png'); } 
             );
             $('#no-btn-'+CareerTest.qpos).hover( 
              function() { $(this).attr('src', '/images/careerfinder/no_active.png'); },
              function() { $(this).attr('src', '/images/careerfinder/no.png'); } 
             );
             
			$('#no-btn-'+CareerTest.qpos).click(function(){
				$('.question').fadeOut(function(){
				    $('#spinner').show();
				});
				
				q.answer(0);
				setTimeout(function(){
					CareerTest.show_question();
				}, 700)
				return false;
			});
			$('#yes-btn-'+CareerTest.qpos).click(function(){
				$('.question').fadeOut(function(){
				    $('#spinner').show();
				});
				q.answer(1);
				setTimeout(function(){
					CareerTest.show_question();
				}, 700)
				return false;
			});
			CareerTest.qpos++;
		} else {
			CareerTest.finish()
		}
	}
}

shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};

