function cowonFaqToggle( num ) {
	var faqRow = document.getElementById( "faq-" + num );
	var faqColL = document.getElementById( "faq-left-" + num );
	var faqColR = document.getElementById( "faq-right-" + num );
	var buttonImage = faqRow.firstChild.firstChild;
	var questionText = document.getElementById( "question" + num );
	var answerText = document.getElementById( "answer" + num );
	
	// Expand question?
	if ( answerText.style.display == "none" ) {
		faqRow.setAttribute( "class", "light" );
		faqColL.setAttribute( "class", "light" );
		faqColR.setAttribute( "class", "light" );
		faqColL.setAttribute( "className", "light" );  // For IE
		faqColR.setAttribute( "className", "light" );  // For IE
		buttonImage.setAttribute( "src", "img/faqbutton_minus.png" );
		questionText.setAttribute( "style", "color: #D2D2D2" );
		questionText.style.color = "#D2D2D2";  // For IE
		answerText.removeAttribute( "style" );
		answerText.style.display = "block";
	}
	
	// ... or shrink question?
	else {
		answerText.style.display = "none";
		faqRow.setAttribute( "class", "dark" );
		faqColL.setAttribute( "class", "dark" );
		faqColR.setAttribute( "class", "dark" );
		faqColL.setAttribute( "className", "dark" );  // For IE
		faqColR.setAttribute( "className", "dark" );  // For IE
 		buttonImage.setAttribute( "src", "img/faqbutton_plus.png" );
 		questionText.removeAttribute( "style" );
 		answerText.setAttribute( "style", "display: none" );
	}
}

function cowonFaqToggleAll() {
	for ( var i = 1; document.getElementById( "faq-" + i ); ++i )
		cowonFaqToggle( i );
}

function cowonGallerySwap( galleryInit, num ) {
	// num is which place to swap (0..2 = small image, 3 = large image)
	// requires an 4-element array of objects named "gallery" containing small and large member variables e.g. in JSON
	// notation [[{small: 41, large: 61 }],[{small: 42, large: 62 }],[{small: 43, large: 63 }],[{small: 44, large: 64 }]];
	
	// Initialize gallery array if not set
	if ( ( typeof gallery ) != "object" )
		gallery = galleryInit;
	
	// Get pics to swap
	var big = document.getElementById( "gallery-big" );
	var small = document.getElementById( "gallery-small" + num );
	
	// Num is now the active image
	var temp = gallery[ num ];
	gallery[ num ] = gallery[ 3 ];
	gallery[ 3 ] = temp;
	
	// Now, put the big version of the formerly small picture to the big place
	big.setAttribute( "src", "?page=file&id=" + temp.large );
	
	// first, put the small version of the formerly big picture to the small place
	small.setAttribute( "src", "?page=file&id=" + gallery[ num ].small );
}

function cowonProdSelHoverEnd( picId, hoveredProd, hoveredProdNum ) {
	// Switch image
	hoveredProd.src = '?page=file&id=' + picId;
	
	// Hide "Zur Produktseite" image
	if ( ( typeof lowestProd ) != "number" )
		lowestProd = 0;
		
	var imgElement = document.getElementById( "toprodpage-img-" + ( hoveredProdNum - lowestProd ) );
	imgElement.style.visibility = "hidden";
}

function cowonProdSelHoverStart( picId, hoveredProd, hoveredProdNum ) {
	// Switch image
	hoveredProd.src = '?page=file&id=' + picId;
	
	// Show "Zur Produktseite" image
	if ( ( typeof lowestProd ) != "number" )
		lowestProd = 0;
		
	var imgElement = document.getElementById( "toprodpage-img-" + ( hoveredProdNum - lowestProd ) );
	imgElement.style.visibility = "visible";
}

function cowonProdSelInit() {
	var prodSelDiv = document.getElementById( "prodsel" );
	
	// Hide scrollbar when JS is enabled
	prodSelDiv.style.overflow = "hidden";
	scrollState = 0;
}

function cowonProdSelScrollLeft( maxProd ) {
	// Lowest product visible
	if ( ( typeof lowestProd ) != "number" )
		lowestProd = 0;
	
	// Don't scroll too far right
	if ( lowestProd <= 0 )
		return;
	
	// Update scrolled view
	--lowestProd;
	scrollTarget = lowestProd * 235;
	
	// Install callback
	cowonProdSelScrollCallback();
}

function cowonProdSelScrollRight( maxProd ) {
	// Lowest product visible
	if ( ( typeof lowestProd ) != "number" )
		lowestProd = 0;
	
	// Don't scroll too far right
	if ( lowestProd + 4 >= maxProd )
		return;
	
	// Update scrolled view
	++lowestProd;
	scrollTarget = lowestProd * 235;
	
	// Install callback
	cowonProdSelScrollCallback();
}

function cowonProdSelScrollCallback() {
	var prodSel = document.getElementById( "prodsel" );
	var curScroll = prodSel.scrollLeft;
	
	// Target position not reached?
	if ( curScroll != scrollTarget ) {
		// Try to make a smooth stop
		var step = Math.ceil( Math.abs( curScroll - scrollTarget ) / 15 );
		
		if ( curScroll < scrollTarget )
			curScroll += step;
		else
			curScroll -= step;
		
		prodSel.scrollLeft = curScroll;
		
		setTimeout( "cowonProdSelScrollCallback()", 20 );
	}
}

function cowonTestDevicesUpdateCapacities( capacities ) {
	var comboBox = document.getElementById( "capacities-combobox" );
	
	comboBox.options.length = 0;
	
	// Got entries? -> Fill them in
	for ( var i = 0; i < capacities.length; ++i ) {
		var optName = capacities[ i ];
		var optValue = capacities[ i ];
		
		if ( optValue.length == 0 )
			optName = "Bitte Produkt selektieren";
		
		comboBox.options[ comboBox.options.length ] = new Option( optName, optValue );
	}
}