$(document).ready(function() 
{
//	$('#social_media').css('margin-right', -148);
	
	$('.unload_vid').live('click', function() {
		$('#popup').empty();
		$('#popup').css('visibility', 'hidden');
	})
	
	$('.show_video').click(function() {
		$('#popup').css('visibility', 'visible');
		$('#popup').load('/video/');
		$('html, body').animate({scrollTop:0}, 'slow'); 
	})
		
	$('.toggle_comments').toggle(
		function() { 
			$('form').slideDown();
			$(this).html('Thanks friend.');
		},
		function() { 
			$('form').slideUp(); 
			$(this).html('Click here to leave a comment.');
		}
	)

//	$('#comment_popup').load('/post_comment/'+$comment_id+'/');
	$('.add_comment_for_post').click(function() {
	})
	
	$('#bg_image').load("/background-image/");
	$('#feature_right').load("/featured-item/");

//	load_home_background();
	$(window).resize(function(e) {
		resize_home_background();
	});

});

function add_comment(comment_id) {
	$('#add_comment').load('/post_comment/'+ comment_id +'/');
}

function t_add_comment(comment_id) {
	$('#add_comment').load('/post_threaded_comment/'+ comment_id +'/');
}

function post_comment(url) {
	$.post(url);
}

var resize = function(img, maxh, maxw) {
	var ratio = maxh/maxw;
	if (img.height < maxh) {
 		img.width = Math.round(img.width*(maxh/img.height));
		img.height = maxh;
	}
	if (img.width < maxw) {
		img.height = Math.round(img.height*(maxw/img.width));
		img.width = maxw;
	}	
};

function load_home_background() 
{
	var page_width = ($('body').width() < 1020) ? 1020 : $('body').width();
	var page_height = ($(document).height() < 775) ? 775 : $(document).height();
	
	$('#bg_image').height(page_height).width(page_width);
	resize($('#bg_image').get(0), page_height, page_width);
	
//	$('#shadow').after('<div id="dots-overlay"></div>');
//	$('#dots-overlay').height(page_height).width(page_width);
};

function resize_home_background() 
{
	var new_page_width = ($('body').width() < 1020) ? 1020 : $('body').width();
	var new_page_height = ($(document).height() < 775) ? 775 : $(document).height();
	$('#bg_image').height(new_page_height).width(new_page_width);
	resize($('#bg_image').get(0), new_page_height, new_page_width);
};


