// JavaScript Document

// JavaScript Document
$('document').ready(function(){init();

});

function init(){
	$('#body #content .featured.find_tutor ul').jScrollPane({showArrows:true, arrowSize: 15});
	
	//init autocomplete for live search button
	var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax Utilities".split(" ");
	var availableTags = ["ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme"];
		$("#live_search_input").autocomplete({
			source: availableTags
		});
	
	//initialize dissapearing labels inside text input(s)
	initGhostLabels();
	
	//initaialize tabs
	$('#why_fox_tuition').tabs();
    
    $("#accordion_general").accordion({ autoHeight: false });
	$("#accordion_general" ).accordion({ collapsible: true });
	$("#accordion_general" ).accordion({ active: false });

    $("#accordion_questions").accordion({ autoHeight: false });
	$("#accordion_questions").accordion({ collapsible: true });
	$("#accordion_questions").accordion({ active: false });
    $("#accordion_questions").hide();
    
    $("#faq_general_link").click(function(){
        $("#accordion_general").show();
        $("#accordion_questions").hide();
        $("#faq_general_link").addClass('faq_menu_active');
        $("#faq_questions_link").removeClass('faq_menu_active');
    });
    $("#faq_questions_link").click(function(){
        $("#accordion_general").hide();
        $("#accordion_questions").show();
        $("#faq_general_link").removeClass('faq_menu_active');
        $("#faq_questions_link").addClass('faq_menu_active');
    });
    
    init_testimonials();
}

function init_testimonials(){
	textElement = $('#accordion_review p.text');
	textElement.each(function(){
		fullText = $(this).text();
		$(this).attr('title', fullText);
		text = $(this).text().substring(0,200);
		$(this).text(text + '...');
		$('div.review_element').find('button').html('READ ALL');
		
		$(this).parent().find('.action').toggle(function(){
			textElement = $(this).parent().find('p.text');
			$(this).parent().find('button').html('READ LESS');
			$(this).parent().find('img').hide();
			$(this).parent().removeClass('min');
			$(this).parent().addClass('max');
			textElement.text(textElement.attr('title'));
		},
		function(){
			textElement = $(this).parent().find('p.text');
			textElement.text(textElement.attr('title'));
		
			text = textElement.text().substring(0,200);
			textElement.text(text + '...');
			
			$(this).parent().find('button').html('READ ALL');
			$(this).parent().find('img').show();
			$(this).parent().removeClass('max');
			$(this).parent().addClass('min');
		}
		);
	});
}

function maximize(){
    $('div.review_element').find('img').hide();
}

//initialize inputs with inside label that dissapears on focus, then and input gets "active" class
//works for all text inputs with class "ghost_labelled"
function initGhostLabels(){
	//add ghost label behaviour to all inputs with class 'ghost_labelled'
	var ghost_labelled = $('input.ghost_labelled');
	ghost_labelled.each(function(){
		if($(this).val() == ''){
			$(this).get(0).value = $(this).get(0).defaultValue;
			$(this).removeClass('active');
		}
		else if($(this).val() != $(this).attr('defaultValue')){
			$(this).addClass('active');
		}
		$(this).bind('focus', function(e){
											  if($(this).get(0).value == $(this).get(0).defaultValue){
												$(this).get(0).value = '';
												$(this).addClass('active');
											  }
										  });
		$(this).bind('blur', function(e){
											  if($(this).get(0).value == ''){
												$(this).get(0).value = $(this).get(0).defaultValue;
											  	$(this).removeClass('active');
											  }
										  });
	});
}
