// jQuery setup stuff
$(window).resize( function() { jQuery.fn.positionBar(); } );
//jQuery.fn.positionBar();

// colorize ative #areanav link
	$(function(){ if (location.pathname.substring(1))
			//							  alert(location.pathname.substring(1));
  		$('#areanav a[@href$="' + location.pathname.substring(1) + '"]').addClass('selectedlink'); //alert('i am')//$('#areanav a[@href$="' + location.pathname.substring(1) + '"]').attr('class', 'selectedlink')
		//$('#areanav a').fadeOut(1500);
	});
	


 $(document).ready(function(){
	// ------------------ fix height of sidebar	
	jQuery.fn.setupDS();
	jQuery.fn.setupforms();
	//jQuery.fn.setupCareerforms();
	jQuery.fn.positionBar();
	jQuery.fn.styleMenu();
	$("#formtrigger").mouseup( function() { 
										
		//alert("Hello"); 
		$("#formtrigger").hide();
		jQuery.fn.setupCareerforms();
										
	} );
	
	
	
	// randomize column image
	var backImageClass = 'backimage' + jQuery.fn.get_randomNum();
	$("#thecolumn").addClass(backImageClass);
	//alert(backImageClass);
	
	
	// position bar
	jQuery.fn.positionBar();
	$('body').dblclick(function(){
		
		jQuery.fn.positionBar();
	});
	
	$(document).trigger("resize");
	

});


jQuery.fn.get_randomNum = function () {
    		var ranNum= Math.floor(Math.random()*7);
    		return ranNum + 1;
}//

jQuery.fn.styleMenu = function() {

}//
	
jQuery.fn.setupDS = function() {

	jQuery.fn.positionBar();
	
	  
	  // ----------------  SUCKERFISH STYLE NAV
	  $("#nav-oneX li").hover(
				//function(){ $("ul", this).fadeIn("normal", function(){	//$("#areanav").hide(); 	}) }, 
				function(){},
				function() {
				
				
				} 
			);
	  	if (document.all) {
				$("#nav-one li").hoverClass ("sfHover");
			}
	  }
	  
	  $("#nav-oneX li li").hover(function(){}, function(){});
	  
		$.fn.hoverClass = function(c) {
			return this.each(function(){
				$(this).hover( 
					function() { $(this).addClass(c);  },
					function() { $(this).removeClass(c); }
				); 
			});
			
		

	
};




jQuery.fn.positionBar = function() {

		var docH = $(document).height();
		//var docH = $("html").height();
		var winH = $(window).height();
		if(docH > winH){
			var foundHeight = docH;
		}else{
			var foundHeight = winH;
		}
		
		// fix height
		$("#thecolumn").height(foundHeight + "px");
		
		var leftpoint = $("#pagetitle").offset().left + 495;	
	  	$("#thecolumn").css("right", "auto");
	  	$("#thecolumn").css("left", leftpoint+"px");
	  
	  
		
};

jQuery.fn.setupforms = function() {
	
	$('#positionlistings .posting h4X').css('cursor','pointer');
	$('#positionlistings .posting .appform').css('cursor','pointer');
	
	
	
	$("#positionlistings .posting .appform").hide();
	$("#positionlistings .posting h4X").click(
	
		function(){
			$(".posting").removeClass('posting-active');
			//$(this).parent(".appform").show();
			$("#positionlistings .posting .appform").hide('slow');
			$("#positionlistings .posting .expand").show();
			
			
			
			$(this).prev().hide();
			$("#positionlistings .posting .expand").show();
			$(this).next().next().show('slow');
			
			$(this).parent().addClass('posting-active');
			//alert('you clicked me');
		}
	);
	
	// Resume upload on contact page
	$('#resumeupload').css('cursor','pointer');
	$('#resumeupload label').css('cursor','pointer');
	$('#resumeupload').addClass('rescollapsed');
	$('#resumeupload input').hide();
	$('#resumeupload').click(
		function(){
			$('#resumeupload input').show("normal");
			$('#resumeupload').addClass('resexpanded');
			$('#resumeupload').removeClass('rescollapsed');
		
		}
	);
	
	
	
	
	
	$("#positionlistings .posting .expand").click(
		function(){
			$(".posting").removeClass('posting-active');
			//$(this).parent(".appform").show();
			$("#positionlistings .posting .appform").hide('slow');
			$("#positionlistings .posting .expand").show();
			
			
			$(this).parent().addClass('posting-active');
			$(this).hide();
			$(this).next().next().next().show('slow');
			//alert('you clicked me');
		}
	);
}

jQuery.fn.collapseCareerforms = function() {
	$(".position-expanded").hide("slow");
	$(".position-expanded").removeClass("position-expanded");
	
	$(".position-collapsed").show("slow");
	$(".position-collapsed").removeClass("position-collapsed");
		
}


jQuery.fn.setActiveStep = function(stepName) {
	var StepClass = '.' + stepName + ' .steplabel';
	//alert(StepClass);
	
	// unsett all
	$(".steplabel").removeClass('active-step');
	$('.instruction').hide();
	$(StepClass).addClass('active-step');
	$(StepClass + ' .instruction').show();
	jQuery.fn.positionBar();		
							
		
		
	
}


jQuery.fn.setupCareerforms = function() {
	$("#submitbuttons").empty();// get rid of the submit buttons.  they are no longer needed
	// re-write label for step 3
	$("tr.row-positionsavailable .steplabel").empty();// empty it
	$("tr.row-positionsavailable .steplabel").html('Available Positions<span class="instruction"> - choose a position below</span>');
	//$("tr.row-positionsavailable .step").html('<div>Weeeeee</div>');// area to place found positions
	
	$('.row-positionsavailable .position-form').hide();
	$('#positionlistings .posting h4X').css('cursor','pointer');
	$('#positionlistings .posting .appform').css('cursor','pointer');
	jQuery.fn.setActiveStep('row-positiontype');
	$('.step').hide();// hide next steps initially
	
	$(".row-positiontype input").mouseup(
		function(){
			$(".row-positiontype li a").removeClass("selectedtab");
			$(this).addClass("selectedtab");
			$(".row-industrytype .step").hide();
			$(".row-positionsavailable .step").hide();
			
			
			$(".row-industrytype .step").show("slow",function(){
										jQuery.fn.positionBar();		
								});
			
			jQuery.fn.setActiveStep('row-industrytype');
			
			// add ajax to pull in data
			
			
			
			
			
			
			
			
		}
	);
	
	$(".row-industrytype input").click( 
		function() { 
			$(".row-positionsavailable .step").hide();
			$(".row-positionsavailable .step").show("slow",function(){
										jQuery.fn.positionBar();		
								}); 
			jQuery.fn.setActiveStep('row-positionsavailable');
			
			
			// hide everything else
			$("tr.row-positionsavailable .step #results").hide();
			$("tr.row-positionsavailable .step #results").empty();
			$("tr.row-positionsavailable .step #preloader").html('<p>loading results...</p>');
			$("tr.row-positionsavailable .step #preloader").show();
			
			// get info from form
			positionType = $("#defaultform");//"1";
			industryType = "1";
			randNumber = Math.random();
			
			//alert('positionType:: '+positionType);
			var varString =  $("input[@type=radio][@checked]").serialize();
			
			$.ajax({
			  type: "GET",
			  url: "cf_getPositionsDynamic.asp",
			  data: varString+'&action=getPositions',
			  success: function(msg){
				//alert( "Data Saved: " + msg );
				$("tr.row-positionsavailable .step #preloader").hide();
				$("tr.row-positionsavailable .step #results").html(msg);// area to place found positions
				$("tr.row-positionsavailable .step #results").show("slow",function(){
						 jQuery.fn.positionBar();
				});	
				//alert(':'+varString);
				jQuery.fn.formatCareerResults();
			  }
			});
			
			
			
			
			
		}
	);
	
	//$("form input").filter(":radio, :checkbox");
	
	
	$('.row-positionsavailable .position-viewfull').hide();
	$('.row-positionsavailable .position-viewfull').unbind();
	$('.row-positionsavailable .position-viewfull').removeAttr("href");
	$('.row-positionsavailable .position-viewfull').css('cursor','pointer');
	$('.row-positionsavailable .position-viewfull').click(
		function(){
			//
			
			$(this).hide();
			$(this).addClass("position-collapsed");
			
			$(this).next().show("slow",function(){
										jQuery.fn.positionBar();		
								});
			$(this).next().addClass("position-expanded");
			$(this).next().removeClass("hiddenelement");
			
		}
		
	);
	
	
	
	$('.row-positionsavailable .position-moreinfo').removeClass("hiddenelement");
	$('.row-positionsavailable .position-moreinfo').show();
	$('.row-positionsavailable .position-moreinfo').removeAttr("href");
	$('.row-positionsavailable .position-moreinfo').css('cursor','pointer');
	$('.row-positionsavailable .position-moreinfo').click(
		function(){
			jQuery.fn.collapseCareerforms();
			
			$(this).next().removeClass("hiddenelement");
			$(this).next().show("slow",function(){
										jQuery.fn.positionBar();		
								});
			$(this).next().addClass("position-expanded");
			$(this).hide();
			$(this).addClass("position-collapsed");
			$(this).prev().find(".position-viewfull").show();
			$(this).prev().find(".position-viewfull").addClass("position-expanded");
			
			
		}
	);
	

}


jQuery.fn.formatCareerResults = function() {
	$('.row-positionsavailable .hiddenelment').hide();
	
	
	$('.row-positionsavailable .position-viewfull').hide();
	$('.row-positionsavailable .position-viewfull').unbind();
	$('.row-positionsavailable .position-viewfull').removeAttr("href");
	$('.row-positionsavailable .position-viewfull').css('cursor','pointer');
	$('.row-positionsavailable .position-viewfull').click(
		function(){
			//
			
			$(this).hide();
			$(this).addClass("position-collapsed");
			
			$(this).next().show("slow",function(){
										jQuery.fn.positionBar();		
								});
			$(this).next().addClass("position-expanded");
			$(this).next().removeClass("hiddenelement");
			
		}
		
	);
	
	
	
	$('.row-positionsavailable .position-moreinfo').removeClass("hiddenelement");
	$('.row-positionsavailable .position-moreinfo').show("fast");
	$('.row-positionsavailable .position-moreinfo').removeAttr("href");
	$('.row-positionsavailable .position-moreinfo').css('cursor','pointer');
	$('.row-positionsavailable .position-moreinfo').click(
		function(){
			jQuery.fn.collapseCareerforms();
			
			$(this).next().removeClass("hiddenelement");
			$(this).next().show("slow",function(){
										jQuery.fn.positionBar();		
								});
			$(this).next().addClass("position-expanded");
			$(this).hide();
			$(this).addClass("position-collapsed");
			$(this).prev().find(".position-viewfull").show();
			$(this).prev().find(".position-viewfull").addClass("position-expanded");
			
			
		}
	);
	
}
