function update_upload() {
	$('#div_open_url').toggle();
	$('#div_open_file').toggle();
}

function update_color() {
	if ($('input[@name=color_mode]:checked').val() == 'yes') {
		$('#div_quality').fadeIn('slow');
	} else {
		$('#div_quality').fadeOut('slow');
	}
}

function update_mapping() {
	$('#div_mapping').toggle();
	$('#div_custom_mapping').toggle();
}

function restart() {
	location.href='/';
}

function update_previous_image() {
	$('#div_color_mode').fadeIn('slow');
	if ($('input[@name=color_mode]:checked').val() == 'yes') {
		$('#div_quality').fadeIn('slow');
	}
	$('#div_size').fadeIn('slow');
	if ($('#custom_mapping').val() == '') {	
		$('#div_mapping').fadeIn('slow');
	} else {
		$('#div_custom_mapping').fadeIn('slow');
	}
	$('#div_submit').fadeIn('slow');
}

function switch_code() {
	$('#ascii').toggle();
	$('#ascii_text').toggle();
	$('#ascii_code').toggle();
	$('#ascii_code_text').toggle();
}

function get_code(id) {
  var ascii = $('#'+id).html();
  ascii = ascii.replace(new RegExp('<pre>'), '');
  ascii = ascii.replace(new RegExp('</pre>'), '');
  ascii = ascii.replace(new RegExp('<pre></pre>'), '');
  var win = window.open('', id, 'width=750px,height=600px,resizable,scrollbars=yes');
  win.document.write('<html><head>');
  win.document.write('<style>');
  win.document.write('body, textarea { font-family: "Courier New", Courier, mono; font-weight: bold; font-size: 8px; margin: 0; padding: 0; background-color: #000000; color: #FFFFFF; } ');
  win.document.write('textarea { width:100%; height:100% } ');
  win.document.write('</style>');
  win.document.write('</head><body><textarea onclick="javascript: this.focus(); this.select();">');
  win.document.write(ascii);
  win.document.write('</textarea></body></html>');
  win.document.close();
}

function update_mini_gallery(id) {
$.get(
  "rid.php?"+Math.round(Math.random()*100000000),
  function(data){
    var info = eval(data);
    $('#'+id+' a').attr('href', '/gallery/art/'+info.id+'.html');
    if (info.type == 'video') {
      $('#'+id+' a img').attr('src', '/video/'+info.id+'.gif');
    } else {
      $('#'+id+' a img').attr('src', '/image/'+info.id+'.jpg');
    }
    var next = Math.round((Math.random()*60000) + 30000);
    setTimeout("update_mini_gallery('"+id+"')",next);    
  }
);
}

function init_update_mini_gallery(id) {
  var next = Math.round((Math.random()*60000) + 10000);
  setTimeout("update_mini_gallery('"+id+"')",next);    
}

$(document).ready(function(){
	if ($('input[@name=previous_image]:checked').val() == 'yes') {
		$('#div_open_file').hide();
		$('#div_open_url').hide();
		$('#div_color_mode').hide();
		$('#div_quality').hide();
		$('#div_size').hide();
		$('#div_mapping').hide();
		$('#div_custom_mapping').hide();
		$('#div_submit').hide();
		return;
	}
	$('#div_open_url').hide();
	if ($('input[@name=color_mode]:checked').val() == 'yes') {
		$('#div_quality').show();
	} else {
		$('#div_quality').hide();
	}
	$('#div_custom_mapping').hide();

	if ($('#error')) {
		setTimeout(function() { $('#error').fadeOut(2000); }, 5000);
	}
});
