var actualRoom = null;
var actualRoomLoading = false;

$(document).ready(
	function() {
		Cufon.replace('#header h1#header_hoopoe', {
			textShadow: '#7f9344 0px 2px, #9ab152 0px -2px, #9ab152 -2px 0px, #9ab152 2px 0px',
			hover: {
				textShadow: '#95ab52 0px 2px, #adc85f 0px -2px, #adc85f -2px 0px, #adc85f 2px 0px'
			}
		});
		Cufon.replace('#header_hoopoe_lang', {
			textShadow: '#c9d6a2 0px 2px, #c9d6a2 0px -2px, #c9d6a2 -2px 0px, #c9d6a2 2px 0px'
		});

		var params = {
			'titlePosition'	: 'inside'	
		}
		$("a[href$='.jpg'], a[href$='.png']").each(function() {
			var t = $(this).next(':first');
			if (t.get(0) && t.get(0).nodeName == 'div') {
				params['title'] = t.html();
			}
			$(this).fancybox(params);
		});

		$('#flashbox_ul').innerfade({
			speed: 'slow',
			timeout: 4000,
			type: 'random_start',
			containerheight: 'auto'
		});
				
		$('.changer #house').fadeIn();
		actualRoom = $('.changer #house'); 
		$('.changer .changerGallery a[href$=.jpg]').fancybox(params);
		$('.changer .graphics a').click(function(){
			var link = this;
			if (actualRoomLoading || ('#' + actualRoom.attr('id')) == $(link).attr('href')) {
				return false;
			}
			actualRoomLoading = true;
			actualRoom.fadeOut('slow', function(){
				actualRoom = $($(link).attr('href'));
				actualRoom.fadeIn();
				$('.changer .changerGallery a[href$=.jpg]').fancybox(params);
				actualRoomLoading = false;
			});
			
			return false;
		});

		$("#mov1").click(function(e) {
			e.preventDefault();
			$.fancybox({
					'padding'	: 0,
					'autoScale'	: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'title'		: $(this).children("img").attr("alt"),
					'width'		: 500,
					'height'	: 350,
					'href'		: this.href,
					'type'		: 'swf'
				});
		});

		$("#mov2, #mov3").click(function(e) {
			e.preventDefault();
			$.fancybox({
					'padding'	: 0,
					'autoScale'	: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'title'		: $(this).children("img").attr("alt"),
					'width'		: 680,
					'height'	: 495,
					'href'		: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type'		: 'swf'
				});
		});
	}
);

function reset(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).reset();
	}
}

function submit(id) {
	if (document.getElementById(id) && checkform(id)) {
		document.getElementById(id).submit();
	}
}

function checkform(id) {
	if (id == 'gb_form') {
		return checkGuestbookForm();
	}
	else if (id == 'message_form') {
		return checkMessageForm();
	}
	else if (id == 'contact_form') {
		return checkContactForm();
	}
	else if (id == 'cart_form') {
		document.getElementById('update').value = 'true';
		return true;
	}
	else if (id == 'order_form') {
		return checkOrderForm();
	}
	return false;
}

function checkGuestbookForm() {
	if (document.getElementById('name').value == "" || document.getElementById('email').value == "" || document.getElementById('comment').value == "") {
		return false;
	}
	return true;
}

function checkMessageForm() {
	if (document.getElementById('email').value == "" || document.getElementById('message').value == "") {
		return false;
	}
	document.getElementById('send_message').value = 'true';
	return true;
}

function checkContactForm() {
	if (document.getElementById('email').value == "" || document.getElementById('name').value == "") {
		return false;
	}
	document.getElementById('send_form').value = 'true';
	return true;
}

function checkOrderForm() {
	var error = false;
	var errorMessage = i18n.errorForm;	
	
	if (document.getElementById('name').value == "") {
		errorMessage += i18n.errorFirstName;
		error = true;
	}
	if (document.getElementById('surname').value == "") {
		errorMessage += i18n.errorName;
		error = true;
	}
	if (document.getElementById('company').value != "" && document.getElementById('nip').value == "") {
		errorMessage += i18n.errorNIP;
		error = true;
	}
	if (document.getElementById('email').value == "") {
		errorMessage += i18n.errorEmail;
		error = true;
	}
	if (document.getElementById('address').value == "") {
		errorMessage += i18n.errorStreet;
		error = true;
	}
	if (document.getElementById('postcode').value == "") {
		errorMessage += i18n.errorPostalCode;
		error = true;
	}
	if (document.getElementById('place').value == "") {
		errorMessage += i18n.errorCity;
		error = true;
	}
	if (document.getElementById('district').selectedIndex == 0) {
		errorMessage += i18n.errorVoivodeship; 
		error = true;
	}
	if (document.getElementById('phone').value == "") {
		errorMessage += i18n.errorPhone;
		error = true;
	}
	if (document.getElementById('payment_form').selectedIndex == 0) {
		errorMessage += i18n.errorPaymentWay;
		error = true; 
	}	
	if (document.getElementById('agreement').checked == false)	{
		errorMessage += i18n.errorData;
		error = true; 
	}
		
	if (error) {
		alert(errorMessage);
		return false;
	}
	else {
		return true;
	}
}



function initialize(title, zoom) {
    if (GBrowserIsCompatible()) {
      var map = new GMap2(document.getElementById("map_canvas"), {size: new GSize(500, 330) });
      
      var coords = new GLatLng(52.585216,14.821329);
      map.setCenter(coords, zoom);
      map.setUIToDefault();
      var pompa = new GMarker(coords);
      map.addOverlay(pompa);
      var textNode = "<p class='fl c no_indent' style='margin: 15px 0 0 15px; width: 130px; font-weight: bold;'>"+ title +"</p><img style='margin: 5px 30px 0 0' src='/img/dudek_maly.png' alt='BTP Dudek'/>";


      pompa.bindInfoWindowHtml(textNode);        
      pompa.openInfoWindowHtml(textNode);
    }
  }






