/*
Javascript file for Marks and Labels (http://marks-n-labels.com)
Author: Michael Asuncion
Date: July 28 , 2011
*/


$(document).ready(function(){

	/**CONTACT - CHECK AVAILABILITY**/
	$('#contact').live("click", function(){
		
		$('.loader').show();
		//alert('tadaaa!');
		//AJAX START
		var contact = $("input[name='contact']").val();
		var dir = $("input[name='dir']").val();
		var dataString = '?qry='+contact;
		
		$.ajax({
			type: 'POST',
			url: dir+'includes/l_bub.php?'+dataString,
			data: dataString,
			success: function(){
					$(".loader").fadeOut();
					$('#l_bub').fadeIn().load(dir+'includes/l_bub.php'+dataString);
			}
			
			});	// end ajax
		});
	$('#check_av').live("click", function(){
		
		$('.loader').show();
		//alert('tadaaa!');
		//AJAX START
		var check_av = $("input[name='check_av']").val();
		var dir = $("input[name='dir']").val();
		var dataString = '?qry='+check_av;
		
		$.ajax({
			type: 'POST',
			url: dir+'includes/l_bub.php?'+dataString,
			data: dataString,
			success: function(){
					$(".loader").fadeOut();
					$('#l_bub').fadeIn().load(dir+'includes/l_bub.php'+dataString);
			}
			
			});	// end ajax
		});
	
	$('#close').live("click", function(){
		$('#l_bub').fadeOut('');
		});
	
	/**TOGGLES **/		
	//comment-box text area AUTO RESIZE
	$('textarea[name="comment"]').autoResize({
		// On resize:
		onResize : function() {
			$(this).css({opacity:0.8});
			//$(this).animate({height: '53' });
		},
		// After resize:
		animateCallback : function() {
			$(this).css({opacity:1});
			//$(this).animate({height: 'auto' });
		},
		// Quite slow animation:
		animateDuration : 300,
		// More extra space:
		extraSpace : 3
	});
	
	$('textarea[name="comment"]').toggleVal({
				focusClass: "hasFocus",
				changedClass: "isChanged",
				populateFrom: "custom",
				text: "Leave your comment here"
	});	
	
	$('textarea[name="comment"]').focusin(function(){
		if($(this).val().length > 2 )
		{
			$(this).animate({height: 'auto',});
		}
		else
		{		
			$(this).animate({height: '53' });
		}
	});
	$('textarea[name="comment"]').focusout(function(){
		if($(this).val().length <= 5 || $(this).val() == "Leave your comment here")
		{
			$(this).animate({height: '16',});
		}
		else
		{		
			$(this).animate({height: 'auto' });
		}
	});

	
	$('input[name="author"]').toggleVal({
		focusClass: "hasFocus",
		changedClass: "isChanged",
		populateFrom: "custom",
		text: "Nickname"
	});	
					
	$('input[name="email"]').toggleVal({
		focusClass: "hasFocus",
		changedClass: "isChanged",
		populateFrom: "custom",
		text: "Valid email"
	});	
										
	$('input[name="s"]').focusin(function(){
		$(this).animate({width: '127px'});
		$('input[id="searchsubmit"]').val('Go!');
		}).focusout(function(){
			$(this).animate({width: '50px'});
			setTimeout("$('input[id=\"searchsubmit\"]').val('boring...');",1000);
		});	
	
	
//load bubble

										
}); // end ready function






