$(document).ready(function(){
	
	$("#panelSliderNav").jFlow({
		slides: "#panelSlides",
		controller: ".panelNav", // must be class, use . sign
		slideWrapper : "#panelSlide", // must be id, use # sign
		selectedWrapper: "here",  // just pure text, no sign
		easing: "swing",
		duration: 400,
		height: "304px",
		width: "905px",
		prev: ".panelPrev", // must be class, use . sign
		next: ".panelNext" // must be class, use . sign
	});
	
	/* [START] Menu Functions */
	$('.header .nav a, .panel .nav a, .panel .subnav a, .footer .nav a').hover(
		function(e){
			$(this).addClass('here');
		},
		function(e){
			
			if($(this).attr('href') != window.location.href && (window.location.pathname.indexOf($(this).attr('href')) == -1))
				$(this).removeClass('here');
		}
	);
	
	$('.header .nav a, .panel .nav a, .footer .nav a').each(function(i){
		if($(this).attr('href') == window.location.href || (window.location.pathname.indexOf($(this).attr('href')) != -1))
			$(this).addClass('here');
	});
	
	$('.panel .subnav a').each(function(i){
		if($(this).attr('href') == window.location.href || (window.location.pathname.indexOf($(this).attr('href')) != -1))
		{
			$(this).addClass('here');
			$('.header .nav a').eq(2).addClass('here');
		}
	});
	
	/* [END] Menu Functions */
	
	$('.panel.industry a').click(function(){
		var theUri = this.href;
		if($(this).hasClass('closeIndustry') || $(this).hasClass('openIndustry'))
			return;
		
		$('.panel.industry a').removeClass('here');
		$(this).addClass('here');
		
		if(theUri == 'javascript:;')
			return;
		if($('.panel.project').css('display') != 'none')
			$('.panel.project').slideUp(600);
		
		$("#projectLoader").hide();
		$("#projectLoader").html('<div class="ajaxLoading"><img src="images/ajax-loading.gif" alt="Loading..." /></div>');
		tmp = new Date();
		tmp = "?"+tmp.getTime();
		$('.ajaxLoading img').attr('src', $('.ajaxLoading img').attr('src'));
		$("#projectLoader").fadeIn(200, function(){
			
			$.ajax({
				url: theUri,
				success: function(html){
					$("#projectLoader").html(html);
					
					$('#clientPanelNav a').click(function(){
						$('.panel.industry').slideUp(200, function(){
							$('.panel.industry.open').removeClass('hide');
							$('.panel.industry.open').show();
						});
						if($('.panel.project').css('display') == 'none')
						{
							$('.panel.project').removeClass('hide');
							$('.panel.project').show();
				
							$("#clientPanelNav").jFlow({
								slides: "#projectPanels",
								controller: ".clientNav", // must be class, use . sign
								slideWrapper : "#projectPanel", // must be id, use # sign
								selectedWrapper: "here",  // just pure text, no sign
								easing: "swing",
								duration: 400,
								height: "1140px",
								width: "871px",
								prev: ".panelPrev", // must be class, use . sign
								next: ".panelNext" // must be class, use . sign
							});
							$(this).click();
						}
					});
	
				}
			});
		});
			
		return false;
	});
	
	$('a.closeIndustry').click(function(){
		$('.panel.industry').slideUp(200, function(){
			$('.panel.industry.open').show();
		});
	});
	
	$('a.openIndustry').click(function(){
		$('.panel.industry').slideUp(10, function(){
			$('.panel.industry').eq(0).slideDown(200);
		});
	});
	
	$('.panel.industry a').eq(1).click();
});