$(document).ready(function()
{

	$(".btn_download").click(function(){
		$.post("scripts/downloads.php", { download_id: $("#new_name").val(), }, function(data) {
			$('#dialog').dialog('open');
			//$('#dialog').dialog('option', 'title', 'Opt In');
			$('#dialog').dialog('option', 'height', 125);
			$('#dialog').dialog('option', 'width', 480);
			if (data.error != "") {
				$("#download_password_content").html(data.error);
				$("#download_password").show();
			}
			else if (data.success != "") {
				$(location).attr('href',data.url);
			}
		}, "json");
	});

	if ($("#dialog").length > 0) {
		$('#dialog').dialog({
			autoOpen: false,
			width: 670,
			height: 630,
			modal: true,
			overlay: {
				backgroundColor: '#fff',
				opacity: 0.7
			}		
		});
	}

	//$("#col_2").height($("#col_1").height()); // Make the 'News' column the same height as the main column
	
	height_col_1 = $("#col_1").height();
	height_col_2 = $("#col_2").height();
	
	if (height_col_1 < height_col_2) {
		$("#col_1").height($("#col_2").height());
	}
	else {
		$("#col_2").height($("#col_1").height());
	}

	var first = 0;
	var speed = 700;
	var pause = 3500;

	function removeFirst(){
		first = $('ul#news_ticker li:first').html();
		$('ul#news_ticker li:first')
		.animate({opacity: 0}, speed)
		.fadeOut('slow', function() {$(this).remove();});
		addLast(first);
	}
	
	function addLast(first){
		last = '<li style="display:none">'+first+'</li>';
		$('ul#news_ticker').append(last)
		$('ul#news_ticker li:last')
		.animate({opacity: 1}, speed)
		.fadeIn('slow')
	}
	
	interval = setInterval(removeFirst, pause);

});