var GoogleMapsAPI_initialize = function() {
	var Tiffanpince = new google.maps.LatLng(45.881513, 18.428871),
	    myOptions = {
			zoom: 17,
			center: Tiffanpince,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		},
		Villanykovesd = new google.maps.Map(document.getElementById("GoogleMap"), myOptions),
		pinceIkon = new google.maps.Marker({
			position: Tiffanpince,
			map: Villanykovesd,
			icon: 'images/tiffan_map_pointer.png'
		});
}

function slideSwitch() {
	var container = $('#header_img'),
		$active = $('img.active', container);

	if($active.length==0) {$active = $('img:last', container);}

	var $next =  $active.next().length ? $active.next() : $('img:first', container);

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

jQuery(function(){
	$('<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&callback=GoogleMapsAPI_initialize"></script>').appendTo('body');
	
	$("a[rel=level]").each(function(i,o){
		var c = $(o).html().replace(' kukac ', '@');
		c = c.replace(' pont ', '.');
		$(o).attr('href', 'mailto:'+c);
	});

	for(i=27; i>=2; i--)
		{
		$('<img src="images/slideshow/tiffan'+(i<10?'0':'')+i.toString()+'.jpg" alt="" />').prependTo("#header_img");
		}
	
	setInterval("slideSwitch()", 5000);

	var hibauzenet = function(msg, focusnode){
		alert(msg);
		focusnode.focus();
	};
	
	$("#vendegkonyv_bekuld").submit(function(){
		if($("#nev", $(this)).val().length==0){
			hibauzenet("Kérjük, adja meg a nevét!", $("#nev", $(this)));
			return false;
		}
		
		var uzenetLen = $("#uzenet", $(this)).val().length, uzenetMaxLen = 2000;
		
		if(uzenetLen==0){
			hibauzenet("Kérjük, írj üzenetet!", $("#uzenet", $(this)));
			return false;
		}
		
		if(uzenetLen>uzenetMaxLen){
			hibauzenet("Kérjük, az üzenet hossza ne legyen több "+uzenetMaxLen+" karakternél\nAz Ön üzenete most "+uzenetLen+" karakter hosszú", $("#uzenet", $(this)));
			return false;
		}
		
		$(this).attr("action", "");
		return true;
	});
});

