$(function() {
	/* main menu*/
	var menuitems = $("#mainmenu li");
	menuitems.each(function() {
		$(this).append("<div class='bg'><div class='c1'></div><div class='c2'></div><div class='c3'></div></div>");
		$(".bg",this).width($(this).outerWidth());
	});
	menuitems.hover(function() {
		menuitems.removeClass("show");
		$(this).addClass("show");
	}, function() {
		$(this).removeClass("show");
	});

	/* language selector */
	$("#langSelect > li").hover(function() {
		$("#langSelect ul").show();
	}, function() {
		$("#langSelect ul").hide();
	});
	
	/* lightbox */
	$("a[rel='lightbox']").lightBox();
	
	if ($(".productbox").length) {
		var row = 0;
		var box_1 = ''; var box_2 = ''; var box_3 = '';
		var row_height = 0;
		$(".productbox").each(function (i) {
			if (i%3==0) {
				row = row + 1;
				box_1 = '#productbox_'+(row*3-3);
				box_2 = '#productbox_'+(row*3-2);
				box_3 = '#productbox_'+(row*3-1);
				if ($(box_1).height()>$(box_2).height()) {
					if ($(box_1).height()>$(box_3).height()) row_height = $(box_1).height();
					else row_height = $(box_3).height();
				} else {
					if ($(box_2).height()>$(box_3).height()) row_height = $(box_2).height();
					else row_height = $(box_3).height();
				}
				$(box_1).height(row_height);
				$(box_2).height(row_height);
				$(box_3).height(row_height);
			}
	  });
	}
});

/* Térkép */
var map;
var geocoder;

function initialize() {
	if ($("#map_canvas").attr('id')=='map_canvas') {
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map_canvas"));
			geocoder = new GClientGeocoder();
			map.setCenter(new GLatLng(47.6091732, 19.1081273), 14);
			showLocation();
			map.setUIToDefault();
			map.removeMapType(G_PHYSICAL_MAP);
			map.setMapType(G_HYBRID_MAP); 
		}
	}
}

function showLocation() {
	geocoder.getLocations('1225 Budapest, Dűlő utca 4.', addAddressToMap);
}

function addAddressToMap(response) {
	map.clearOverlays();
	if (!response || response.Status.code != 200) {
		alert("Sorry, we were unable to geocode that address");
	} else {
		place = response.Placemark[0];
		
		point = new GLatLng(place.Point.coordinates[1],
												place.Point.coordinates[0]);
		marker = new GMarker(point);
		map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]), 14);
		map.addOverlay(marker);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindow('<div style="width: 300px; height: 80px; z-index: 10;">'+
			'<strong>Duna Élzáró Kft.</strong><br /><br />'+
			'1225 Budapest, Dűlő utca 4.<br />'+
			'Tel.: (+36 1) 207-6301<br />'+
			'Fax: (+36 1) 207-6299'+
			'</div>');
		});
	}
}
