$(document).ready(function(){

(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

$.fn.pause = function(duration) {
    $(this).animate({ dummy: 1 }, duration);
    return this;
};


	$("#splash div.tab").addClass("normal_tab");
	
	//dynamically add the white line to the last element
	$("#splash div.normal_tab:last").css("border-right", "2px solid white");

	//splash hover events
	$("#splash div.normal_tab").mouseenter(function () { 
			$(this).addClass("hover_tab");
	}); 
		
	$("#splash div.normal_tab").mouseleave(function () { 
		$(this).removeClass("hover_tab");
	}); 
	
	
	$("#header .nav li").mouseenter(function () { 
			$(this).addClass("on");
	}); 
	
		$("#header .nav li").mouseleave(function () { 
			$(this).removeClass("on");
	}); 
	

		
	//click event-handler for splash elements
	$("#splash div.tab").click(function () { 
		var rel = $(this).find("a").attr("rel");
		
		
			
			//AJAX CHANGE PAGE
			if(rel){
			$("#page_content").css("display", "none");
			$("#page_content").html('<div align="center"><img src="/images/misc/loading.gif" alt="loading" /> Loading</div>');
			$("#page_content").customFadeIn(500);
			$.get("/ajax.php",{page: rel}, function(data){
			$("#page_content").html(data);
			},"text");
			}
			
			
			
			document.title = "Strategic Fulfillment Group";


				$(this).removeClass();
				$(this).siblings().removeClass();

				if ($.browser.msie) {
				
				}else{
					$(this).animate({ 
					width: "711px",
					float: "left",
					height: "382px"
					}, 1000 );
					$(this).siblings().animate({ 
					width: "55px",
					float: "left",
					height: "382px",
					opacity: ".5"
					}, 1 );
					$("#default_tab").animate({
					opacity: "0",
					float: "left"
					}, 5000);
					$(this).siblings().animate({ 
					opacity: "1"
					}, 300 );
				}
				$(this).siblings().addClass("normal_tab");
				$(this).addClass("active_tab");
				$("#default_tab").remove();
				$("#header ul.nav li").removeClass("on");

			
			
		}); 

	//clear the login field when the user clicks	
	$("#p_login").click(function (){
	var value = $("#p_login").val();
	if(value == "Enter your partner code"){
	$("#p_login").val("");
	}
	});
	
	//add default text if field is blank	
	$("#p_login").blur(function (){
	var value = $("#p_login").val();
		if(value){
			
		}else{
			$("#p_login").val("Enter your partner code");
		}
	});
	
	//manually create ajax event for a link
	$("#ajax_request").click(function () { 
	
			var href = $(this).attr("rel");
			var href = href.split("?page=");
			var href = href[1];
			$.get("/ajax.php",{page: href}, function(data){
			$("#page_content").html(data);
			},"text");
			
			
			
		}); 
		
		
		//sidebar effects
		$("#template_right_sidebar .box ul li").mouseenter(function () { 
		$(this).addClass("background");
		$(this).find("span.ctl").removeClass("off");
		$(this).find("span.ctl").addClass("on");
		
		}); 
		
		$("#template_right_sidebar .box ul li").mouseleave(function () { 
		$(this).removeClass("background");
		$(this).find("span.ctl").removeClass("on");
		$(this).find("span.ctl").addClass("off");
		}); 
		
		$("#template_right_sidebar .box ul li").click(function () { 
			var element_a = $(this).find("a");
			
			if(element_a !== undefined){
			
			var element_src = element_a.attr("href");
			var target = element_a.attr("target");
			var element_rel = element_a.attr("rel");
			if(element_src !== undefined){
			if(element_rel.length > 0){
				
			}else{
			if(target === "_blank"){
				window.open(element_src, target);
				return false;
			}else{
				document.location = element_src;
				return false;
				}
			}
			}else{
				return false;
			}
			}else{
				return false;
			}
		}); 
		
		
				$('a.career').fancybox({
				'width'				: 448,
				'height'			: 368,
				'autoScale'     	: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
				});

		

		
		//footer testimonials
		$("#footer_testimonial").cycle({
		fx: 'fade',
		speed: 3000,
		timeout: 10000
		});
		
		$("#footer_testimonial div").css("display","block");
		
		
 }); 


