/* show/hide our large map */
function show_or_hide_map(div_name) {
	var map = document.getElementById(div_name);
	if (map.style.display=='block')
		map.style.display = 'none';
	else
		map.style.display = 'block';
}

/* rotating images */
var initialized = false;
var current_image_number = 0;
var rotating_images = new Array();
var rotation_delay = 5000;

function rotate_images() {
	// if we haven't initialized let's do that now
	if (! initialized)
	{
		// use jquery to find any image with a class of "rotating_image" and add them to our array
		$(".rotating_image").each(function(i) {
			rotating_images[i] = this;
		});
		initialized = true;
		setTimeout("rotate_images()", rotation_delay);
		return;
	}
	// if the first image doesn't exist, just exit
	if (! rotating_images[0]) return;
	// if the first image has downloaded, continue
	if (rotating_images[0].complete || rotating_images[0].complete == undefined)
	{
		// set the next image we should load
		var next_image_number = current_image_number + 1;
		if (next_image_number >= rotating_images.length) next_image_number = 0;
		// has this image been loaded
		if (rotating_images[next_image_number].complete || rotating_images[next_image_number].complete == undefined)
		{
			// ok, switch to this new image			
			$(rotating_images[current_image_number]).fadeOut("crawl");
			$(rotating_images[next_image_number]).fadeIn("crawl");
			// change the current image to this one
			current_image_number = next_image_number;
		}
		setTimeout("rotate_images()", rotation_delay);		
	}
	else
	{
		// not downloaded yet, check back later
		setTimeout("rotate_images()", rotation_delay);
	}
}

/* tabbed content */
$.fn.tabs = function(options) {
    // basic stuff
    var ON_CLASS = 'on';
    var OFF_CLASS = 'tabs-hide';
    // options
    var on = options && options.on && (typeof options.on == 'number' && options.on > 0) ? options.on - 1 : 0;
    return this.each(function() {
        $(this).find('>div').not(':eq(' + on + ')').addClass(OFF_CLASS);
        $(this).find('>ul>li:eq(' + on + ')').addClass(ON_CLASS);
        var container = this;
        $(this).find('>ul>li>a').click(function() {
            if (!$(this.parentNode).is('.' + ON_CLASS)) {
                var re = /([_\-\w]+$)/i;
                var target = $('#' + re.exec(this.href)[1]);
                if (target.size() > 0) {
                    $(container).find('>div:visible').addClass(OFF_CLASS);
                    target.removeClass(OFF_CLASS);
                    $(container).find('>ul>li').removeClass(ON_CLASS);
                    $(this.parentNode).addClass(ON_CLASS);
                } else {
                    alert('There is no such container.');
                }
            }
            return false;
        });
    });
};