// JavaScript Document

Event.observe(window, 'load', function() {
	$$('a.pic_control').each(function(ele) {
		ele.observe('click', function(e) {
			e.stop();
			changePicture(ele.getAttribute('id'));
		});
	});
	
	if ($('picture_click')) {
		$('picture_click').observe('click', function(e) {
			e.stop();
			var ele = Event.element(e);
			
			window.open('images/listing_images/' + large_images[ele.getAttribute('name')]);
		});
	}
});

var changePicture = function(id) {
	if (id == 'picture_left') {
		images_count = (images_count == 0) ? images.length - 1 : images_count - 1;
	} else {
		images_count = (images_count == (images.length - 1)) ? 0 : images_count + 1;
	}
	
	var a = new Element('a').update(new Element('img', { src: 'images/listing_images/' + images[images_count], name: images_count })).observe('click', pictureClick);
	$('picture').update(a);
	$('pic_caption').update(captions[images_count]);
};

var pictureClick = function(e) {
	e.stop();
	var ele = Event.element(e);
	
	window.open('images/listing_images/' + large_images[ele.getAttribute('name')]);
};


function spamFreeEmailAddress(linkText,userName,self_titled){
	var domain='visittablerocklake.com';	
	var emailE = userName + '@' + domain;
	if (self_titled) {
		document.write('<a href="mailto:' + emailE + '">' + emailE + '</a>');
	} else {
		document.write('<a href="mailto:' + emailE + '">' + linkText + '</a>');
	}
}
