



/********** tell a friend *************/
window.form_friend_options = {
	duration:		700,
	transition:		Fx.Transitions.Cubic.easeOut,
	transition_types:	['morph', 'fade'], // morph, fade
	overlay:		{ color: '#000000', opacity: 0.5, close_on_click: false }
};


/********** optin *************/
window.form_subscribe_options = {
	duration:		700,
	transition:		Fx.Transitions.Cubic.easeOut,
	transition_types:	['morph', 'fade'], // morph, fade
	overlay:		{ color: '#000000', opacity: 0.5, close_on_click: true }
};

/******** gallery **********/
window.gallery_options = {
	overlay: 	{ color: '#000', opacity: 0.6, close_on_click: false },
	background: 	'#fff',
	fontcolor:	'#444',
	border:		'solid gray 1px',
	padding:	'10px',
	image_dir:	'gallery-light',
	fade_duration:	500,
	morph_duration:	400,
	enable_slideshow: true,
	slideshow_delay: 7000
};

function preloadImage(href) {
	if(!window.__preloadImageList) window.__preloadImageList = [];
	window.__preloadImageList.push(href);
}
window.addEvent('load', function() {
	if(window.__preloadImageList) {
		for(var i=0; i<window.__preloadImageList.length; ++i) {
			var n = new Image();	
			n.src = window.__preloadImageList[i];
		}
	}
});


// handle rollover images
window.addEvent('load', function() {
	$$('img,input').each(function(el) {
		if(!el.getAttribute('rollover')) return;

		var pimg = new Element('img');
		pimg.addEvent('load', function() {
			this.addEvent('mouseover', function() {
				imageRollover(this, (this.getAttribute('rollover') == 'true') ? '' : this.getAttribute('rollover'));
			});
			this.addEvent('mouseout', function() {
				imageRollout(this);
			});
		}.bind(el));
		pimg.src = (el.getAttribute('rollover') == 'true') ? el.src.replace(/\.([^\.]+)$/, '-over.$1') : el.getAttribute('rollover');
	});
});


window.addEvent('domready', function() {

	// fade in rollovers
	$$('img.fade').each(function(el) {
		var cfg;
		try { cfg = JSON.decode(el.getAttribute('fade'));  } catch(e) { cfg = {}; };
		if(!cfg) cfg = {};

		if(!cfg.duration) cfg.duration = 300;
		if(!cfg.from) cfg.from = 0.5;
		if(!cfg.to) cfg.to = 1;

		el.setStyle('opacity', cfg.from);
		el.store('fadeConfig', cfg);

		el.addEvents({
			'mouseover': function() {
				var cfg = this.retrieve('fadeConfig');
				new Fx.Tween(this, { duration: cfg.duration }).start('opacity', cfg.to);
			},
			'mouseout': function() {
				var cfg = this.retrieve('fadeConfig');
				new Fx.Tween(this, { duration: cfg.duration }).start('opacity', cfg.from);
			}
		});
	});
});


window.addEvent('load', function() {
	// handle rollover images
	$$('img.rollover').each(function(el) {

		var pimg = new Image();
		pimg.src = el.src.replace(/\.([^\.]+)$/, '-over.$1');

		el.addEvents({
			mouseover: function() {
				this.src = this.src.replace(/\.([^\.]+)$/, '-over.$1');
			},
			mouseout: function() {
				this.src = this.src.replace(/-over/, '');
			}
		});
	});

});




var showMoreHtml = 'Show More <img src="assets/images/arrow-down.png" style="border:none;" align="absmiddle">';
var hideMoreHtml = 'Hide <img src="assets/images/arrow-up.png" style="border:none;" align="absmiddle">';

window.addEvent('domready', function() {
	$$('div.moreContent').each(function(el) {
		if(!el.id) el.id = 'more'+Math.round(Math.random() * 100000);
		var ln = new Element('a', {
			id: 'lnkmore'+el.id,
			href: 'javascript:void(0);',
			title: 'Show More...',
			styles: {
				cursor: 'pointer',
				'text-decoration': 'none',
				display: 'block'
			}
		})
		.addEvent('click', function() {
			moreContent(el.id);
		})
		.set('html', showMoreHtml)
		.injectAfter(el);


	});

});
function moreContent(id) {
	var div = $(id);
	if(!div) return;

	if(div.getStyle('display') == 'none') {
		div.setStyles({
			'overflow': 'hidden',
			height: 1,
			display: 'block'
		});
		new Fx.Tween(div, {
			duration: 500
		}).start('height', div.getScrollHeight());

		var lnk = $('lnkmore'+id);
		if(lnk) lnk.set('html', hideMoreHtml);
	}
	else {
		new Fx.Tween(div, {
			duration: 500,
			onComplete: function() {
				div.setStyle('display', 'none');
			}
		}).start('height', 1);

		var lnk = $('lnkmore'+id);
		if(lnk) lnk.set('html', showMoreHtml);
	}
}

function imageRollover(that, href) {
	that = $(that);
	if(!that) return;

	that.store('rollback', that.src);

	if(!href) href = that.src.replace(/\.([^\.]+)$/, '-over.$1');
	var tmp = new Element('img');
	tmp.addEvent('load', function() {
		this.src = href;
	}.bind(that));
	tmp.src = href;
}

function imageRollout(that) {
	that = $(that);
	if(!that) return;

	//that.src = that.src.replace(/-over\.([^\.]+)$/, '.$1');
	that.src = that.retrieve('rollback');
}





function test(v) {
	try {
		console.log(v);
	} catch(e) {};
}






