$(function(){
	
	//show page content
	$('#show_content').click(function(){
		$(this).fadeOut();
		$('#content_container, #gallery_positioner, #download').fadeIn();	
	});
	
	//testimonials height fixes
	var testiContainer = $('#testimonials_container');
	var testiheight = testiContainer.height();
		console.log(testiheight);
			testiContainer.css('height', testiheight, function(){	
	});
	
	//testimonials animation
	$('#show_testimonials').click(function(){
		$(this).fadeOut(function(){
			testiContainer.fadeIn();
			$('#next').fadeIn();
		});
		$('#show_content').animate({"top" : "420px"})	
	});
	
	
	//testimonials slider
	$('#testimonials_container').cycle({
		prev: '#prev',
		next: '#next',
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc..
		speed: 1000,
		timeout: 100000000
	});
	
	
	
	//main container js height fixes
	var height = $('#content_container').height();
	var fullheight = height + 20;
	$('#gallery_positioner').css('height', fullheight);
	
	
	//get file name, and the apply a class of active to a link with an idea equalling the file name
	var urlID = location.href.substring(location.href.lastIndexOf('/')+1).split('.')[0];
	if(urlID == ""){
		urlID = "index";	
	}
	$('#'+urlID).addClass("active");
	

	//if the file called is the homepage
	if(urlID == "index"){
		//hide the li's and position the news container off the page
		$('#nav_position ul li').hide();
		
		//fade in the navigation li's and once done animate the drop down of the news container
		$('#nav_position ul li').fadeIn(1000);
	}//end if
	

	//slider code
	$('#slider').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc..
		sync: true
	});
	
	
	
	
	
	//Once the contact link is clicked...
	$('a#contact').click(function(e){
		//prevents default # value
		e.preventDefault();

		//Add active class to the contact link
		$(this).addClass('active');
		//fade in the dark overlay
		$('#darker').fadeIn(function(){
			//once this function has run, run another which is to fade in the contact container
			$('#contact_container').fadeIn();		
		});
		
		//if esc key is pressed fade out the overlay div, and the contact container, also remove the active class from the contact link
		$(document).keyup(function(e) {
    		if (e.keyCode == 27) {
				$('#contact_container, #darker').fadeOut(400);
	   			$('a#contact').removeClass('active');
 			}
		});
		
		//close window button
		$('a#close').click(function(e){
			e.preventDefault();
			$('#darker, #contact_container').fadeOut();
			
			$('a#contact').removeClass('active');
		});
	});	
	
	
	//Once the geta  quote link is clicked...
	$('a#get_a_quote').click(function(e){
		//prevents default # value
		e.preventDefault();

		//Add active class to the contact link
		$(this).addClass('active');
		//fade in the dark overlay
		$('#darker').fadeIn(function(){
			//once this function has run, run another which is to fade in the contact container
			$('#contact_container').fadeIn();		
		});
		
		//if esc key is pressed fade out the overlay div, and the contact container, also remove the active class from the contact link
		$(document).keyup(function(e) {
    		if (e.keyCode == 27) {
				$('#contact_container').fadeOut(400);
				$('#darker').fadeOut(400);	
	   			$('a#contact').removeClass('active');
 			}
		});
		
		//close window button
		$('a#close').click(function(e){
			e.preventDefault();
			$('#darker').fadeOut();
			$('#contact_container').fadeOut();
			$('a#contact').removeClass('active');
		});
	});	
	
	
	//individual page gallery show / hide script
	$('#show_gallery').click(function(e){
		e.preventDefault();
		$(this).fadeOut();
		$('#gallery_background').fadeIn();
		$('#next, #gallery_positioner, #content_container, #testimonials_container, #show_testimonials, #show_content').fadeOut();
		$('#gallery_wrapper').fadeIn(function(){
				$('#gallery, a#close_gallery').fadeIn();
				$('#gallery img').css('margin-bottom', '10px');
		});
	});
	
	
	//close gallery
	$('a#close_gallery').click(function(e){
		e.preventDefault();
		$('#gallery_background').fadeOut();
		$('#gallery_wrapper').fadeOut(function(){
			$('#gallery_positioner').css('height', fullheight);
			$('#show_gallery, #content_container, #gallery_positioner, #show_testimonials').fadeIn();
		});
	});
	
	
	/*lightbox
	$(function(){
		$('a.lightbox').lightBox();
	});*/
	
	
	
	//sub downloads list
	$('.faux').click(function(){
		$('#list_downloads').fadeIn();
		$('#videos').fadeOut();
	});
	
	
});
