

/********** tell a friend *************/
window.form_friend_options = {
	duration:		700,
	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
};


window.addEvent('domready', function() {
	// load menus
	Asset.javascript('assets/js/class/Menus.js', {
		onload: function() {
			window.MainMenu = new Menus('mainmenu');
		}
	});


	// load cart widget
	Asset.javascript('assets/js/class/ShopCart.js', {
		onload: function() {
			window.Cart = new ShopCart({
				anchor: 'btnCart',
				align: 'center',
				width: 320
			});
		}
	});

	// methods for db forms
	Asset.javascript('assets/js/forms.js');

	// tree view
	Asset.css('assets/css/TreeView.css');
	Asset.javascript('assets/js/class/TreeView.js', {
		onload: function() {
			new TreeView('tradedocs', {
				onOverFunction: function() { }
			});
		}
	});

	// buttons
	new Buttons();
});


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/, '');
			}
		});
	});

});



