$(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'); 
	})

	// check cookies and load video if cookies set..
	// fixme:
	if( (document.location.href) == "http://www.riotfest.org/"){
	//	if (!(ref.match(/^https?:\/\/([^\/]+\.)?riotfest\.org(\/|$)/i))) {	   
			$('#popup').css('visibility', 'visible');
			$('#popup').load('/video/');
			$('html, body').animate({scrollTop:0}, 'slow'); 
	//	}
	}
	// end hack

	
	
	$('.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();
	});

// countdown timer to tickets			
	$('#countdown_dashboard').countDown({
			targetDate: {
				'day': 		5,
				'month': 	10,
				'year': 	2011,
				'hour': 	19,
				'min': 		0,
				'sec': 		0
			}
	});
			
	
});
//-----------------------------------------------------------

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);
};


