var content_height = 0;

function adjustSize() {
	$('#main').css({height: 'auto'})
	if ($('body.home').size() == 0) {
		$('#main').css({height: $('#content').height()+$('#top').height()-$('#loga').height()})
	} else {
		var diff = $("#content").height()-content_height
		//console.log('diff: '+diff+' bh: '+content_height)
		//$('#content').height()-$('#top').height()-$('#loga').height()+diff+30
		$('#main').css({height: $('#main').height()+diff})
	}
}

$(window).load(function() {
	content_height = $("#content").height()
	$("#content").bind('DOMSubtreeModified', function(e) {
	    if (content_height != $("#content").height()) {
	    	//console.log($("#content").height())
	    	adjustSize()
	    }
	});
})

$(function () {
	
	$('#btn-send').val('')
	
	$('#intro').flash({
		src: _BASE_URL+'static/flash/intro.swf',
		width: 680,
		height: 265,
		wmode: 'transparent',
		flashvars: { config: _BASE_URL+'static/flash/intro.json?'+Math.random() }
	}, { version: 9 });

	$('#loga .flash').flash({
		src: _BASE_URL+'static/flash/scroll.swf',
		width: 660,
		height: 49
		//wmode: 'transparent',
		//flashvars: { config: _BASE_URL+'static/flash/intro.json?'+Math.random() }
	}, { version: 9 });
	
	$('#category-tree li').prepend('<span class="toggler">&nbsp;</span>')
	$('#category-tree li ul').hide().each(function () {
		$(this).parent().find('.toggler').eq(0).addClass('toggler-plus').click(function () {
			$(this).parent().find('ul').toggle()
			$(this).toggleClass('toggler-minus')
			adjustSize()
		})
	})
	
	/*$('.link-katalog').mouseover(function () {
		$('#categories').css({left: $('#content .row').offset().left+5, top: $('#header').height()}).fadeIn('slow')
		$('#categories').data('over', true)
	})

	$('.link-katalog').mouseout(function () {
		$('#categories').data('over', false)
		setTimeout("checkCategories()", 1000)
	})

	$('#categories').hover(
		function () { $('#categories').data('over', true) },
		function () { $('#categories').data('over', false); setTimeout("checkCategories()", 1000) }
	)*/
	
	if ($('#map').size() > 0) {
		var point = new google.maps.LatLng(49.93180, 19.98349)
		var opts = {
		  zoom: 14,
		  center: point,
		  mapTypeId: google.maps.MapTypeId.SATELLITE
		}
		var map = new google.maps.Map(document.getElementById("map"), opts)
		var marker = new google.maps.Marker({
			position: point,
			map: map,
			title: "Met-Gal"
		})
	}
	
	$('.kgallery a, .photo-area .photo').fancybox({
		'transitionIn'	:	'expo',
		'transitionOut'	:	'expo',
		'titlePosition'	:	'over',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'		:	'easeOutExpo',
		'easingOut'		:	'easeInExpo',
		'speedOut'		:	600,
		'speedIn'		:	600
	})
	
	//adjustSize()
})

function checkCategories() {
	if ($('#categories').data('over') == false) { $('#categories').fadeOut('slow') }
}

