/*
 * for calendar
 *
 * create: 2009.06.06
 * modify: 2009.09.11
 *
 */

window.addEvent('domready', ScrollAfterOpen);


/*----------------------------------------------------------------------
    scroll after open slide (do nothing colse slide)
----------------------------------------------------------------------*/
function ScrollAfterOpen()
{
	var scroll = new Fx.Scroll(window);

	var switches = $$('.slideSwitch');
	var slides = $$('.slideArea');
	var closeButtons = $$('.closeButton');

	switches.each(function(element, i) {
		var slide = new Fx.Slide(slides[i]);

		switches[i].addEvent('click', function(e) {
			e.stop();
			slide.toggle();
		});

		closeButtons[i].addEvent('click', function(e) {
			e.stop();
			slide.slideOut();
		});

		slide.addEvent('complete', function() {
			if (slide.open) {
				// close button.
				switches[i].src = '/calendar/image/btn_close.gif';
				switches[i].onmouseover = function() {this.src = '/calendar/image/btn_close_on.gif';};
				switches[i].onmouseout = function() {this.src = '/calendar/image/btn_close.gif';};
				switches[i].alt = 'CLOSE';
				// scroll.
				var position = switches[i].getPosition();
				scroll.start(position.x, position.y - 30);
			} else {
				// open button.
				switches[i].src = '/calendar/image/btn_open.gif';
				switches[i].onmouseover = function() {this.src = '/calendar/image/btn_open_on.gif';};
				switches[i].onmouseout = function() {this.src = '/calendar/image/btn_open.gif';};
				switches[i].alt = 'OPEN';
			}
		});

		slide.hide();
//		slide.slideOut();
	});
}


/*----------------------------------------------------------------------
    scroll before open slide (do nothing colse slide)
----------------------------------------------------------------------*/
function ScrollBeforeOpen()
{
	var scroll = new Fx.Scroll(window);

	var switches = $$('.slideSwitch');
	var slides = $$('.slideArea');
	var closeButtons = $$('.closeButton');

	switches.each(function(element, i) {
		var slide = new Fx.Slide(slides[i]);

		switches[i].addEvent('click', function(e) {
			e.stop();
			if (!slide.open) {
				// go to open.
				var position = this.getPosition();
				scroll.start(position.x, position.y - 30).chain(function(){slide.toggle();});
			} else {
				// go to close.
				slide.toggle();
			}
		});

		closeButtons[i].addEvent('click', function(e) {
			e.stop();
			slide.slideOut();
		});

		slide.addEvent('complete', function() {
			if (slide.open) {
				// close button.
				switches[i].src = '/calendar/image/btn_close.gif';
				switches[i].onmouseover = function() {this.src = '/calendar/image/btn_close_on.gif';};
				switches[i].onmouseout = function() {this.src = '/calendar/image/btn_close.gif';};
				switches[i].alt = 'CLOSE';
			} else {
				// open button.
				switches[i].src = '/calendar/image/btn_open.gif';
				switches[i].onmouseover = function() {this.src = '/calendar/image/btn_open_on.gif';};
				switches[i].onmouseout = function() {this.src = '/calendar/image/btn_open.gif';};
				switches[i].alt = 'OPEN';
			}
		});

		slide.hide();
//		slide.slideOut();
	});
}
