function drawStadiumMaps() {
	$('.stadiumMap').each(function(index) {
		if ($(this).is(':visible')) {
			drawStadiumMap($(this).attr('id'));
		}
	});
}

function drawStadiumMap(mapId) {
	$('#' + mapId + ' .draggableContainer').draggable();
	
	drawStadiumMapPoints(mapId);
}

function drawStadiumMapPoints(mapId) {
	$('#' + mapId + ' .point').each(function(index) {
		drawStadiumMapPoint($(this).attr('id'));
	});
}

function drawStadiumMapPoint(pointId) {
	var pointParts = pointId.split('_');
	
	$('#' + pointId).bind('click', function(event) {
		if ($('#stadiumMapPointBubble_' + String(pointParts[1]) + '_sectionTarget').val()) {
			switchStadiumMap($('#stadiumMapPointBubble_' + String(pointParts[1]) + '_sectionTarget').val(), $('#hiddenEventId').val(), $('#hiddenStadiumId').val(), $('#hiddenShowTimeId').val());
		} else {
			
		}
	});
	
	$('#' + pointId).hover(
		function(event) {
			$('#tooltipText_' + String(pointParts[1])).fadeIn('fast');
		},
		function(event) {
			$('#tooltipText_' + String(pointParts[1])).fadeOut('fast');
		}
	);
}

function closeStadiumPricingBubble(pointId) {
	$('#stadiumMapPointBubble_' + String(pointId)).fadeOut('fast');
}


function switchStadiumMap(sectionId, eventId, stadiumId, showTimeId) {
	$('#stadiumSeatsBlock').html('<center><img src="tickets/images/loader-bar-trans.gif" /></center>');
	$.ajax({
		url: 'tickets/engine/pages/stadiumSeatsBlock.php',
		type: 'post',
		data: [{ name: 'sectionId', value: sectionId }, { name: 'eventId', value: eventId }, { name: 'showTimeId', value: showTimeId }, { name: 'stadiumId', value: stadiumId }, { name: 'switcher', value: 1 }],
		success: function(transport) {
			$('#stadiumSeatsBlock').html(transport);
		}
	});
}

function changeStadium(eventId) {
	$('#stadiumSeatsBlock').html('<center><img src="tickets/images/loader-bar-trans.gif" /></center>');
	$.ajax({
		url: 'tickets/engine/pages/stadiumSeatsBlock.php',
		type: 'post',
		data: [{ name: 'stadiumId', value: $('#eventStadium').val() }, { name: 'eventId', value: eventId }, { name: 'switcher', value: 1 }],
		success: function(transport) {
			$('#stadiumSeatsBlock').html(transport);
		}
	});
}

function applyReservationCode(eventId, stadiumId, showTimeId) {
	var groupReservationCode = $('#groupReservationCode').val();
	$('#stadiumSeatsBlock').html('<center><img src="tickets/images/loader-bar-trans.gif" /></center>');
	$.ajax({
		url: 'tickets/engine/pages/stadiumSeatsBlock.php',
		type: 'post',
		data: [{ name: 'applyCode', value: '1' }, { name: 'groupReservationCode', value: groupReservationCode }, { name: 'eventId', value: eventId }, { name: 'showTimeId', value: showTimeId }, { name: 'stadiumId', value: stadiumId }],
		success: function(transport) {
			$('#stadiumSeatsBlock').html(transport);
		}
	});
}
