/* Author: Andrew Nickerson

*/

$(document).ready(function(){
	  $("#contactFormWraper label").inFieldLabels();
	
	
	var navItems = $('#mainNav li p, #mainNav li a:not(#mainNav ul.secondLevelNav li a)');
	var pageTitle = $('#pageTitle').html()
	$(navItems).each(function(){

		if($(this).html() == pageTitle){

			$(this).addClass("active");
		}
	});
	

$('#twitter_update_list a').attr('target', '_blank');
});
	function captchaCheck(elem, helperMsg){
		$('.quoteError').remove();
		helperMsg = '<div class="quoteError" ><div class="notice" ><h4>'+helperMsg+'</h4></div></div>';
		if($(elem).val() !== '30'){
			$('#contactFormWraper').prepend(helperMsg);
			$(elem).focus(); // set the focus to this input
			return false;
		}
	}



/* USed on the opportunities page */
function unique(vals){
			    var vals = vals;
			    var uniques = [];
			    for(var i=vals.length;i--;){
			        var val = vals[i];  
			        if($.inArray( val, uniques )===-1){
			            uniques.unshift(val);
			        }
			    }
			    return uniques;
			} 








	function categorySort(defaultCat, xmlLoaded){
				
				if(xmlLoaded != ''){
					$('#opportunitiesList li').hide(); 			
					var categories = new Array();
					$('#opportunitiesList li').each(function(){
						var currentCategory = $(this).find('h4.category').html();
						console.log(currentCategory);	
						categories.push(currentCategory);
					});
					
					
					categories = (unique(categories));
					
					for(i in categories){
					    var currentCategory = categories[i];
				    
				   
					    $('<span class="filter" data-category="'+currentCategory+'">'+currentCategory+'</span>').appendTo('#filters').each(function(){
					    	$(this).click(function(){
					    		var clickedCategory = $(this).data('category');
							    	$('#opportunitiesList li').fadeOut('200');
							    	$('#filters .filter').removeClass('active');
						    		
						
						    		$('#opportunitiesList li').each(function(){
						    			if($(this).find('.category').html() == clickedCategory){
						    				$(this).delay('300').fadeIn();
						    			}
						    		});
						    	
						    		$(this).addClass('active');
						    	
						    	
			
							});
					    
					    });
						
					}
					if(defaultCat){
						$('#opportunitiesList li').each(function(){
			    			if($(this).find('.category').html() == defaultCat){
			    				$(this).fadeIn();
			    			}
			    		});
			    		$('#filters .filter').each(function(){
			    			if($(this).html()== defaultCat ){
			    				$(this).addClass('active');
			    			}
			    		});
					}
				}else{
					$('#contentColumn').append('<p>To view the available opportunities please <a href="javascript:this.location.reload();">Reload the page</a></p>');
				}
				
		}





