// hogdex - events
// (c) Copyright 2009, hogdex
// The Enlarge>> button for images on the detail page

var gImg = null;
// var gDelay = 5;
var gRealWidth = null;
var gMaxShrunkWidth = 250; // const
var gDialogInsideWidth = 670; // const
var gSpeed = 500; // const

function readyToEnlarge() {
	$('#toggle_text').html('Enlarge >>');
	$('#toggle_link').attr({href: 'javascript:enlarge()'});
	$('#toggle_text').slideDown();
}

function readyToShrink() {
	$('#toggle_text').html('<< Back to Details');
	$('#toggle_link').attr({href: 'javascript:shrink()'});
	$('#toggle_text').slideDown();
}

function enlarge() {
	var	width, title;

	width = gRealWidth;
	if (width > gDialogInsideWidth) width = gDialogInsideWidth;
	
	$('#event_image').width(width);
	$('#right_cell').hide(gSpeed);
	$('#map_canvas').hide(0);
	
	title = $('#h1_normal').html();
	$('#h1_enlarged').html(title);
	$('#h1_enlarged').slideDown();

	readyToShrink();
}

function shrink() {
	$('#event_image').width(gMaxShrunkWidth);
	$('#right_cell').slideDown(gSpeed);
	$('#map_canvas').slideDown(0);
	$('#h1_enlarged').hide();
	readyToEnlarge();
}

function checkSizeOnce(url) {
	var	width;

	if ($('#event_image').attr('src') != url) return;
	width = $('#event_image').width();
	if (width > gMaxShrunkWidth) {
		gRealWidth = width;
		$('#event_image').width(gMaxShrunkWidth);
		readyToEnlarge();
	}

	$('#event_image').slideDown(gSpeed);
}

function checkSize(url) {
	gRealWidth = null;
	$('#event_image').load(function() {
		checkSizeOnce(url);
	});
}

