//View & Hide divs  
$(document).ready(function showbox() {
	$('a.showbox').live('click',function() {
		var ID = $(this).attr('id');
		$('#viewbox' + ID).toggle();   
			return false;
		});
});


//Public share on FB & Twitter  
function facebook(u) {t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
function twitter(u) {t=document.title;window.open('http://twitter.com/share?text=Read+this+shout+from+4backpacker&url='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
function digg(u) {t=document.title;window.open('http://digg.com/tools/diggthis/confirm?url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}


//Check email
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}

$(document).ready(function() {
 
//Explore 
$(".view-this").live('click',function() {
	var url = $(this).attr("id");
	$('#right-box-630').html('<div class="error">Loading..</div>');
	eval($('#right-box-630').load('http://www.4backpacker.com/ajax/view-' + url + '-feed.php'));
});

 

//Filter post 
$(function() {
$(".filter-post").live('click',function() {
	
	var user = $(this).attr("id");    
	var word = $('#word').val();
	var tags = $('#tag').val();
	var country = $('#country').val();
	
	$.ajax({
		
		 type: 'GET',
		 url: '/ajax/filter-post.php',
		 data: 'word=' + word + '&tag=' + tags + '&country=' + country + '&user=' +  user,
		 dataType: 'html',
		 cache: false,
		 beforeSend: function() {   
		  $('#msg').show().html('Loading...');
		  $('#msg').addClass("notice");
			if(id = 'user'){
		 	$('#paginate').hide();
		 	} 
		 },
		 success: function(response) {
		  	$('#msg').show().html('Recent entries with your keywords');
		  	$('#msg').addClass("success");
		 	$('#timeline').html(response);
		 },
		 error: function(){
			$('#msg').show.html('<li>No Connection, please reload the page.</li>');
	        $('#msg').addClass("error");
		 }
	});
	
	 
});

}); 

//From http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/super-simple-lightbox-with-css-and-jquery/
$('.lightbox_trigger').live('click', function(e) {  

e.preventDefault();
var image_href = $(this).attr("href");
if ($('#lightbox').length > 0) { 
	$('#img-content').html('<img src="' + image_href + '" />');
	$('#lightbox').show();
} else { 
	var lightbox = 
	'<div id="lightbox">' +
	'<p><a href="#" id="close">Click to close</a></p>' +
	'<div id="img-content">' +  
	'<img src="' + image_href +'" />' +
	'</div>' +	
	'</div>';
	$('body').append(lightbox);
}
});
	
$('#lightbox, #close').live('click', function() {  
	$('#lightbox').hide();
});
 
$(document).bind('keydown', function(e) { 
        if(e.keyCode==27){
          $('#lightbox').hide();
        }
}); 
 
}); 
	
