
//category select
$(document).ready(function(){	
	
	var changedSpecialSelect = false;
	//hide as default - if category is not 'Bemanning'
	
	/*
	if( $('#worker').attr('checked') == undefined && $('#employer').attr('checked') == undefined )
	{
		$('#the-rest').hide();
	}
	
	
	$('#worker').click(function() {
		$('#the-rest').show();
		$('#title-p').hide();
		$('#company-p').hide();
		$('#birthyear-p').show();
		$('#length_of_service-p').hide();
		this.blur();
		
		$("#business").children("option").each( function() { //only show Bemanning and Rekrytering when a worker
			if ( $(this).val() > 2 )
			{
				$(this).hide();
			}
		})
		
		$('#label-message').html('Beskriv dig sj&auml;lv kortfattat; dina meriter, &aring;r i branschen, mm:*');
	});
	
	$('#employer').click(function() {
		$('#the-rest').show();
		$('#title-p').show();
		$('#company-p').show();
		$('#birthyear-p').hide();
		this.blur();
		
		$("#business").children("option").show();	//show all options in business
		$('#label-message').html('Beskrivning av tj&auml;nsten, krav p&aring; kandidaten, mm*');
	});
	*/
	
	if( $('#business').val() != 1 ) {
		$('#length_of_service-p').hide();
		$('#hours-p').hide();
	}

	var revert = $('#speciality').html();
	
	//setting the specialities from what category you choose
	$('#category').change(function() {
		if($('#category').val() == "") { //if choosing the top value, revert to original html code 
			$('#speciality').html('<option id="blaj">'+revert); //had to do a work-around for IE, since it removed the first '<option>'-tag
			$('#blaj').remove();
			changedSpecialSelect = false;
		}
		else {
			$('#speciality').html('<option value="" selected="selected"> - V&auml;lj yrke - </option>');
			for(i=0; i < (category[$('#category').val()].length); i++) {
				$('#speciality').append('<option value="'+ category[$('#category').val()][i]['speciality_id'] +'">'+ category[$('#category').val()][i]['speciality'] +'</option>');
			}
			changedSpecialSelect = true;
		}
		$('#speciality option:eq(0)').attr('selected','selected'); //make the first option of speciality selected
		
	});
	
	$('#speciality').change(function() {
		if(!changedSpecialSelect) { //ok, provided that I haven't selected a category..
			var categoryArrPos = speciality[ $('#speciality').val() ]; 
			$('#category option:eq('+ categoryArrPos +')').attr('selected','selected'); //.. I make the right category selected depending on what speciality I pick
		}
	});
	
	$('#business').change(function() {
		if( $('#business').val() == '1' || $('#business').val() == '2' ) { //if Bemanning, show length of service
			$('#hours-p').show();
			if( $('#business').val() == '1' /* && $('#employer').attr('checked') == true */ )
			{
				$('#length_of_service-p').show();
			}
			else {
				$('#length_of_service-p').hide();
			}
		}
		
		else {
			$('#length_of_service-p').hide();
			$('#hours-p').hide();
		}
	});

	$('#leadHeader').click(function() {
		toggleForm();
	});

	$('#memberHeader').click(function() {
		if( $('#worker').attr('checked') == true || $('#employer').attr('checked') == true )
		{
			toggleForm();
		}
	});

	$('#contact').after('<a id="onwards" class="btnSmall" href="#" onClick="this.blur(); return toggleForm();">G&aring; vidare &raquo;</a>');
	$('#mandatory').prepend('<a class="btnSmall" href="#" onClick="this.blur(); return toggleForm();">&laquo; G&aring; tillbaka</a>');

	if(!errorOnlyInLeadForm) { //this variable is set in /inclues/inc-form.php
		$('#leadHeader').append('<div id="arrowLead" class="arrow arrowDown"></div>');
		$('#memberHeader').append('<div id="arrowMember" class="arrow arrowRight"></div>');
		$('#memberForm').hide();
	}
	else {
		$('#leadHeader').append('<div id="arrowLead" class="arrow arrowRight"></div>');
		$('#memberHeader').append('<div id="arrowMember" class="arrow arrowDown"></div>');
		$('#leadForm').hide();	
	}
	
	//the height is set in the css to 580px so that without javascript the form won't overlap the foot 
	$('#form').css("height", "290px"); 

});


/*** 		FUNCTIONS	 	**/
function toggleLengthOfServiceVisibility(_state) {
		$('#length_of_service').css({ visibility:_state });
		$('#label_length_of_service').css({ visibility:_state });
}


function toggleForm() {
	$('#leadForm').slideToggle(1000);
	$('#arrowLead').toggleClass('arrowDown');
	$('#arrowLead').toggleClass('arrowRight');

	$('#memberForm').slideToggle(1000);
	$('#arrowMember').toggleClass('arrowDown');
	$('#arrowMember').toggleClass('arrowRight');
	
	return false;
}