// ie png fix
if (document.all && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule) 
{ document.styleSheets[0].addRule('*','behavior: url(/js/iepngfix/iepngfix.htc)'); }


var SafeEmail = new Class
({
	options : 
	{
		'user' : ''
		, 'host' : '' // example.com or example (using tld)
		, 'tld' : '' // .com, .net, .org (with the dot)
		, 'subject' : ''
	},

	initialize : function(options)
	{
		this.setOptions(options);
	},

	getMailto : function()
	{
		var mailto = 'mailto:' + this.getEmail() ;
		if (this.options.subject) mailto += '?subject=' + this.options.subject ;
		return mailto;
	},

	getEmail : function()
	{
		var email = this.options.user + '@' + this.options.host + this.options.tld ;
		return email;
	},

	injectLink : function(container,linkText,cssClass)
	{
		new Element('a',
		{
			'href': this.getMailto()
			, 'class': cssClass ? cssClass : 'email-link'
			,  'html': linkText ? linkText : this.getEmail()
		}).inject($(container));
	}
});

SafeEmail.implement(new Options);


var Slideshow = new Class 
({
	options: 
	{
		'duration': 5000
		, 'images': []
		, 'container': 'slideshow'
		, 'start': 0
	},

	i: -1,
	first_run: false,

	initialize : function(options)
	{
		this.setOptions(options);
		new Asset.images(this.options.images,{'onComplete': this.next.bind(this)});
	},

	next : function()
	{
		// next image
		this.i = (this.i == (this.options.images.length - 1)) ? 0 : this.i + 1 ;

		// set starting image
		if (!this.first_run && this.options.start) 
		{
			this.first_run = true; // first run, prevents infinite loop
			this.i = this.options.start - 1; // next loop increments to correct number
			this.next.delay(this.options.duration,this); // auto delay
			return;
		}
		
		// current element
		var c = $(this.options.container).getElement('img');

		// hide current
		if (c)
		{
			c.fade('out');
			c.destroy.delay(1250,c); // wait then destroy
		}

		// new element
		new Element('img',
		{
			'src': this.options.images[this.i]
			, 'alt': ''
			, 'style':'position:absolute;'
		}).inject($(this.options.container)).fade('hide').fade('in');

		// show next after duration
		this.next.delay(this.options.duration,this);
	}
});

Slideshow.implement(new Options);