$(document).ready(function(){
	
	///////////////////////focus blur for all input fields///////////////////////////
	$('input#s').val('SEARCH');
	$('input#author').focus(function(){
	        var defaultText = $(this).val();
	        $(this).val('');
			$('input#author').css({'color' : '#00E0E0'});
	        $('input#author').blur( function () {
	        var userInput = $(this).val();
	
	                if (userInput == ''){
	                        $(this).val(defaultText);
	                }
	        });
	
	});
	$('input#email').focus(function(){
	        var defaultText = $(this).val();
	        $(this).val('');
			$('input#email').css({'color' : '#00E0E0'});
	        $('input#email').blur( function () {
	        var userInput = $(this).val();
	
	                if (userInput == ''){
	                        $(this).val(defaultText);
	                }
	        });
	
	});
	$('input#url').focus(function(){
	        var defaultText = $(this).val();
	        $(this).val('');
			$('input#url').css({'color' : '#00E0E0'});
	        $('input#url').blur( function () {
	        var userInput = $(this).val();
	
	                if (userInput == ''){
	                        $(this).val(defaultText);
	                }
	        });
	
	});
	$('input#s').focus(function(){
	        var defaultText = $(this).val();
	        $(this).val('');
	
	        $('input#s').blur( function () {
	        var userInput = $(this).val();
	
	                if (userInput == ''){
	                        $(this).val(defaultText);
	                }
	        });
	
	});
	$('textarea').focus(function(){
	        
	        
		$('textarea').css({'color' : '#00E0E0'});
	        
	
	});
	$('input#phone').focus(function(){
	        var defaultText = $(this).val();
	        $(this).val('');
			$('input#phone').css({'color' : '#00E0E0'});
	        $('input#phone').blur( function () {
	        var userInput = $(this).val();
	
	                if (userInput == ''){
	                        $(this).val(defaultText);
	                }
	        });
	
	});
	///////////////////////Form Validation///////////////////////////
	
	
	function nameCheck(){
				
		var nameInput = $('input#author').attr('value');
		var requiredText = 'This Field is Required';
		var defaultVal = 'NAME (REQUIRED)';
		if(nameInput == '' || nameInput == defaultVal || nameInput == requiredText){
			
			
			$('input#author').attr('value', requiredText);
			$('input#author').css({'color' : '#C22280'})
			return(false);	
					
		}else{
			
			return(true);
		
		}	
				
	}
	
	function emailCheck(){
		
		var emailValid = $("input#email").val().match(/^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/);
		
		var emailInValid = "Enter a Proper Email Address";
		
		if(emailValid == null || emailValid == emailInValid){
			
			$('input#email').attr('value', emailInValid);
			$('input#email').css({'color' : '#C22280'});
			return(false);		
				
		}else{
			
			return(true);
			
		}	
				
	}
	
	function textareaCheck(){
		
		var textareaInput = $('textarea').val();
		var requiredText = "This Field is Required";
		if(textareaInput == '' || textareaInput == requiredText){
			
		
			$('textarea').attr('value', requiredText);
			$('textarea').css({'color' : '#C22280'});
			return(false);
						
		}else{
			
			return(true);
			
		}	
				
	}
	
	$('#submit').click(function formcheck(event){
		
		textareaCheck();
		emailCheck();
		nameCheck();
		
		if(nameCheck() == true && emailCheck() == true && textarea() == true){	
	
			$('#submit').unbind('click', formcheck);
				
		}else{
			
			event.preventDefault();
			
		}
	
	});
	/////////////////////last.fm effects/////////////////////
	
   
	//$('a').tooltip({track: true, delay: 0, showURL: true, fade: 250});
	$('#lastfmrecords ol li').hover(function(){
	
			var titleA = $('a img', this).attr('title');

			$('a', this).attr('title', titleA)
		//	$('#pop_up_bubble').css({'display' : 'block', 'z-index':'1000000'});
	 });
	////////////////////switch effect/////////////////////
	$('#switch a').click(function(event){
		event.preventDefault();
		
	});
	$('#switch a').css({backgroundPosition: "0 0"}).toggle(function(){
		$(this).stop().animate({backgroundPosition: '(0 -120px)'}, {duration:200});
		$('#off').stop(true,true).animate({bottom: '128px'}, {duration:200}).animate({opacity: 0}, {duration:200})
		$('#on').stop(true,true).animate({bottom: '128px'}, {duration:200}).animate({opacity: 1}, {duration:200})
		
		$('.info_sitemap').fadeIn('fast');
		
	},function(){
	
		$('#off').stop(true,true).animate({bottom: '8px'}, {duration:200}).animate({opacity: 1}, {duration:200});
		$('#on').stop(true,true).animate({bottom: '8px'}, {duration:200}).animate({opacity: 0}, {duration:200});
		$(this).stop().animate({backgroundPosition: '(0 0)'}, {duration:200});
		$('.info_sitemap').fadeOut("fast");
		
		
	});
	////////////////////portfolio effects/////////////////////
	$('.project_container').hover(function(){
		$( '.project_details', this).stop().animate({top: '0'}, {duration:400});
	},function(){	
		$( '.project_details', this).stop().animate({top: '279px'}, {duration:400});
	});
	
	$('#flash').addClass('active')
	$('#design').addClass('active')
	$('#front-end').addClass('active')
	
	$('#flash').click(function(){
		
		
		if($(this).hasClass('active')){
			$('.project_container.flash').fadeOut('slow');
			$(this).removeClass('active');
				
		}else{
			
			$('.project_container.flash').fadeIn('slow');
			$(this).addClass('active');
			
		}
		
	});
	
	$('#design').click(function(){
		
		
		if($(this).hasClass('active')){

			$('.project_container.design').fadeOut('slow');
			$(this).removeClass('active');
				
		}else{

			$('.project_container.design').fadeIn('slow');
			$(this).addClass('active');
			
		}
	
	});
	
	$('#front-end').click(function(){
		
		
		if($(this).hasClass('active')){
			
			$('.project_container.front-end').fadeOut('slow');
			$(this).removeClass('active');
				
		}else{
			
			$('.project_container.front-end').fadeIn('slow');
			$(this).addClass('active');
			
		}
	});
	
});




