function Gallery(parent, images)
{
	var gallery = this;
	this.images = images;
	this.length = images.length;
	this.index = 0;
	this.img = parent.find("img");
	this.counter_element = parent.find(".ic_counter").text(this.index+1);
	this.total_element = parent.find(".ic_total").text(this.length);
	parent.find(".ic_next").click(function() {
		if(gallery.index < gallery.length - 1)
		{
			gallery.index++;
			
		} else {
			gallery.index = 0;
		}	
		gallery.img.attr("src", gallery.images[gallery.index]);
		gallery.counter_element.text(gallery.index + 1);
		return false;
	});
	
	parent.find(".ic_prev").click(function() {
		if(gallery.index > 0)
		{
			gallery.index--;
			
		} else {
			gallery.index = gallery.length-1;
		}	
		gallery.img.attr("src", gallery.images[gallery.index]);
		gallery.counter_element.text(gallery.index + 1);
		return false;
	});	
	
	
	for(i = 0; i < images.length; i++)
	{
		img = new Image();
		img.src=images[i];
	}
}

function Mailinglist(form_id)
{
	var mailinglist = this;
	this.form_id = form_id;
	this.email = $(form_id +' :text');
	$(form_id).submit(function(){
		$.post(this.action, $(this).serialize(), 
				function(data){
					if(data == 'error')
					{
						data = '<em>An error occurred.</em>  Please check your email address and <a href="#" onclick="$(\''+mailinglist.form_id+'\').find(\'div\').toggle(\'slow\');return false;">try again</a>';
					} else {
						data = 'Thanks!';
					}
					$(mailinglist.form_id+"_message").html(data);
					$(mailinglist.form_id).find("div").toggle("slow");
		});
		return false;
	});
	this.email.click(this.clear_email)
	this.email.select(this.clear_email);
	
}

Mailinglist.prototype.clear_email = function(){
	if(this.value=="enter email address")
		this.value='';
};

function clickLink()
{
	window.location = $(this).find("a").attr('href');
}
$(document).ready(function(){
	$(".nav li").click(clickLink);
});
