// JavaScript Document
/* hide "pages", setup the site */
var visiblePage;
var currentPageName;

$(document).ready(
	function() {
		$('#content_what_do_i_do').toggle();
		$('#content_what_have_i_done').toggle();
		$('#content_how_do_i_do_it').toggle();
		$('#content_contact_me').toggle();
		
		$('.statusMessage').hide();
		
		visiblePage = $('#content_who_am_i');
	}
);

/* add menu behavior */
$(document).ready(
	function() {
		$('a[href*="content_who_am_i"]').click(
			function() {
				if( currentPageName != 'content_who_am_i' ) {
					visiblePage.hide('fast', 
						function() {
							$('#content_who_am_i').fadeIn('slow');
							visiblePage = $('#content_who_am_i');
							currentPageName = 'content_who_am_i';
						}
					);
					//return false;
				}
			}
		);
		
		$('a[href*="content_what_do_i_do"]').click(
			function() {
				if(currentPageName != 'content_what_do_i_do') {
					visiblePage.hide('fast', 
						function() {
							$('#content_what_do_i_do').fadeIn('slow');
							visiblePage = $('#content_what_do_i_do');
							currentPageName = 'content_what_do_i_do';
						}
					);
					//return false;
				}
			}
		);
		
		$('a[href*="content_what_have_i_done"]').click(
			function() {
				if(currentPageName != 'content_what_have_i_done') {
					visiblePage.hide('fast', 
						function() {
							$('#content_what_have_i_done').fadeIn('slow');
							visiblePage = $('#content_what_have_i_done');
							currentPageName = 'content_what_have_i_done';
						}
					);
					//return false;
				}
			}
		);
		
		$('a[href*="content_how_do_i_do_it"]').click(
			function() {
				if(currentPageName != 'content_how_do_i_do_it' ) {
					visiblePage.hide('fast', 
						function() {
							$('#content_how_do_i_do_it').fadeIn('slow');
							visiblePage = $('#content_how_do_i_do_it');
							currentPageName = 'content_how_do_i_do_it';
						}
					);
					//return false;
				}
			}
		)
		
		$('a[href*="content_contact_me"]').click(
			function() {
				if(currentPageName != 'content_contact_me' ) {
					visiblePage.hide('fast', 
						function() {
							$('#content_contact_me').fadeIn('slow');
							visiblePage = $('#content_contact_me');
							currentPageName = 'content_contact_me';
						}
					);
					//return false;
				}
			}
		)
	}
);

/* sweeten up the contact form */
$(document).ready(
	function() {
		$('.inputs input, .inputs textarea').focus(
			function() {
				$(this).css('background-color', '#eaeaea').css('border', '2px solid #99cccc');
			}
		);
		
		$('.inputs input, .inputs textarea').blur(
			function() {
				$(this).css('background-color', '#6d6f75').css('border', '2px solid #191c1f');		 
			}
		);
		
		$('.inputs input, .inputs textarea').hover(
			function() {
				$(this).css('outline', '1px solid #66ccff');
			},
			
			function() {
				$(this).css('outline', 'none');
			}
		);
	}
);

/* contact form functionality */
function checkContactForm() {
	if(! checkEmail($('#email').val())) {
		showMessage('error', 'If you won\'t provide me a valid email address, I won\'t be able to reply. Please provide a valid email address and I promise I will write you back. Thank you!');
		document.location.href = '#content_contact_me';
		$('#email').focus();
		
		return false;
	}
	
	if($('#message').val() == '') {
		showMessage('error', 'If you won\'t tell me what can I help you with, I won\'t be able to... well, help you. Please fill up your message and shoot it up my way!');
		document.location.href = '#content_contact_me';
		$('#message').focus();
		
		return false;
	}
	
	return true;
}

function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	} 
	return true;
}

function showMessage(type, message) {
	$('.statusMessage').html(message);
	
	if(type == 'error') {
		$('.statusMessage').addClass('errorMessage');
	} else {
		$('.statusMessage').addClass('succesMessage');
	}
	
	$('.statusMessage').fadeIn('slow');
	$('.statusMessage').fadeOut('slow').fadeIn('slow');
}

/* add seo safer contact info */
$(document).ready(
	function() {
		$('#contact_box').prepend('<div><strong>phone:</strong> +40 746 969 767</div>');
		$('#contact_box').prepend('<div><strong>email:</strong> <a href="mailto:hireme@1up.ro">hireme@1up.ro</a></div>');
	}
);

/* ajax history */
$(document).ready(
	function() {
		$.ajaxHistory.initialize();
	}
);

/* enhanced styles */
$(document).ready(
	function() {
		if( ! $.browser.msie || ($.browser.msie && $.browser.version > 6) ) {
			$('head').append('<link rel="stylesheet" id="enhancedCss" type="text/css" href="styles/enhanced.css" />');
		}
	}
);

/* themes */
$(document).ready(
	function() {
		$('.upperMenu span').hover(
			function() {
				$(this).css('outline', '1px solid #66ccff')
			},
			
			function() {
				$(this).css('outline', 'none')
			}
		)
	}
);
	
$(document).ready(
	function() {
		$('.upperMenu span').click(
			function() {
				switch( this.id ) {
					case 'btnBlackTheme':
						setTheme('black');
						break;
					
					case 'btnBlueTheme':
						setTheme('blue');
						break;
						
					case 'btnRedTheme':
						setTheme('red');
						break;
						
					case 'btnGreenTheme':
						setTheme('green');
						break;
						
					case 'btnMagentaTheme':
						setTheme('magenta');
						break;
						
					case 'btnNoneTheme':
						$('#divMainContainer').css('background-image', 'none');
						$('#enhancedCss').remove();
						$('#logo').addClass('smallLogo').css('visibility', 'visible');
						break;
				}
			}
		)
	}
);

function setTheme(color) {
	$('body').css('background-image', 'none');
	$('#divMainContainer').css('background-image', 'url(images/tshirt_vector_no_label_' + color + '.jpg)');	
}
