/* (c) 2010 Vojtěch Brázda, www.vbrazda.cz */

onLoad = function() {
	// init Google map
	var el = $('#mapa').get(0);
	if (el) {
		if (GBrowserIsCompatible()) {
			var mapa = new GMap(el);
			mapa.setUIToDefault();
			//mapa.disableScrollWheelZoom(); 
			mapa.setCenter(gmpoint, 13);

			if (gmitems.length){
				//var icons = {1:'/img/pronajmy/i1.png',2:'/img/pronajmy/i2.png',3:'/img/pronajmy/i3.png',4:'/img/pronajmy/i4.png',5:'/img/pronajmy/i5.png'};
				$.each(gmitems,function(index,item){
					//var cIcon = new GIcon({image:icons[item.kat],iconSize:new GSize(24,24),iconAnchor:new GPoint(12,12)});
					//var marker = new GMarker(item.point, {icon:cIcon, title:item.title})
					var marker = new GMarker(item.point, {title:item.title});
				  GEvent.addListener(marker, 'click', function() {
				    window.location.href = item.url;
				  });
					mapa.addOverlay(marker);
				});
			}
		}
	}

	// fancy box
 	$('a[rel*=gallery]').fancybox({
	 	'type':'image'
	});

}


$(document).ready(function(){
	onLoad();

	// vypis nabidek - cela plocha klikaci
	$('#vypis .item table').click(function(){
		 window.location.href = '/'+this.id.replace('i','');
	});

	// odchozi odkazy
	$('a.ext').bind('click',function(event){
		recordOutboundLink(this, 'outgoing', 'nemovitosti.cz');
		event.preventDefault();
	});

	// sledovani prokliku na prvnim odkazu
	$('#sidelinks li, #ssslevy-box li, #footlinks .block h4').click(function(){
		var odkaz = $(this).find('a').get(0);
		//document.location.href = odkaz.href;
		document.location.href = '/?log&pozice='+$(this).index()+'&url='+odkaz.href;
	});

	// sidetabs
	$('#sidetabs .tabs li').click(function(){
		$('#sidetabs .tabs li').removeClass('active');
		$('#sidetabs .tab-content').addClass('hide');
		$(this).addClass('active');
		$('#sidetabs .tab-content:eq('+$(this).index()+')').removeClass('hide');
	});

	// vychozi nastaveni
	$('#sidetabs .tabs li:eq(0)').addClass('active');
	$('#sidetabs .tab-content:gt(0)').addClass('hide');
});

// onUnload
$(window).unload(function(){
	// unload Google map
	var el = $('#mapa');
	if (el.length) {
		GUnload();
	}
});

function recordOutboundLink(link, category, action) {
	try {
		var myTracker=_gat._getTrackerByName();
		_gaq.push(['myTracker._trackEvent', ' + category + ', ' + action + ']);
		setTimeout('document.location = "' + link.href + '"', 100)
	}catch(err){}
}
