var map;
function initialize()
{
	var latlng = new google.maps.LatLng(46.249238,6.203476);
	var myOptions = {
		zoom: 16,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map = new google.maps.Map(document.getElementById("map"), myOptions);
	var marker = new google.maps.Marker({
		position: latlng
	});
	marker.setMap(map);
}
$(document).ready(function(){
	$('.menu a,.submenu a').each(function() {
		if (this.id)
		{
			$(this).click(function() {
				$(this).addClass('selected');
				$('#b'+this.id.substr(1)).show();
				return false;
			});
		}
	});

	$('.page_area').hover(function() {
		$('#page_image').stop().animate({
			width: '954px'
		});
	},
	function() {
		$('#page_image').stop().animate({
			width: '420px'
		});
	});

	$('.checkbox_off,.checkbox_on').click(function() {
		if ($(this).hasClass('checkbox_off'))
		{
			$(this).attr('class', 'checkbox_on');
			$('#'+$(this).attr('id')+'Var').val(1);
		}
		else
		{
			$(this).attr('class', 'checkbox_off');
			$('#'+$(this).attr('id')+'Var').val(0);
		}
	});

	$('.date_list a').click(function() {
		$('.date_list a').each(function() {
			$(this).removeClass('selected');
		});
		$(this).addClass('selected');
		if ($(this).attr('rel').substr(1) == 1)
		{
			$('#reduced-price1').css('display', 'none');
			$('#reduced-price2').css('display', 'none');
			$('#reduced-price3').css('display', 'none');
		}
		else
		{
			$('#reduced-price1').css('display', '');
			$('#reduced-price2').css('display', '');
			$('#reduced-price3').css('display', '');
		}
		$('#EventID').val($(this).attr('id').substr(1));
		return false;
	});

	$('#reserve').click(function() {
		var a = new Object;
		for (var i = 0; i < this.form.elements.length; i++)
		{
			if (this.form.elements[i].value == '') this.form.elements[i].value = this.form.elements[i].defaultValue;
			a[this.form.elements[i].name] = this.form.elements[i].value;
		}
		$('#error').hide();

		var fields = new Array('FullBilets', 'ReducedBilets', 'FirstName', 'LastName', 'Phone', 'Email');
		for (var i in fields)
		{
			$('#'+fields[i]).css('background-color', '#ffffff');
		}
		$('#loading').show();
		$('#reserve').attr('disabled', 'disabled');

		JsHttpRequest.query(
			projectPath+'infoblock/ajax.php',
			a,
			function(result, errors)
			{
				$('#reserve').attr('disabled', '');
				$('#loading').hide();
				if (result.Placed)
				{
					$('.date_list a').each(function() {
						if ($(this).hasClass('selected'))
						{
							$('#date-placed').html($(this).html());
						}
					});
					$('#full-bilets').html(result.FullBilets);
					$('#reduced-bilets').html(result.ReducedBilets);
					$('#total').html(result.Total);
					$('#reservation-placed').show();
					$('#reservation-form').hide();
				}
				else
				{
					$('#error').html(result.Error);
					$('#error').fadeIn();
					if (result.ErrorFields)
					{
						for (var i in result.ErrorFields)
						{
							$('#'+result.ErrorFields[i]).css('background-color', '#FC8D8D');
						}
					}
				}
			}
		);
	});

	$('#media-list a').click(function() {
		if ($('#main-gallery-image').attr('src') != $(this).attr('href'))
		{
			$('#loading-gallery').show();
			$('#media-list a').each(function(e) {
				$(this).removeClass('selected');
			});
			$(this).addClass('selected');
			$('#main-gallery-image').attr('src', $(this).attr('href'));
		}
		return false;
	});

	$('#main-gallery-image').load(function() {
		$('#loading-gallery').hide();
	});

	$('#showmap').bind('click', function(){
		if (!map) initialize();
		$('.page_image, #showmap').hide();
		$('#map, #hidemap').show();
		$('#map').css('z-index', '3000');
		return false;
	});

	$('#hidemap').bind('click', function(){
		$('.page_image, #showmap').show();
		$('#map, #hidemap').hide();
		$('#map').css('z-index', '900');
		return false;
	});
});

