var effects_time = 200;
var effects_lock = false;
var popup_lock = false;

function scroll_h(arg,diff) {
	$(arg).stop().animate({scrollTop: $(arg).scrollTop()+diff}, 1000);
	return false;
}
function scroll_v(arg,diff) {
	$(arg).stop().animate({scrollLeft: $(arg).scrollLeft()+diff}, 1000);
	return false;
}
function menu_swap(menu) {
	if (menu_cat = document.getElementById('menu_cat_'+menu)) {
		if (menu_cat.className == 'cat-closed') {
			menu_cat.className = 'cat';
			$('#menu_cat_list_'+menu).hide().slideDown(effects_time);	
		} else {
			menu_cat.className = 'cat-closed';
			$('#menu_cat_list_'+menu).show().slideUp(effects_time);
		}
	}
	return false;
}
function init_images() {
	$('a.image').live('click',function() {return popup_image(this);});
}
function init_hovers() {
		$('.hover img:not(.hover .active img)')
		.live('mouseover', function () {
				$(this).fadeTo(effects_time,1);
			})
		.live('mouseout', function () {
				$(this).fadeTo(effects_time,0);
			})
		.fadeTo(0,0);
}
function flash_toggle(arg) {
	if (arg) {
		$('.flash').show();
	} else {
		$('.flash').hide();
	}
}
overlay_toggle = function(arg) {
	if (arg && !popup_lock) {
		flash_toggle(false);
		popup_lock = true;
		$('#overlay').show().fadeTo(effects_time,0.7);
	} else if (!arg && popup_lock) {
		$('#overlay').stop().fadeTo(effects_time,0,function() {
			$('#overlay').hide();
			popup_lock = false;
			flash_toggle(true);
			});
	}
	return false;
}
popup_toggle = function(arg) {
	if (arg) {
		$('#popup').stop().css({
			'opacity'	: 0,
			'max-height'	: (minmax('min',$('html').innerHeight(),$('body').innerHeight()) - 70) + 'px',
			'width'		: (minmax('min',$('html').innerWidth(),$('body').innerWidth()) - 70) + 'px',
			'top'		: minmax('max',$('html').scrollTop(),$('body').scrollTop()) + 'px',
			'left'		: minmax('max',$('html').scrollLeft(),$('body').scrollLeft()) + 'px'
			}).show().fadeTo(effects_time,1);
			//todo: fix for ie
	} else {
		$('#popup').stop().fadeTo(effects_time,0,function() {
			$('#popup').hide();
			$('#popup-content').html('');
			});
	}
	return false;
}
popup_close = function() {
	popup_toggle(false);
	return overlay_toggle(false);
}
popup_show = function(code,image) {
	overlay_toggle(true);
	$('#popup-content').html(code);
	popup_toggle(true,image || false);
	return false;
}
popup_image = function(path) {
	return popup_show('<div style="width:100%; text-align:center;"><a href="' + path + '" onclick="return popup_close();"><img src="' + path + '.(' + ($('html').innerWidth() - 130) + 'x' + ($('html').innerHeight() - 130) + ')?nocache=1" alt="" /></a></div>',true);
}
$(init_images);
$(init_hovers);
