


function equalColumns() {

	if(!$('left') || !$('right')) return false;

	$('left').style.height = '';
	$('right').style.height = '';

	var maxHeight = $('left').getHeight();

	if($('right').getHeight() > maxHeight) {
		maxHeight = $('right').getHeight();
	}

	$('left').style.height = maxHeight+'px';
	$('right').style.height = maxHeight+'px';


}

initAdd(equalColumns);

//also call this on window load, just to double check!!

Event.observe(window, 'load', equalColumns);


function applyEntryButtons() {


	$$('.js_print').each(function(el) {

		el.observe('click', function(e) {

			windowopen(this.href, 'width=500,height=500,resizable,scrollbars', false);

			e.stop();

		 });

	});

	$$('.js_email').each(function(el) {

		el.observe('click', function(e) {

			Modalbox.show(this.href, {title: 'Email this entry', width: 300});

			e.stop();

		 });

	});

}

initAdd(applyEntryButtons);



function load_calendar(timestamp) {

	if(timestamp == null) timestamp = '';

	if(!$('calendar')) return false;

	//pull up any calendar info
	new Effect.BlindUp('calendar_info', { duration: .5, queue: {position: 'end', scope: 'calender_info_scope'}});

	//load a new calendar into it
	new Ajax.Updater('calendar', 'ajax/calendar/?timestamp='+timestamp, { onComplete: function(transport) {

		//if an error came back, then dont go forward anymore
		transportText = ajaxTransportText(transport);
		if(transportText['error']) return false;

		//find the scroll bars
		$$('.calendar_scroll').each(function(el) {

			//when click on a scrollbar, run this function again
			el.observe('click', function(e) {
				load_calendar(this.rel);
				e.stop();
			});

		});

		//find calender days
		$$('.day').each(function(el) {

			//if events_0 is on the classname, then it should not be clickable!
			if(el.className.indexOf('events_0') > -1) return false;

			//when click on day, call load into calendar_info
			el.observe('click', load_calendar_info);

		});

		equalColumns();

	}});


}

//this function is run when a calendar day is clicked
function load_calendar_info() {

	if(!$('calendar_info')) return false;

	var timestamp = $('calendar_'+this.id).value;


	//take off other 'on'
	$('calendar').select('.day').each(function(day) {

		day.removeClassName('on');

	});

	//make this one class = 'on'
	this.addClassName('on');



	//pull up the existing calendar
	new Effect.BlindUp('calendar_info', { duration: .5, queue: {position: 'end', scope: 'calender_info_scope'}, afterFinish: function(el) {

		$('calendar_info').update('<p>Loading events...</p>');
		$('calendar_info').style.display = '';

		//load a new calendar into it
		new Ajax.Updater('calendar_info', 'ajax/calendar/events/?timestamp='+timestamp, { onComplete: function(transport) {

			$('calendar_info').style.display = 'none';

			//if an error came back, then dont go forward anymore
			transportText = ajaxTransportText(transport);
			if(transportText['error']) return false;

			//calendar is ready, pull blind down now
			new Effect.BlindDown('calendar_info', {duration: .5, queue: {position: 'end', scope: 'calender_info_scope'}, afterFinish: function(el) {

				equalColumns();

			}});

		}});


	}});

}

initAdd(load_calendar);



function keyword_toggle_eventsAttach() {

	if(!$('keywords') || !$('keyword_popular_tab')) return false;

	$('keyword_popular_tab').observe('click', function(e) {

		keywords_off();
		this.addClassName('on');
		$('keyword_popular_words').style.display = '';
		e.stop();

	});

	$('keyword_recent_tab').observe('click', function(e) {

		keywords_off();
		this.addClassName('on');
		$('keyword_recent_words').style.display = '';
		e.stop();

	});

	$('keyword_random_tab').observe('click', function(e) {

		keywords_off();
		this.addClassName('on');
		$('keyword_random_words').style.display = '';
		e.stop();

	});

}

function keywords_off() {

	$('keyword_popular_tab').removeClassName('on');
	$('keyword_recent_tab').removeClassName('on');
	$('keyword_random_tab').removeClassName('on');
	$('keyword_popular_words').style.display = 'none';
	$('keyword_recent_words').style.display = 'none';
	$('keyword_random_words').style.display = 'none';

}

initAdd(keyword_toggle_eventsAttach);

function issue_browser() {

	if(!$('issues_scroll')) return false;

	$('issues_scroll').select('.js_issueopen_click').each(function(header) {

		header.observe('click', function() {

			//take off other 'on'
			$('issues_scroll').select('.header').each(function(day) {

				day.removeClassName('on');

			});

			//make this one class = 'on'
			this.addClassName('on');

			var toPull = header.next();

			if(toPull.style.display != 'none') return false; //its already opened, or opening..

			//pull up any opened ones
			$('issues_scroll').select('.images').each(function(image) {

				if(image.style.display == 'none') return false;

				new Effect.BlindUp(image, {scaleContent: false, duration: .4, queue: { position: 'end', scope: 'issue_browse'}});

			});

			new Effect.BlindDown(toPull, {scaleContent: false, duration: .4, queue: {posistagtion: 'end', scope: 'issue_browser'}, afterFinish: function() {

				equalColumns();

			}});

		});

	});

}

initAdd(issue_browser);




function superfooter() {

    Nifty("#super_footer", "big fixed-height");

}


initAdd(superfooter);




function article_mymapsAdd(mapentryID)
{

    var response = '';

    jQuery.ajax({
        url: 'maps/my-maps/add/'+mapentryID+'/',
        async: false,
        success: function(data) {

            response = 'Map added';

        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {

            response = XMLHttpRequest.responseText;

        }
    });

    var responseHTML = '<div class="break"></div>';

    responseHTML += '<p>' + response + '</p>';

    responseHTML += '<p>';
    responseHTML += '  <a href="maps/my-maps/">';
    responseHTML += '      Go to My Maps'
    responseHTML += '  </a>';
    responseHTML += '</p>';

    jQuery('#mapFeedback').html(responseHTML).slideDown('normal', function() {

        equalColumns();

    });

    return false;

}

function article_mymapsRemove(mapentryID)
{

    if(!confirm('Are you sure you want to remove this from your maps?')) {

        return false;

    }

    var response = '';

    jQuery.ajax({
        url: 'maps/my-maps/remove/'+mapentryID+'/',
        async: false,
        success: function(data) {

            response = 'Map removed';

        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {

            response = XMLHttpRequest.responseText;

        }
    });

    var responseHTML = '<div class="break"></div>';

    responseHTML += '<p>' + response + '</p>';

    responseHTML += '<p>';
    responseHTML += '  <a href="maps/my-maps/">';
    responseHTML += '      Go to My Maps'
    responseHTML += '  </a>';
    responseHTML += '</p>';

    jQuery('#mapFeedback').html(responseHTML).slideDown('normal', function() {

        equalColumns();

    });

    return false;

}