// JavaScript Document for clicksandclients.com
// requires jquery
$(document).ready(function(){
	
	//candc.getInitialValues();
	
	//candc.blog_newWindow();
	
	candc.bindLightbox();
	
	candc.showQuiz();
	
});


var candc = function(){
	
	var inputvalues = [];	

	// empties input on focus
	function emptyInput(el) {
		if ($(el).val() == inputvalues[$(el).attr('id')]) {
			$(el).val('');
			$(el).css('color', '#000');
		}
	}
	
	// refills unused input on blur
	function refillInput(el) {
		if (jQuery.trim($(el).val()) == '') {
			$(el).val(inputvalues[$(el).attr('id')]);
			$(el).css('color', '#666');
		}			
	}

	// quiz functions
	function makeMonthly(monthly) {
		if (monthly.indexOf('$') == -1) {
			return '$' + parseFloat(monthly).toFixed(2);
		} else {
			return '$' + parseFloat(monthly.slice(1)).toFixed(2);
		}
	}
	function makeYearly(monthly) {
		if (monthly.indexOf('$') == -1) {
			return '$' + parseFloat(monthly * 12).toFixed(2);
		} else {
			return '$' + parseFloat(monthly.slice(1) * 12).toFixed(2);
		}
	}

	return {	
	
		// gets text input initial values and stores them in associative array
		getInitialValues: function() {
			$(':text').each(function(i){
				inputvalues[this.id] = this.value;
			});
			// bind focus & blur events
			$(':text').focus(function(){ emptyInput(this); }).blur(function(){ refillInput(this); });
		},
	
		blog_newWindow: function() {
			$('#nav_blog a').click(function(){
				var href = $(this).attr('href');
				var w = window.open(href, 'menubar,resizable,scrollbars,status,toolbar');
				return false;
			});	
		},
		
		bindLightbox: function() {
			$('a[rel="multibox"]').multibox();
		},
		
		showQuiz: function() {
			if ($(document.body).attr('id') != 'home') {
				return;
			} else {
				$('div.quiz').css('display', 'none');			
				$('#ppcquiz a').click(function(){
					$('div.quiz_step').removeClass('current');
					$('#step1').addClass('current');
					$('div.quiz').css('display', 'block');
					var quiz = $('div.quiz').get();
					jQuery.facebox(quiz);
					return false;
				});
				$('#step1 a.next_step').click(function(){
					$('#step1').removeClass('current');
					$('#step2').addClass('current');
					var botox = $('#step1 input#budget2').val();
					botox = makeMonthly(botox);
					$('#step2 #monthly_spent').html(botox);
					var yearly = makeYearly(botox);
					$('#step2 #yearly_spent').html(yearly);
					return false;
				});
				$('#step2 a.next_step').click(function(){
					$('#step2').removeClass('current');
					$('#step3').addClass('current');
					return false;
				});
				$('#step3 a.next_step').click(function(){
					$('#step3').removeClass('current');
					$('#step4').addClass('current');
					return false;
				});
				$('#step4 a.next_step').click(function(){
					$('#step4').removeClass('current');
					$('#step5').addClass('current');
					return false;
				});	
			}
			
		}
	
	
	}
}();
