
// NORMAL RULES

$(document).ready(function() {

// GLOBAL RULES

if(typeof document.body.style.maxHeight === "undefined") {
	var is_ie6 = true;
}
else {
	var is_ie6 = false;
}

	
	
if($("#container").hasClass("home")){

// HOME PAGE RULES

	// SLIDER
	// USER DEFINED VARIABLES 
	
	slide_width = -337;
	slides_shown = 3;
	
	popup_width = -1000;
	popups_shown = 1;
	
	slide_selector = '#button_slider li';
	slide_selector_container = '#button_slider';

	popup_selector = '#slider_popup li';
	popup_selector_container = 'ul#slider_popup';
	
	default_container = "#main_body";
	
	// BROWSER DEFINED VARIABLES
	
	slide_current = 1;
	popup_current = 1;
		
	pos_slide_width = slide_width * -1;
	pos_popup_width = popup_width * -1;
	
	slide_amount =  $(slide_selector).length;
	popup_amount =  $(popup_selector).length;	
	
	$(slide_selector).addClass("jq_slides");
	slide_container_width = slide_width * slide_amount;
	new_slide_container_width = slide_width * -1 * slide_amount;
	single_group_length = slide_width * -1 * slides_shown;
	new_slide_container_width = new_slide_container_width + single_group_length;
	$(slide_selector_container).css({'width':new_slide_container_width});

	popup_container_width = popup_width * popup_amount;
	new_popup_container_width = popup_width * -1 * popup_amount;
	single_group_length = popup_width * -1 * popups_shown;
	new_popup_container_width = new_popup_container_width + single_group_length;
	$(popup_selector_container).css({'width':new_popup_container_width});

	slide_duplicate_selector = slide_selector+':lt('+slides_shown+')'
	popup_duplicate_selector = popup_selector+':lt('+popups_shown+')'
	
	$(slide_duplicate_selector).clone().appendTo($(slide_selector_container));
	$(popup_duplicate_selector).clone().appendTo($(popup_selector_container));


    // SLIDER FUNCTIONS
	
	function slider(slide_current_overide) {
		if(slide_current_overide != "test"){
			if (slide_current_overide == "next") {
				slide_current = slide_current + 1;
				popup_current = popup_current + 1;
			}
			else if (slide_current_overide == "prev") {
				slide_current = slide_current - 1;
				popup_current = popup_current - 1;
			}
			else{
				if($(default_container).hasClass("init_click")){
					popup_current = slide_current_overide;
				}
				else {			
					slide_current = slide_current_overide;
					popup_current = slide_current_overide;
				}
			}
	
			if(slide_current == 0){
				$(slide_selector_container).animate({"left" : slide_container_width}, 0);
				slide_current = slide_amount;
			}
	
			if(popup_current == 0){
				$(popup_selector_container).animate({"left" : popup_container_width}, 0);
				popup_current = slide_amount;
			}
			
			slide_current_multiplier = slide_current - 1;
			popup_current_multiplier = popup_current - 1;
			
			left_slide_value = slide_current_multiplier * slide_width;
			left_popup_value = popup_current_multiplier * popup_width;
		
			
			if (slide_current_overide == "next") {
				//console.log("next subtract method");
				left_slide_value = '-='+pos_slide_width;
				left_popup_value = '-='+pos_popup_width;
			}
			if (slide_current_overide == "prev") {
				//console.log("next add method");
				left_slide_value = '+='+pos_slide_width;
				left_popup_value = '+='+pos_popup_width;
			}
			
			if(!$(default_container).hasClass('popup')){
				//console.log("manual slider");				
				$(popup_selector_container).animate({left : left_popup_value},{duration:0 });
				$(slide_selector_container).animate({left : left_slide_value},{duration:900 });
			}
			else {
				if ($(default_container).hasClass('init_click')) {
					//console.log("initial click popup");							
					//$(slide_selector_container).css({left : left_slide_value});
					$(popup_selector_container).css({left : left_popup_value});
				}
				else {
					//console.log("popup manual");							
					$(slide_selector_container).animate({left : left_slide_value},{duration:0 });
					$(popup_selector_container).animate({left : left_popup_value},{duration:900 });
				}
			}
			if (slide_current == slide_amount+1) {
				//console.log("manual slide infinity fix");							
				$(slide_selector_container).animate({"left" : "0"},0);
				//console.log("workinG?");											
				slide_current = 1;
			}
			if (popup_current == popup_amount+1) {
				//console.log("manual popup infinity fix");							
				$(popup_selector_container).animate({"left" : "0"},0);
				//console.log("workinG?");											
				popup_current = 1;
			}
		}
		else{
			if(slide_current == slide_amount+1){slide_current = 1};
			if(popup_current == slide_amount+1){popup_current = 1};


			slide_current = slide_current + 1;
			popup_current = popup_current + 1;
			
			slide_current_multiplier = slide_current - 1;
			popup_current_multiplier = popup_current - 1;
	
			left_slide_value = slide_current_multiplier * slide_width;
			left_popup_value = popup_current_multiplier * popup_width;
	
			if(!$(default_container).hasClass('popup')){
				//console.log("autoslide");
				$(slide_selector_container).animate({left : left_slide_value},{duration:900 });
				$(popup_selector_container).animate({left : left_popup_value},{duration:0 });
			}
			else {
				//console.log("autoslide popup");
				$(slide_selector_container).animate({left : left_slide_value},{duration:0 });
				$(popup_selector_container).animate({left : left_popup_value},{duration:900 });
			}
			if (slide_current == slide_amount+1) {
				//console.log("slide repeat fix");				
				$(slide_selector_container).animate({"left" : "0"},0);
				slide_current = 1;
			}
			if (popup_current == popup_amount+1) {
				//console.log("popup repeat fix");				
				$(popup_selector_container).animate({"left" : "0"},0);
				popup_current = 1;
			}
		}
	// console.log('popup_current:  '+popup_current);
	// console.log('slide_current:  '+slide_current);
	}

	function slider_class_compare () {
		if ($(default_container).hasClass("popup") && $(default_container).hasClass("init_click")) {
			$(default_container).removeClass("init_click");
			////console.log("removed init click");
		}
	}
		
	// SLIDER BUTTONS
		
	$("#what_else_btn").click( function(){
		//console.log("next click");							
		clearInterval(rotating);
		slider_class_compare ();
		slider("next");
		return false;
	});
	
	$("#back_it_up_btn").click( function(){
		//console.log("back click");							
		clearInterval(rotating);
		slider_class_compare ();
		slider("prev");
		return false;
	});
	
	$(slide_selector).click( function (index) {
		//console.log("slide click");
		slider_num = $(".jq_slides").index(this) + 1;
		if (slider_num > slide_amount) {
			//console.log("slide click infinity fix");
			slider_num = slider_num - slide_amount;
		}
		//console.log(slider_num);
		clearInterval(rotating);
		$(default_container).addClass("popup");
		$(default_container).addClass("init_click");
		//console.log("init_click added");		
		$(slide_selector_container).animate({top : "-364"}, 400, function () {
			slider(slider_num);
		});
		$("#slider_popup_container").delay(200).animate({bottom : "0"}, 400);
		return false;

	});
	$("#popup_close").click(function (){
		//console.log("popup close");											  
		$(default_container).removeClass("popup");
		$(default_container).removeClass("init_click");		
		$("#slider_popup_container").stop().animate({bottom : "-350"},400);
		$(slide_selector_container).stop().animate({top : "0"},{duration:400});	
		return false;
	});
	
	// SLIDER INTRAVAL 
	
	rotating = setInterval(function() {
		slider("test");
	},5000)
	
	
	// SLIDE HOVER 
	
	$("#button_slider li a").hover(
		function (){
			$(this).find("strong").animate({top : "-145"},500);
		}, 
		function(){
			$(this).find("strong").animate({top : "0"},500);
		}
	);
	
}
else {
// INTERIOR RULES

	container_height = $("#container").outerHeight();
	$("#eye_candy_container").css({"height":container_height})

	//  ACCORDIAN RULES
	
	$("#accordian div").hide();
	
	$("#accordian h3").live("click",function() {
	  $(this).toggleClass("on");
	   if($(this).hasClass("on")) {
		$(this).next().slideDown();
		} 
	   else {
		$(this).next().slideUp();
	   }
	 });
	
	$("#accordian h3, #accordian h3 strong").each(function() {
		$(this).data("orig_height",$(this).height());
		$(this).css({height:$(this).data("orig_height")});
	});	
	
	
	// BUILD YOUR OWN SOLUTION TOGGLE

	liberty_solutions_val = ", Exceptional Service , Human Touch , Fresh Approach , Real Value , Rapid Turnaround , Innovation ";
	your_needs_val = ", Employment Screening ";

	$('#liberty_solutions_feild').attr({ value: liberty_solutions_val });
	$('#your_needs_feild').attr({ value : your_needs_val });				

	$(".build_your_own_solution_list li a").click(function() {
		$(this).toggleClass("toggled");
		solution_list_value = $(this).attr("title");
		solution_list_value = ", "+ solution_list_value +" ";
		//console.log(solution_list_value);
		if($(this).hasClass("toggled")){
			if($(this).hasClass("liberty_solutions")){	
				liberty_solutions_val = liberty_solutions_val + solution_list_value;
				$('#liberty_solutions_feild').attr({ value: liberty_solutions_val });
			}
			else {
				your_needs_val = your_needs_val + solution_list_value;
				$('#your_needs_feild').attr({ value : your_needs_val });				
			}
		}
		else{	
			if($(this).hasClass("liberty_solutions")){
				liberty_solutions_val = liberty_solutions_val.replace(solution_list_value,"");				
				$('#liberty_solutions_feild').attr({ value: liberty_solutions_val });
			}
			else {
				your_needs_val = your_needs_val.replace(solution_list_value,"");				
				$('#your_needs_feild').attr({ value : your_needs_val });				
			}
		}
		//console.log("liberty_solutions_val :" + liberty_solutions_val);
		//console.log("your_needs_val :" + your_needs_val);
		return false;
	});
	

	// FORM RULES 
	
	//$("#contact_form p:odd").css("background-color","#f6f6f6");
	
	applicant_other = "null";
	$(".form_menu").not(':button, :submit, :reset, :hidden').val('').removeAttr('checked');
	$(".form_menu").change(function() {
		if($(this).val() == "please_choose"){
			//console.log($(this).val());
			alert("please choose what you are!");
			applicant_other = "null";
		}
		if($(this).val() == "client"){
			//console.log($(this).val());
			$("#interested_feilds, #applicant_other_feilds").hide(800);
			$("#current_client_feilds").show(800);
			applicant_other = "null";
		}
		if($(this).val() == "interested"){
			//console.log($(this).val());
			$("#current_client_feilds, #applicant_other_feilds").hide(800);
			$("#interested_feilds").show(800);
			applicant_other = "null";
		}
		if($(this).val() == "applicant"){
			//console.log($(this).val());
			if (applicant_other == "null" ) {
				$("#current_client_feilds, #interested_feilds").hide(800);
				$("#applicant_other_feilds").show(800);
				applicant_other = "set";
			}
		}
		if($(this).val() == "other"){
			//console.log($(this).val());
			if (applicant_other == "null" ) {
				$("#current_client_feilds, #interested_feilds").hide(800);
				$("#applicant_other_feilds").show(800);
				applicant_other = "set";
			}
		}
	});
	
	$("#previous_inquiry_yes").change(function() {			
		if($(this).is(":checked")){
			$(".inquiry_when input").css("background-color", "#ffffff");
			$(".inquiry_when input").removeAttr("disabled").focus();
			$(".inquiry_when label").css("color","#6a6a6a");
			//console.log('this is working');
		}
	});
	
	$("#previous_inquiry_no").change(function() {			
		if($(this).is(":checked")){
			$(".inquiry_when input").css("background-color", "#f3f3f3");
			$(".inquiry_when input").attr("disabled", "disabled");
			//$(".inquiry_when input").clearForm();
			$(".inquiry_when label").css("color","#dcdcdc");
			//console.log('this is working');
		}
	});
	
	
	var count = 10;
	countdown = setInterval(function(){
	$("#timer").html("Please wait " + count + " seconds before you submit!");
	if (count == 0) {
		$('#timer').remove();
		$("#sumbmit_container").html('<a href="#" class="submit_button "><span>Submit</span></a>');
		$(".submit_button").fadeIn('slow');
	}
	count--;
	}, 1000);
	$("a.submit_button").live('click', function() {
			$(this).parents("form").submit();
			return false;
	});
	
	
	// BUILD YOUR OWN SOLUTIONS SUBMIT BUTTON

	var solution_count = 10;
	solution_countdown = setInterval(function(){
	$("#solution_timer").html("Please wait " + count + " seconds before you may submit!");
	if (count == 0) {
		$('#solution_timer').remove();
		$("#solution_submit_container").html('<a id="build_it_now_link" href="#"><img src="/images/misc_elements/build_it_now_button.jpg"></a>');
		$("#build_it_now_link").fadeIn('slow');
	}
	solution_count--;
	}, 1000);
	$("a#build_it_now_link").live('click', function() {
		$("#build_your_solution_form").submit();
		return false;	
	});
	
	
	// POSITION FIXED MADNESS
	
	function pos_fixed_footprint () {
		var body_width = $('body').width()
		var abs_postion_right = body_width - 1000;
		var abs_postion_right = abs_postion_right / 2;
		if (is_ie6 === true || body_width <= 1000){
			$('a#flair_slider ').css({'position':'absolute', 'top': '589px', 'right': abs_postion_right});
		}else {
			$('a#flair_slider ').css({'position':'fixed', 'top:': '589px', 'right': abs_postion_right});
		}
	}; 
	pos_fixed_footprint ();
	$(window).bind("resize", pos_fixed_footprint);
	
}
});



