$(document).ready(function (){	
	
//	$('a').bind('click',function(){
//		var href = $(this).attr('href');
//		alert( href );
//		return false;
//	});



	$('#pageheader').bind('mouseenter',function (){
	   $(this).animate({
	     height: '100px'
	   }, {
	     duration: 150, 
	     specialEasing: {
	       width: 'linear',
	       height: 'easeOutBounce'
	     }, 
	     //complete: function() {
	     //  $(this).after('<div>Animation complete.</div>');
	     //}
	   });
	});

	$('#pageheader').bind('mouseleave',function (){
	   $(this).animate({
	     height: '20px'
	   }, {
	     duration: 150, 
	     specialEasing: {
	       width: 'linear',
	       height: 'easeOutBounce'
	     }, 
	     //complete: function() {
	     //  $(this).after('<div>Animation complete.</div>');
	     //}
	   });
	});

   $('#postform').submit(function(){
   	submitForm1( this );
   	return false;
   });


   //show menu
   $('#inputmenu').bind('mouseenter',function (){
      $("#inputmenu").animate({opacity: 1},{queue:false, duration:500 } );
         
         //emtpy input items onclick
         $(document).ready(function(){  
            $('.emptyonclick').emptyonclick();
         });
      
      return false;
   });
   
   //hide menu
   $('#inputmenu').bind('mouseleave',function (){
      $("#inputmenu").animate({opacity: 0.1},{ queue:false, duration:500 });
      return false;
   });

	//disable showurl button
	$('#showurl').bind('click',function (){
		var url = "http://" + window.location.hostname + "/showurl/";
		
		item_lightbox(url);
		
		$('#showurl').fadeOut("slow",function() {
	        $('#showurl').toggleClass("tagged");
	    });
		$('#showurl').fadeIn("slow");
		
		return false;
	});


});

//post
function submitForm1 (contact)
{ 	
	var parameters = {
		postsubmit: contact.postsubmit.value,
		link: contact.link.value
    };

    var url = "/api/";

	$.post(url,parameters,onComplete1);
	working = false;
	return false;
}

function onComplete1(response) {
		if(response == 'not a valid url') {
			var html = '<div id="shorturl">'+response+'</div>';
		}
		else{
			var html = '<div id="shorturl2"><div id="shortrurl">'+response+'</div></div>';
		}		
		document.getElementById('shorturl_wrapper').innerHTML = html;
		if(response == 'not a valid url') {
			$("#shorturl").fadeIn("slow");
			window.setTimeout(function(){
				$("#shorturl").fadeOut("slow");
				//$("#shorturl_wrapper").slideUp("slow");
			},10000);
		}else{
			$("#shorturl2").fadeIn("slow");
			//clear the input field on submit
			$(".textarea").val('');
			
		}
		
		$('#shortrurl').bind('click',function(){
			return false;
		});
		
		working = false;
}



function item_lightbox(url){
	
	var html = $.ajax({
		  url: url,
		  async: false
		 }).responseText;
	
	var newStr = "<div id=\"lb\"></div>" + html;
	$("body").prepend(newStr);

	$("#lb").css("width",$(document).width());
	$("#lb").css("height",$(document).height());
	$("#container").css("height",$(document).height());
	$("#lb").fadeIn("fast");
	$("#lb-content").fadeIn("fast");
	
	$("#lb").animate({ 
        opacity: 0.8
      }, 1500 );
	
			
	$("#lb").bind('click',function (){
		$("#lb-content").fadeOut("fast"); //ignored due to the remove lines
		$("#lb").fadeOut("fast"); //ignored due to the remove lines
		$("#lb").remove();
		$("#lb-content").remove();
		return false;
	});
	
	$(".close").bind('click',function (){
		$("#lb-content").fadeOut("fast"); //ignored due to the remove lines
		$("#lb").fadeOut("fast"); //ignored due to the remove lines
		$("#lb").remove();
		$("#lb-content").remove();
		return false;
	});
	
	
	

	return false;
}

