$(document).ready(function(){
	
	var browserWidth = $(window).width();
	var browserHeight = $(window).height();
	var documentWidth = $(document).width();
	var documentHeight = $(document).height();
	var centerX = browserWidth/2;
	var centerY = browserHeight/2;
	

	/* Footer client logos */
	$("#scroller").simplyScroll({
		autoMode: 'loop'
	});
	
	/* Wordpress Monthly Archives */
	// Accordions for content areas
	var accordions = $('#wp-archives div');
	if (accordions.length > 1) {
	
		$('#wp-archives span').css('cursor', 'pointer');
		
		accordions.hide();
		
		//$('#main-content .accordion:first').show();

		$('#wp-archives span').click( function() {
			var checkElement = $(this).next('div');
			
			if (checkElement.is(':visible')) {
				checkElement.slideUp('normal', function() { } );
				return false;
			}
			
			if (!checkElement.is(':visible')) {
				$('#wp-archives div:visible').slideUp('normal', function() { } );
				checkElement.slideDown('normal', function() { } );
				return false;
			}
		});
	}


	/* LIFE CYCLE DIAGRAM */
	$('#acquisition').mouseover(function(){
		$('#life-cycle-diagram').css('background-position','-280px top');
	});

	$('#retention').mouseover(function(){
		$('#life-cycle-diagram').css('background-position','-560px top');
	});
	
	$('#conversion').mouseover(function(){
		$('#life-cycle-diagram').css('background-position','-840px top');
	});
	
	$('#life-cycle-diagram').mouseout(function(){
		$('#life-cycle-diagram').css('background-position','left top');
	});


	/* MODAL WINDOW */
	var modalWidth = $('#modal-window div.content').width();
	var modalHeight = $('#modal-window div.content').height();
	var modalX = (centerX - (modalWidth/2));
	var modalY = (centerY - (modalHeight/2));
	var modalForm;
	
	$('.mask').width(documentWidth);
	$('.mask').height(documentHeight);
	
	$('#modal-window').hide();
	$('#modal-window .content-inner').hide();
		
	$('#modal-window .content').css('left',modalX);
	$('#modal-window .content').css('top',modalY);
		
	$('.button-go').click(function(event){
		var filePath = $(event.target).attr('file');
		$('#file').val(filePath);
		
		modalForm = $(event.target).attr('href');
		var formTitle = $(event.target).attr('data');
		$('.modal-header h5').replaceWith('<h5>'+formTitle+'</h5>')
		$('#modal-window').fadeIn(250);
		
		$(modalForm).show();
		centerModal();
		return false;
	});
	
	$('#modal-window .mask, #modal-window .close-button').click(function(){
		$('#modal-window').fadeOut(250, function(){
	    	$(modalForm).hide();
	    });
	    return false;
  	});
			
	/* RESIZE HANDLER */
	$(window).resize(function(){
		centerModal();
	});
	
	
	/* FOOTER */
	var footerSwitch = false;
	
	animateFooter(160);
	
	function animateFooter(width){
		setInterval(function() {
  			$('#client-strip').delay(1000).animate({backgroundPosition: '-=' + width + 'px 0px'});
  			
		}, 1000);
	};
			
		
	/*
		//FORM VALIDATION & CONFIRMATION
		$('#download-data-sheet .button-submit').click(function(){
			validateForm("#download-data-sheet");
		});
		
		$('#download-data-sheet input').click(function(){
			
			var inputName = $(this).attr('name');
			var labelID = '#dl-'+inputName;
			
			$(labelID).removeClass('invalid');
		});
	*/
		
});


/* RESIZE HANDLER */
function centerModal(){
	browserWidth = $(window).width();
	browserHeight = $(window).height();
	centerX = browserWidth/2;
	centerY = browserHeight/2;
	modalWidth = $('#modal-window div.content').width();
	modalHeight = $('#modal-window div.content').height();
	modalX = (centerX - (modalWidth/2));
	modalY = (centerY - (modalHeight/2));
	if (browserWidth > modalWidth){
		$('#modal-window .content').css('left',modalX);
	};
	if (browserHeight > modalHeight){
		$('#modal-window .content').css('top',modalY);
	};
};


/* CHECK FOR FORM ERRORS */
var errors = false;

function validateForm(formID){
	
	$(formID + ' .required').each(function(index, input){
		
		if($(input).val().length != ""){
		
			$('#'+inputID).removeClass('invalid');
			
			errors = false;
			
		} else {
		
			console.log($(input).val());
	
			var inputID = $(input).attr('id');
			
			$('#'+inputID).addClass('invalid');
			
			errors = true;
		};
		
	});
	
	if(errors == true){
		$('#error-box').addClass('invalid');
		return false;
	};
};
