function toggle_bank_transfer_form()
{
	if ($('#payment_bank_transfer').attr('checked'))
		$('#bank_transfer_form').show();
	else
		$('#bank_transfer_form').hide();

	// check if a credit card payment with communicationMode == active was chosen
	var chosen = $('input[type=radio][name=payment]:checked').val();
	var found = false;
	// credit_card_payment was set in html.tpl
	for(var i in credit_card_payment_active)
	{
		if(chosen == credit_card_payment_active[i])
		{
			found = true;
			break;
		}
	}
	if(found)	// check for all credit card services that require credit card data at this step
		$('#credit_card_form').show();
	else
		$('#credit_card_form').hide();
}

function pictureBoxTransform()
{
	$('.pictureBox > ul').each(function () {
		var obj = $(this).parent();
		//obj.prepend('<div class="picturePreviewContainer"><a href="'+obj.find('a:first').attr('href')+'"><img src="'+obj.find('a:first img:first').attr('src')+'" class="picturePreview" /></a></div>');
        thumbnailfunc = function (){
			var obj = $(this);
			obj.parents('div.pictureBox').find('img.picturePreview').attr('src', obj.find('img:first').attr('src')).parent().attr('href', obj.attr('href'));
			obj.parents('div.pictureBox').find('li img').removeClass('active');
			obj.find('img').addClass('active');
			return false;
		};
		obj.find('li img').removeClass('active').parent().mouseover(thumbnailfunc).click(function(){initShowroom(this);return false;});
		obj.find('li img:first').addClass('active');
	});
}

$(document).ready(function (){

	$("button, input:submit, a.button").button();

	if($('input[type=radio][name=payment]').length > 0)
	{
		toggle_bank_transfer_form();
		$(':radio[name=payment]').change(function (){toggle_bank_transfer_form();});
	}

	pictureBoxTransform();
	
	// order/address radiosets
	$(function() {
		$(".radioset").buttonset();
	});
});

function openInvoice(url)
{
	$('#invoiceDialog').load(url + ' div:first', "ajax=1", function () {
		$('#invoiceDialog').dialog({
			width:650,
			height:400
			/*,buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}*/
		});
	});
}
