// NORMAL RULES

$(window).scroll(function(){
	if($("#events_sidebar_showcase_link").hasClass("sidebar_ads") || $("#jobs_sidebar_showcase_link").hasClass("sidebar_ads") || $("#press_sidebar_showcase_link").hasClass("sidebar_ads") || $("#testimonials_sidebar_showcase_link").hasClass("sidebar_ads")){
		min_scroll_offset  = $.data(document.body, 'sidebar_offset');
		footer_offset = $("#footer").offset();
		max_scroll_offset = footer_offset.top - $(".sidebar_ads").height() - 20;
		current_scroll = $(window).scrollTop();		
		sidebar_abs_pos = max_scroll_offset - 387;
		if(current_scroll > min_scroll_offset) {
			if (current_scroll > max_scroll_offset ){
				scrollstate = "abs"
				$(".sidebar_ads").css({position:'absolute', top:sidebar_abs_pos});
			}
			else {
				scrollstate = "fixed"
				$(".sidebar_ads").css({position:'fixed', top:'0'});
			}
		}
		else {
			$(".sidebar_ads").css({position:'static', top: 'auto'});
		}

	}
});


$(document).ready(function() {						   
	// CALCULATE AND STORE INITIAL AD OFFSET
	
	sidebar_offset = $(".sidebar_ads").offset();
	if($("a").hasClass("sidebar_ads")){
	$.data(document.body, 'sidebar_offset', sidebar_offset.top);
	}
	$('#navigation li a').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
						$('.dropdown').hide();
						dd_name = $(this).attr("id");
						dd_name = dd_name.replace("_link","_dd");
						dd_selector = "div#"+dd_name;
						$(dd_selector).show();
		}
	});
	
	$("#navigation_container").hover(
		function (){},
		function (){
			$('.dropdown').hide();
		}
	);


	function fancybox_ajax(){
	// FANCYBOX RULES
	
		$("a.fancy_testimonial").fancybox({ 
			'padding':		0,
			'type':  		'iframe',								
			'width': 		625,
			'height': 		350,
			'speedIn': 		100,
			'speedOut': 	100,
			'transitionIn': 'elastic',
			'transitionOut': 'elastic',
			'easingIn': 	'easeInSine',
			'easingOut': 	'easeOutSine',
			'titleShow' : false
		}); 
		
	}

	
	// AUTOSLIDER FUNCTION 	
	
function auto_slider(slide_distance, slides_shown, slide_selector, slide_selector_container, slide_speed, slide_pause, direction, override) {
	
	// BROWSER DEFINED VARIABLES	
	if(override == false){
		slide_amount =  $(slide_selector).length;
		slide_container_size = slide_distance * slide_amount;
		single_group_length = slide_distance * slides_shown;
		slide_container_size = slide_container_size + single_group_length;
		if(direction == "up" || direction == "down"){
			$(slide_selector_container).css({'height':slide_container_size});
		}
		if(direction == "left" || direction == "right"){
			$(slide_selector_container).css({'width':slide_container_size});
		}
		slide_duplicate_selector = slide_selector+':lt('+slides_shown+')'
	
		$(slide_duplicate_selector).clone().appendTo($(slide_selector_container));

		$(slide_selector_container).data('slide_current', 1);
		if(direction == "up"){
			$(slide_selector_container).animate({"top" : 0},0);
		}
		if(direction == "down"){
			$(slide_selector_container).animate({"bottom" : 0},0);
		}
		if(direction == "right"){
			$(slide_selector_container).animate({"right" : 0},0);
		}
		if(direction == "left"){
			$(slide_selector_container).animate({"left" : 0},0);
		}
		fancybox_ajax();
	}
	
	// SLIDER FUNCTIONS
function slider(slide_distance, slides_shown, slide_selector, slide_selector_container, slide_speed, slide_pause, direction, override) {
		slide_current = $(slide_selector_container).data('slide_current');
		slide_amount =  $(slide_selector).length - slides_shown;
		if(slide_current == slide_amount+1){slide_current = 1};
		slide_current = slide_current + 1;
		slide_current_multiplier = slide_current - 1;
		$(slide_selector_container).data('slide_current', slide_current);
		annimate_slide_value = slide_current_multiplier * slide_distance * -1;			
		if(direction == "up"){
			$(slide_selector_container).animate({top : annimate_slide_value},{duration:slide_speed });
		}
		if(direction == "down"){
			$(slide_selector_container).animate({bottom : annimate_slide_value},{duration:slide_speed });
		}
		if(direction == "left"){
			$(slide_selector_container).animate({left : annimate_slide_value},{duration:slide_speed });
		}
		if(direction == "right"){
			$(slide_selector_container).animate({right : annimate_slide_value},{duration:slide_speed });
		}
		if (slide_current == slide_amount+1) {
			if(direction == "up"){
				$(slide_selector_container).animate({"top" : "0"},0);
			}
			if(direction == "down"){
				$(slide_selector_container).animate({"bottom" : "0"},0);
			}
			if(direction == "left"){
				$(slide_selector_container).animate({"left" : "0"},0);
			}
			if(direction == "right"){
				$(slide_selector_container).animate({"right" : "0"},0);
			}
			slide_current = 1;
			
		}
		if(override == false){
			$(slide_selector_container).parent("div").addClass("initiated");
		}
	}

	// SLIDER INTERVAL 
		
	$(slide_selector_container).data("interval",
		setInterval(function () {	slider(slide_distance, slides_shown, slide_selector, slide_selector_container, slide_speed, slide_pause, direction, override)},slide_pause)
	);
}
		
		// HOME PAGE RULES
		if ($("#container2").hasClass("home")){
			if (!$("#container2").hasClass("industry_home")){		
				supply_chain_industry_slider = setTimeout(function(){auto_slider( 284, 1, '#supply_chain_industry_list li', '#supply_chain_industry_list', 500, 6000, "up", false)},1500);
				payment_systems_slider = setTimeout(function(){auto_slider( 310, 1, '#payment_systems_list li', '#payment_systems_list', 500, 6000, "right", false)},2000);
				retail_technology_slider = setTimeout(function(){auto_slider( 284, 1, '#retail_technology_list li', '#retail_technology_list', 500, 6000, "down", false)},300);

				// INDUSTRY SPACIFIC BUTTONS CLICK FUNCTION 
				
				industry_clicks = 0;
				$("#testimonials_container").empty();
				$("#press_room_container").empty();
				$("#navigation").empty();
				$("#social_media_navigation").empty();
				$("#about_dd ul").empty();
				$("#candidates_dd ul").empty();
				$("#employers_dd ul").empty();
				$("#job_ticker").empty();
				$("#rss_feed_body").empty(); // ADDED BY CHAUNCE

				$("#supply_chain_link, #payment_systems_link, #retail_technology_industry_link, #supply_chain_footer_link, #payment_systems_footer_link, #retail_technology_footer_link").click( 
					function (){

						// COUNT CLICKS
						
						industry_clicks = industry_clicks + 1;
						
						// GET ID OF CLICKED ITEM 
						
						this_id = $(this).attr("id");
						
						// APPLY HOME PAGE LINK CLASS
						
						$('#home_link').addClass("back_to_home");

						// OBJECT TRANSITIONS
						
						$("#supply_chain_industry_showcase, #payment_systems_industry_showcase, #retail_technology_industry_showcase").hide(1300);
						$("#testimonial_special_showcase, #company_statement_showcase, #press_room_showcase").delay(600).show();
						$("#site_tagline").hide(1500);
						$("#navigation, #social_media_navigation").delay(400).animate({"left" : "0"},1000);
						$(".intro_statement").hide(600);
						$("#industry_selection_list").hide(600);
	
											
						// SUPPLY CHAIN RULES 
						
						if (this_id == "supply_chain_link" || this_id == "supply_chain_footer_link") {
							$("#container2").addClass("supply_chain_visited");						
							$.ajax({
								url: '/refresh/code/sessions.php?industry=supply_chain'
							});	
							
							$("#testimonials_container").load('includes/testimonial_content.php?ajax=yes&industry=supply_chain', function () {
								testimonials_slider = setTimeout(function(){auto_slider( 284, 1, '#testimonials_container div', '#testimonials_container', 500, 6000, "down", false)},1500);
								fancybox_ajax();
							});	
							$("#press_room_container").load('includes/press_room_content.php?ajax=yes&industry=supply_chain', function () {
								press_room_slider = setTimeout(function(){auto_slider( 284, 1, '#press_room_container div', '#press_room_container', 500, 6000, "up", false)},300);
								fancybox_ajax();
							});							
							$("#job_ticker").load('includes/job_ticker_content.php?ajax=yes&industry=supply_chain', function () {
								job_ticker_slider = setTimeout(function(){auto_slider(240,4,'#job_ticker li','#job_ticker',500,4000,"left", false)},30);
								$("#job_ticker_container").show(500);
								fancybox_ajax();
							});							
							$("#navigation").load('includes/navigation_content.php?ajax=yes&industry=supply_chain');							
							$("#social_media_navigation").load('includes/social_media_navigation_content.php?ajax=yes&industry=supply_chain');							
							$("#about_dd ul").load('includes/sub_navigation_content_about.php?ajax=yes&industry=supply_chain');							
							$("#candidates_dd ul").load('includes/sub_navigation_content_candidates.php?ajax=yes&industry=supply_chain');							
							$("#employers_dd ul").load('includes/sub_navigation_content_employers.php?ajax=yes&industry=supply_chain');							
							$("#supply_chain_text").show(1000);
							$("#container2").addClass("job_tickering");						
							$("#footer").animate({backgroundPosition: '0px 0px'},1200);
						}
						
						// PAYMENT SYSTEMS RULES 
						
						if (this_id == "payment_systems_link" || this_id == "payment_systems_footer_link") {
							$.ajax({
							  url: '/refresh/code/sessions.php?industry=payment_systems'
							});

							$("#testimonials_container").load('includes/testimonial_content.php?ajax=yes&industry=payment_systems', function () {
								testimonials_slider = setTimeout(function(){auto_slider( 284, 1, '#testimonials_container div', '#testimonials_container', 500, 6000, "down", false)},1500);
								fancybox_ajax();
							});													
							$("#press_room_container").load('includes/press_room_content.php?ajax=yes&industry=payment_systems', function () {
								press_room_slider = setTimeout(function(){auto_slider( 284, 1, '#press_room_container div', '#press_room_container', 500, 6000, "up", false)},300);
								fancybox_ajax();
							});		
							$("#job_ticker").load('includes/job_ticker_content.php?ajax=yes&industry=payment_systems', function () {
								job_ticker_slider = setTimeout(function(){auto_slider(240,4,'#job_ticker li','#job_ticker',500,4000,"left", false)},30);
								$("#job_ticker_container").show(500);
								fancybox_ajax();
							});														
							$("#navigation").load('includes/navigation_content.php?ajax=yes&industry=payment_systems');							
							$("#social_media_navigation").load('includes/social_media_navigation_content.php?ajax=yes&industry=payment_systems');							
							$("#about_dd ul").load('includes/sub_navigation_content_about.php?ajax=yes&industry=payment_systems');							
							$("#candidates_dd ul").load('includes/sub_navigation_content_candidates.php?ajax=yes&industry=payment_systems');							
							$("#employers_dd ul").load('includes/sub_navigation_content_employers.php?ajax=yes&industry=payment_systems');							
							
							$("#container2").addClass("payment_system_visited");												
							//company_statement_slider = setTimeout(function(){auto_slider( 310, 1, '#company_statement_list li', '#company_statement_list', 500, 5000, "right"), false},2000);
							$("#rss_feed_body").load('includes/rss_news_feed.php?ajax=yes&industry=payment_systems'); // ADDED BY CHAUNCE
							$("#payment_systems_text").show(1000);
							$("#rss_news_feed_link").show(600);
							$("#footer").animate({backgroundPosition: '0px -160px'},1200);
						}
						
						// RETAIL TECHNOLOGY RULES
						
						if (this_id == "retail_technology_industry_link" || this_id == "retail_technology_footer_link") {
							$.ajax({
							  url: '/refresh/code/sessions.php?industry=retail_technology'
							});								
							$("#testimonials_container").load('includes/testimonial_content.php?ajax=yes&industry=retail_technology', function () {
								testimonials_slider = setTimeout(function(){auto_slider( 284, 1, '#testimonials_container div', '#testimonials_container', 500, 6000, "down", false)},1500);
								fancybox_ajax();
							});							
							$("#press_room_container").load('includes/press_room_content.php?ajax=yes&industry=retail_technology', function () {
								press_room_slider = setTimeout(function(){auto_slider( 284, 1, '#press_room_container div', '#press_room_container', 500, 6000, "up", false)},300);
								fancybox_ajax();
							});			
							$("#job_ticker").load('includes/job_ticker_content.php?ajax=yes&industry=retail_technology', function () {
								job_ticker_slider = setTimeout(function(){auto_slider(240,4,'#job_ticker li','#job_ticker',500,4000,"left", false)},30);
								$("#job_ticker_container").show(500);
								fancybox_ajax();
							});		
							$("#navigation").load('includes/navigation_content.php?ajax=yes&industry=retail_technology');							
							$("#social_media_navigation").load('includes/social_media_navigation_content.php?ajax=yes&industry=retail_technology');							
							$("#about_dd ul").load('includes/sub_navigation_content_about.php?ajax=yes&industry=retail_technology');							
							$("#candidates_dd ul").load('includes/sub_navigation_content_candidates.php?ajax=yes&industry=retail_technology');							
							$("#employers_dd ul").load('includes/sub_navigation_content_employers.php?ajax=yes&industry=retail_technology');							
							$("#container2").addClass("retail_technology_industry_visited");
							//company_statement_slider = setTimeout(function(){auto_slider( 310, 1, '#company_statement_list li', '#company_statement_list', 500, 5000, "right", false)},2000);
							$("#rss_feed_body").load('includes/rss_news_feed.php?ajax=yes&industry=retail_technology'); // ADDED BY CHAUNCE				
							$("#retail_technology_text").show(1000);
							$("#rss_news_feed_link").show(600);
							$("#footer").animate({backgroundPosition: '-1000px -80px'},1200);
						}
						
						return false;
					}				
				);
				$("#home_link").click(function(){
					if($(this).hasClass('back_to_home')){
					if(!$("body").hasClass("ie6")){		
					$("#testimonials_container").empty();
					$("#press_room_container").empty();
					$("#navigation").empty();
					$("#social_media_navigation").empty();
					$("#about_dd ul").empty();
					$("#candidates_dd ul").empty();
					$("#employers_dd ul").empty();
					$("#job_ticker").empty();
					$("#rss_feed_body").empty(); // ADDED BY CHAUNCE
					if($("#container2").hasClass("retail_technology_industry_visited") || $("#container2").hasClass("payment_system_visited")){
						clearTimeout(testimonials_slider);
						clearInterval($('#testimonials_container').data("interval"));

						clearTimeout(press_room_slider);
						clearInterval($('#press_room_container').data("interval"));

						clearTimeout(job_ticker_slider);
						clearInterval($('#job_ticker').data("interval"));
					}
					if($("#container2").addClass("supply_chain_visited")){ 
						clearTimeout(testimonials_slider);
						clearInterval($('#testimonials_container').data("interval"));

						clearTimeout(press_room_slider);
						clearInterval($('#press_room_container').data("interval"));
						
						clearTimeout(job_ticker_slider);
						clearInterval($('#job_ticker').data("interval"));
					}					
						
						$("#container2").removeClass("retail_technology_industry_visited").removeClass("payment_system_visited").removeClass("supply_chain_visited");
						
						
						// OBJECT TRANSITIONS
						$("#testimonial_special_showcase, #company_statement_showcase, #press_room_showcase").hide(1300);
						$("#supply_chain_industry_showcase, #payment_systems_industry_showcase, #retail_technology_industry_showcase").delay(600).show(600);
						$("#site_tagline").show(1500);
						$("#navigation, #social_media_navigation").delay(400).animate({"left" : "960"},1000);
						$("#supply_chain_text").hide(1000);
						$("#payment_systems_text").hide(1000);
						$("#retail_technology_text").hide(1000);
						$(".intro_statement").show(600);
						$("#rss_news_feed_link").hide(600);
						$("#industry_selection_list").show(600);						
						$("#footer").animate({backgroundPosition: '0px -80px'},1200);
						if($("#container2").hasClass("job_tickering")){
							$("#job_ticker_container").hide(500);
						}
						$('#rss_feed_body').hide(300);
						$(this).removeClass('back_to_home');
						return false;
					}	
					}							   
					$("#testimonial_special_showcase, #press_room_showcase, #job_ticker_container").removeClass("initiated");
				});	
			}
			else {
				testimonials_slider = setTimeout(function(){auto_slider( 284, 1, '#testimonials_container div', '#testimonials_container', 500, 6000, "down", false)},1500);
				if (!$("#container2").hasClass("supply_chain")){
				}
				press_room_slider = setTimeout(function(){auto_slider( 284, 1, '#press_room_container div', '#press_room_container', 500, 6000, "up", false)},300);
				if ($("#container2").hasClass("supply_chain")){
					job_ticker = setTimeout(function(){auto_slider( 240, 4, '#job_ticker li', '#job_ticker', 500, 4000, "left", false)},0);
				}
			}
			$('#testimonial_special_showcase').live('mouseover mouseout', function(event) {
				if($('#testimonial_special_showcase').hasClass("initiated")){
					if (event.type == 'mouseover') {
						clearTimeout(testimonials_slider);
						clearInterval($('#testimonials_container').data("interval"));
					} else {
							testimonials_slider = setTimeout(function(){auto_slider( 284, 1, '#testimonials_container div', '#testimonials_container', 500, 6000, "down", true)},0);										
					}
				}
			});						
			$('#press_room_showcase').live('mouseover mouseout', function(event) {
				if($('#press_room_showcase').hasClass("initiated")){
					if (event.type == 'mouseover') {
						clearTimeout(press_room_slider);
						clearInterval($('#press_room_container').data("interval"));
					} else {
						press_room_slider = setTimeout(function(){auto_slider( 284, 1, '#press_room_container div', '#press_room_container', 500, 6000, "up", true)},0);
					}
				}
			});
			$('#job_ticker_container').live('mouseover mouseout', function(event) {
				if($('#job_ticker_container').hasClass("initiated")){
					if (event.type == 'mouseover') {
						clearTimeout(job_ticker_slider);
						clearInterval($('#job_ticker').data("interval"));
					} else {
						job_ticker_slider = setTimeout(function(){auto_slider(240,4,'#job_ticker li','#job_ticker',500,4000,"left", true)},0);
					}
				}
			});
			

		}
		else {
		
		// INTERIOR RULES
		
			// GENERAL FORM RULES							 	
			if ($("#request_info_form").hasClass("body_form") || $("#resume_submittal_form").hasClass("body_form")){
				var count = 10;
				countdown = setInterval(function(){
				$("#timer").html("Please wait " + count + " seconds before you submit!");
				if (count == 0) {
					$('#timer').remove();
					$("#submit_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();
				});
			}
			
			// CONTENT ACCORDIAN
				
			$("div.accordion_contents").hide()
			$("h3.accordion").live("click",function() {
				$(this).toggleClass("on");
					if($(this).hasClass("on")) {
						$(this).next(".accordion_contents").slideDown();
					} 
					else {
						$(this).next(".accordion_contents").slideUp();
					}
			});
	
		}

	// GLOBAL RULES

	$("#rss_news_feed_link").mouseover(function() {
		$("#rss_feed_body").toggle(500);
	});
	
	$("#rss_feed_body").mouseleave(function() {
		$("#rss_feed_body").toggle(500);
	});
	
	// AUTO CLICK NEW NAME LINK
	
	if ($("#container2").hasClass("popup")){
		$("a#new_name_link").trigger('click');	
	}

		
});
