$(function() {
	$('#container').vAlign();
	menuCreate();
	$(window).bind('resize', function() {
		$('#container').vAlign();
		beauty_pos();
	});
	$('.scrollable').jScrollPane({
		scrollbarWidth: 10,
		scrollbarMargin: 10,
		showArrows: true,
		arrowSize: 10,
		reinitialiseOnImageLoad: true
	});
	beauty_pos();
	$('#nyitokepek').cycle({
		fx: 'scrollLeft',
		speed: 200,
		timeout: 3500,
		random: 0,
		cleartypeNoBg: true,
		cleartype: true,
		requeueOnImageNotLoaded: true,
		requeueTimeout: 250,
		sync: 1
	});

	$('a.map').click(shopMap.openMap);
	setTimeout('myLytebox.doAnimations = false;', 1000);
});

function beauty_pos() {
	$('span#beauty_forever').css({
		left: $('#leftmenu_pic').position().left + 100,
		top: $('#leftmenu_pic').position().top + 240
	});
}

function menuCreate(){
	$('.vertMenu').buildMenu({
		menuWidth: 250,
		openOnRight: true,
		menuSelector: '.menuContainer',
		hasImages: false,
		fadeInTime: 200,
		openOnClick: false,
		closeOnMouseOut: true,
		closeAfter: 500
	}).find(".rootVoice:not([class='{menu'])").hover(
		function() {
			$(this).addClass('selected');
		},
		function() {
			$(this).removeClass('selected');
		}
	);

};

function setLeftPic() { 
	$('#leftmenu>ul').not(':has(li)').prepend('<img src="images-73/leftpic.jpg" />');
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split('&');
  for(var i = 0; i < vars.length; i++) {
		var pair = vars[i].split('=');
    return pair[0] == variable ? pair[1] : 0;
  }
}
function loadcontent(id, url, el) {
	if(id == getQueryVariable('m')) $(el).load(url);
}

var shopMap = {

	openMap: function(e) {
		var td = $(this)[0].parentNode,
				prev = td.previousSibling;
		while(prev && prev.nodeType != 1) prev = prev.previousSibling;
		document.location = $(this).attr('href') + '&info=' + encodeURIComponent(prev.innerHTML);
		e.preventDefault();
	},

	map: null,
	bounds: null,

	init: function(coord, info) {
		var content = $('#content');
		content.css({
			height: '360px',
			margin: '0 20px 0 0'
		});
		var coords = coord.substr(6).split(',');
		coords[0] = parseFloat(coords[0]);
		coords[1] = parseFloat(coords[1]);
		info = decodeURIComponent(info.substr(5).replace(/\+/g, ' '));

		this.map = new google.maps.Map($('#content')[0], {
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			center: new google.maps.LatLng(coords[0] + 0.001, coords[1])
		});

		var point = new google.maps.LatLng(coords[0], coords[1]);
		var marker = new google.maps.Marker({
			position: point,
			map: this.map
		});

		this.map.setZoom(16);

		var infoWindow = new google.maps.InfoWindow();
		google.maps.event.addListener(marker, 'click', function() {
			infoWindow.setContent(info);
			infoWindow.open(shopMap.map, marker);
		});
		infoWindow.setContent(info);
		infoWindow.open(shopMap.map, marker);
	}

};
