var mymedium = "dvd";

var mylink = '';
var myiso = '';
var directory = "http://download.opensuse.org/distribution/11.2-RC2";
var isos = new Array();

  isos['kde-64'] = 'KDE4-LiveCD-Build0339-x86_64';

  isos['net-64'] = 'NET-Build0339-x86_64';

  isos['net-32'] = 'NET-Build0339-i586';

  isos['gnome-64'] = 'GNOME-LiveCD-Build0339-x86_64';

  isos['kde-32'] = 'KDE4-LiveCD-Build0339-i686';

  isos['nonoss'] = 'Addon-NonOss-BiArch-Build0339-i586-x86_64';

  isos['dvd-64'] = 'DVD-Build0339-x86_64';

  isos['gnome-32'] = 'GNOME-LiveCD-Build0339-i686';

  isos['dvd-32'] = 'DVD-Build0339-i586';

  isos['lang-64'] = 'Addon-Lang-Build0339-x86_64';

  isos['lang-32'] = 'Addon-Lang-Build0339-i586';


function changeiso () {
  mylink = mymedium;
  var arch_suffix = "-64";
  if ($('#i686').attr('checked')) {
    arch_suffix = "-32";
  }
  myiso = directory + "/iso/openSUSE-" + isos[mylink + arch_suffix] + ".iso";
  mylink = myiso;
  var download_suffix = '';
  if ($('#p_torrent').attr('checked')) {
    download_suffix = ".torrent";
  }
  if ($('#p_metalink').attr('checked')) {
    download_suffix = ".metalink";
  }
  if ($('#p_mirror').attr('checked')) {
    download_suffix = "?mirrorlist";
  }
  $('#sig_gpg').attr("href", myiso + ".asc");
  $('#sig_md5').attr("href", myiso + ".md5");
  $('#sig_sha1').attr("href", myiso + ".sha1");
  mylink += download_suffix;

  var langiso = directory + "/iso/openSUSE-" + isos['lang' + arch_suffix] + ".iso";
  $('#md5_lang').attr('href', langiso + ".md5");
  $('#sha1_lang').attr('href', langiso + ".sha1");
  $('#gpg_lang').attr('href', langiso + ".asc");
  $('#iso_lang').attr('href', langiso + download_suffix);
  $('#iso_nonoss').attr('href', directory + "/iso/openSUSE-" + isos['nonoss'] + ".iso" + download_suffix);

  $('#icon_' + mymedium).addClass('icon_selected').removeClass('icon_unselected').parent('div').addClass("medium_selected").removeClass('medium_unselected');
  // $('#icon_' + mymedium).addClass('icon_selected').removeClass('icon_unselected');

  // $('#download_button').html($('#download_' + mymedium).html());
  $('#download_button').html($('#download_' + mymedium).html());

  if (mymedium == 'net') {
     $('#l_torrent').addClass('notavailable');
     $('#p_torrent').attr('disabled', 'disabled');
     if ($('#p_torrent').attr('checked')) {
	$('#p_torrent').attr('checked', '');
	$('#p_http').attr('checked', 'checked');
     }
  } else {
     $('#l_torrent').removeClass('notavailable');
     $('#p_torrent').attr('disabled', '');
  }
}


function unselectOld() {
  // $('#icon_' + mymedium).removeClass('icon_selected').addClass('icon_unselected');
  $('#icon_' + mymedium).removeClass('icon_selected').addClass('icon_unselected').parent('div').addClass("medium_unselected").removeClass('medium_selected');
}

function resizeBoxes() {
  var curmax = $('#ci_gnome').height();
  curmax = Math.max(curmax, $('#ci_kde').height());
  curmax = Math.max(curmax, $('#ci_net').height());
  curmax = Math.max(curmax, $('#ci_dvd').height());
  var curwidth = $('#ci_gnome').width();
  $('#ci_gnome').height(curmax).width(curwidth);
  $('#ci_kde').height(curmax).width(curwidth);
  $('#ci_net').height(curmax).width(curwidth);
  $('#ci_dvd').height(curmax).width(curwidth);
}

$(function() {
    changeiso();
    $('.helplink').show();
    $('.script_only').show();
    $('.noscript').hide();

    $('.changeiso').click(function(){
			    changeiso();
			    return true; 
			  });
    $('div.changeiso').click(function(){
				  unselectOld();
				  mymedium = this.id.substr(3);
				  changeiso();
				  return false; 
				});
    $('button.changeiso').click(function(){
				  unselectOld();
				  mymedium = this.id.substr(3);
				  changeiso();
				  return false; 
				});
    $('#download_button').click(function() {
			   window.location = mylink;
			   return false;
			 });
    $("#help_arch").click(function(){
			    $('#popup_content').html($('#help_arch_content').html());
			    $("#popup").fadeIn('fast');  // Other effects can be used to show the Tooltip
			  });
    $("#help_method").click(function(){
                            $('#popup_content').html($('#help_method_content').html());
                            $("#popup").fadeIn('fast');  // Other effects can be used to show the Tooltip
                          });
    $('#popup_close').click(function() {
			 $("#popup").fadeOut('fast');
			 return false;
                          });
    var resizeTimer = null;
    
    $(window).bind('resize', function() {
		     if (resizeTimer) clearTimeout(resizeTimer);
		     resizeTimer = setTimeout(resizeBoxes, 100);
		   });

    resizeBoxes();

  });
