/*function resizeFlash() {
	var height = $(window).height();
	if (height > 1300)
		height = 1300;
	if (height < 900)
		height = 900;
	
	$('#promo').css({height: height}).attr('height', height);
} */

$(function(){


$('a.print-scheme').click(function(){
    window.print();
    return false;
});

/* ie6 fixes */
if ($.browser.msie && $.browser.version < 7) {
        $.ifixpng('/i/blank.gif');
        $('img').ifixpng();
}

/* popups */
function hidePopups(e){
	var trgt = e.target;
        var curElements = $('.popup:visible').find('*').andSelf();
        if ($.inArray(trgt, curElements) < 0) {
        	$('.popup').hide();
		$(document).unbind('mousedown', hidePopups);
        }
	return true;

};

$('.close', '.popup').click(function(){
	$(this).parents('.popup').hide();
	$(document).unbind('mousedown', hidePopups);
	return false;
});

/* languages popup */
$('.r, .l', '#form-lang, #form-life').css({
	cursor: 'pointer'
}).click(function(){
	$('.popup', $(this).parents('.header-option')).show();
	$(document).bind('mousedown', hidePopups);
});

/* search field value */
var search_default = $('#query').val();
$('#query').focus(function(){
	if ($(this).val() == search_default)
		$(this).val('');
}).blur(function(){
	if ($(this).val() == '')
		$(this).val(search_default);
});

/* accordeon toggle */
$('.accordeon-toggle').click(function(){
	$(this).parent().next('.accordeon').toggle('fast');
	return false;
});
$('.accordeon-hide a').click(function(){
	$(this).parents('.accordeon').hide('fast');
	return false;
});


/* photos */
var photos_noclick = false;
$('.photos p').not('.active p').css({
	visibility: 'visible',
	opacity:    0
});
$('.photos img.frame').not('.active img.frame').css({
	opacity:    0
});
$('.paginator a', '.photos').click(function(){
	if (photos_noclick)
		return false;
		
	if ($(this).hasClass('active'))
		return false;
	
	var $photos = $(this).parents('div.photos');
	var $paginator = $('.paginator', $photos);
	var $active = $('.active', $paginator);
	var $a = $('a:not(.prev):not(.next)', $paginator);
	var $li = $('li', $photos); 
			
	var current = $a.index($active);
	var next    = $a.index(this);
	
	if ($(this).hasClass('prev'))
		next = current - 1;
	else if ($(this).hasClass('next'))
		next = current + 1;

	if (next < 0 || next >= $li.length)
		return false;

	photos_noclick = true;

	$active.removeClass('active');
	$a.eq(next).addClass('active');
	
	$current = $li.eq(current);
	$next    = $li.eq(next);
	
	photos_animate($current, $next)									

	return false;
});

$('img.frame', '.photos').css({cursor:'pointer'}).click(function(){
	if (photos_noclick)
		return false;
		
	var $photos = $(this).parents('div.photos');
	var $paginator = $('.paginator', $photos);
	var $a = $('a:not(.prev):not(.next)', $paginator);
	var $li = $('li', $photos);

	var current = $li.index($(this).parents('li'));
	var next    = current + 1;
	
	if (next >= $li.length)
		next = 0;

	photos_noclick = true;

	$('.active', $paginator).removeClass('active');
	$a.eq(next).addClass('active');
	
	$current = $li.eq(current);
	$next    = $li.eq(next);
	
	photos_animate($current, $next)									

	return false;	

});

function photos_animate($current, $next) {

	$('img.frame, p', $current).animate({
		opacity: 0
	}, 500, function(){
		if ($(this).is('p'))
        		if (this.style.filter && this.style.removeAttribute)
                		this.style.removeAttribute('filter');
	});
	
	$('img.frame, p', $next).animate({
		opacity: 1
	}, 500, function(){
		if ($(this).is('p'))
			if (this.style.filter && this.style.removeAttribute)
                		this.style.removeAttribute('filter');
		photos_noclick = false;
		$current.removeClass('active');
		$next.addClass('active');
		$('.photos p').not('.active p').css({
			opacity:    0
		});
	});

}

});

/* google maps */
function loadMap() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("googlemap"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        
        var point = new GLatLng(mparam.lat, mparam.lng);
        map.setCenter(point, 16, G_NORMAL_MAP);
        
	createMarker(point, html, {});
    }
}

function createMarker(mpoint, tooltip, opts) {
    if (!map) return null;

    mark.push(new GMarker(mpoint, opts));

    GEvent.addListener(mark[mark.length - 1], "click", function() {
        var str = String(tooltip);
        this.openInfoWindowHtml(str);
    });

    map.addOverlay(mark[mark.length - 1]);
    mark[mark.length - 1].openInfoWindowHtml(tooltip);
    return mark[mark.length - 1];
}