var dlform1_content = "";
var dlform2_content = "";
var loadForm1ToForm2 = 0;

$(document).ready(function () {
    if($('#dlbox')){
    	init_dl();
    	dlform1_content = $('#dlform2').html();
		dlform2_content = $('#dlform1').html();
		if(loadForm1ToForm2 == 1){
			// set via typoscript
			$('#dlform1').html(dlform1_content);
		}
		
    }
});


function showActiveContent(){
	if($('#dlrelated').hasClass('dlactive')){
		$('#dlform1').html(dlform1_content);
	}else{
		$('#dlform1').html(dlform2_content);
	}
}


function dlToggle(what){
	if($('#' + what).hasClass('dlactive')){
		$('#' + what).removeClass('dlactive');
		$('#' + what).addClass('inactive');
	}else{
		$('#' + what).addClass('dlactive');
		$('#' + what).removeClass('inactive');
	}
	
	showActiveContent();
}


function init_dl(){
	$("#dlrelated").click(function () { 
      	dlToggle('dlrelated');
      	dlToggle('dlall');
    });
    
    $("#dlall").click(function () { 
      	dlToggle('dlrelated');
      	dlToggle('dlall');
    });

	//alert($('#dlform1').children.find('downloads').html());
	
	$("#dlform2 .downloads").each(function(i){
	  	selectElement = this;
	  	num = 0;
	  	$(this).find('option').each(function(m){
	  		num++;
	  	});
	  	if(num < 2){
	  		$(selectElement).addClass('selectDisabled');
	  		$(selectElement).attr('disabled', true);
	  	}
	  	//alert(num);
	  	//alert(num);
	  	//alert($(this).val(1).html());
		//alert($(this).html());
	 }); 
    
}



