// GENERAL JQUERY FUNCTIONS
//
jQuery.noConflict();
jQuery(document).ready(function($){
	
	// Testimonials Elements ------------------------------- //
	$('#testHolder li').hide();
	var totalTests = 3; // Total number of Testimonials
	var currentTest = ( Math.floor(Math.random()*totalTests) )+1; // Random Number between 1 and Total Number of Tests // The Start Test
	var firstTest = '.test'+currentTest;
	$(firstTest).addClass('current').fadeIn('slow');
	
	// Work Caro Variables ------------------------------- //
	var workWindowWidth = 978; // 3x Col width - 1 Col = 326 (308 + 18)
	var workImages = $('#workCaroSlides li').length; // Number of Windows to view on Work Caro ( 1 window = 3x work images )
	var workMaxWindows = Math.ceil(workImages/3);
	var currentWorkWindow = 0;
	var lastWorkWindow = workMaxWindows-1;
	
	
	$(window).load(function	() {
		
		// Set Nav Line
		var currentNavWidth = $('#nav li.current a').width();
		var currentNavPos = $('#nav li.current a').position();		
		$('#navLine').css('width',currentNavWidth).css('left',currentNavPos.left);
		$('#navLine').fadeIn('slow');
		//$('body').append('<p>'+currentNavWidth+'</p><p>'+currentNavPos.left+'</p>'); // TEST OUTPUT
		// Main Nav Line Animate.
		$('#nav li a').mouseenter(function(){
			var hoverNavWidth = $(this).width();
			var hoverNavPos = $(this).position();
			$('#navLine').animate({
				width : hoverNavWidth,
				left : hoverNavPos.left
			},{
				duration : 400,
				queue : false
			});
		});
		$('#nav').mouseleave(function(){
			$('#navLine').animate({
				width : currentNavWidth,
				left : currentNavPos.left
			}, 400);
		});
		
		// Contact Button Action
		$('#contactBut').click(function(event){
			$('#contactTop').slideToggle('slow');
			event.preventDefault();
		});
		
		
		// Work Image Rollover
		$('.workImg').mouseenter(function(){
			var theURL = $(this).children('a').attr('href');
			$(this).append('<a href="'+theURL+'" class="ovLink"><p>Click to View</p></a>');
		});
		$('.workImg').mouseleave(function(){
			$('.workImg a.ovLink').remove();
		});
		// Work Image Scroll
		$('#workR').click(function(event){
			if ( currentWorkWindow != lastWorkWindow ) {
				currentWorkWindow = currentWorkWindow+1;
				var newPos = 0 - (currentWorkWindow*workWindowWidth);
				$('#workCaroSlides').animate({ left : newPos },{ queue : true, duration : 400 });
			}
			event.preventDefault();
		});
		// Work Image Scroll
		$('#workL').click(function(event){
			if ( currentWorkWindow != 0 ) {
				currentWorkWindow = currentWorkWindow-1;
				var newPos = 0 - (currentWorkWindow*workWindowWidth);
				$('#workCaroSlides').animate({ left : newPos },{ queue : true, duration : 400 });
			}
			event.preventDefault();
		});
		
		// Testimonial Buttons
		$('#testNav li').click(function(){
			var theNext = $(this).attr('title');
			//$('body').append('<p>'+nextTest+'</p>');
			if( $(this).hasClass('current') ){
				// Nothing
			} else {
				var nextTest = '.test'+theNext;
				$('#testNav li.current').removeClass('current');
				$('#testHolder li.current').removeClass('current').fadeOut('fast', function(){
					$(nextTest).fadeIn('fast');
				});
				$(nextTest).addClass('current');
				currentTest = theNext*1;
				// test_data();
			}
		});
		// Create Timed Test Caro
		var testCaro = window.setInterval(
		function() {
			if ( currentTest != totalTests ) {
				var theNext = currentTest+1;
				var nextTest = '.test'+theNext;
				$('#testNav li.current').removeClass('current');
				$('#testHolder li.current').removeClass('current').fadeOut('fast', function(){
					$(nextTest).fadeIn('fast');
				});
				$(nextTest).addClass('current');
				currentTest = currentTest+1;
			} else {
				var theNext = 1;
				var nextTest = '.test'+theNext;
				$('#testNav li.current').removeClass('current');
				$('#testHolder li.current').removeClass('current').fadeOut('fast', function(){
					$(nextTest).fadeIn('fast');
				});
				$(nextTest).addClass('current');
				currentTest = 1;
			}
			// test_data();
		},8000);
		/*
		function test_data() {
			$('#data').remove();
			$('#contact').append('<div id="data" style="clear:both;"><p>Total Tests: '+totalTests+'</p><p>Current Test: '+currentTest+'</p></div>');
		}
		test_data();
		*/
		
	});
	
	
});
