/*
	BiNDFx v1.0
	071023_3
	require mootools v1.11 (http://mootools.net/)
*/
var BiNDFx = {
	version:1.0,
	debug:false
};

/*
	BiNDZoom
	This code based on Slimbox
	by Christophe Beyls (http://www.digitalia.be) - MIT-style license.
*/
var BiNDZoom = new Class({
	groupCount: 0,
	initialize: function(ancs, caps, options){
		this.options = $extend({
			resizeDuration: 200,
			resizeTransition: false,	// default transition
			initialWidth: 250,
			initialHeight: 250,
			showCounter: true,
			useOverlay: false
		}, options || {});
		
		this.imageWidth = 0;
		this.imageHeight = 0;
		this.firstClick = true;
		
		this.addSet(ancs, caps);
		
		this.eventKeyDown = this.keyboardListener.bindAsEventListener(this);
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'styles': {
			'position': 'absolute', 'left': '0', 'width': '100%',
			'background-color': 'transparent', 'cursor': 'pointer', 'display': 'none'
		}}).injectInside(document.body);
		
		this.bindbox = new Element('div', {'id': 'bindbox', 'styles': {
			'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2),
			'display': 'none'}}).injectInside(document.body);
		new Element('div', {'class': 'tl'}).injectInside(this.bindbox);
		new Element('div', {'class': 'tr'}).injectInside(this.bindbox);
		new Element('div', {'class': 'tc'}).injectInside(this.bindbox);
		
		var mm = new Element('div', {'class': 'mm'}).injectInside(this.bindbox);
		new Element('div', {'class': 'ml'}).injectInside(mm);
		new Element('div', {'class': 'mr'}).injectInside(mm);
		
		var mc = new Element('div', {'class': 'mc'}).injectInside(mm);
		
		new Element('div', {'class': 'bl'}).injectInside(this.bindbox);
		new Element('div', {'class': 'br'}).injectInside(this.bindbox);
		new Element('div', {'class': 'bc'}).injectInside(this.bindbox);
		
		this.image = new Element('div', {'id': 'bindbox_image', 'height': this.options.initialHeight,
			'styles':{'text-align':'center'}}).injectInside(mc);
		this.image.onclick = this.overlay.onclick = this.close.bind(this);
		
		this.comment = new Element('div', {'id': 'bindbox_comment', 'styles': {'visibility':'hidden'}}).injectInside(mc);
		
		this.lineDiv = new Element('div', {'id': 'bindbox_line', 'styles': {'visibility':'hidden'}}).injectInside(mc);
		
		this.controlDiv = new Element('div', {'id': 'bindbox_control', 'styles': {'visibility':'hidden'}}).injectInside(mc);
		
		this.prevLink = new Element('div', {'id': 'bindbox_back'}).injectInside(this.controlDiv);
		this.nextLink = new Element('div', {'id': 'bindbox_next'}).injectInside(this.controlDiv);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);
		
		this.number = new Element('div', {'id': 'bindbox_num', 'styles': {'visibility':'hidden'}}).injectInside(this.controlDiv);
		
		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
			overlay: this.overlay.effect('opacity', {duration: 200}).hide(),
			resize: {},
			image: this.image.effect('opacity', {duration: 150, onComplete: nextEffect}),
			close: this.bindbox.effects($extend({duration: this.options.resizeDuration, onComplete: this.closeEnd.bind(this)},
					this.options.resizeTransition ? {transition: this.options.resizeTransition} : {}))
		};
		
		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},
	
	addSet: function(ancs, caps) {
		ancs = $A(ancs);
		caps = $A(caps);
		
		this.groupCount++;
		var groupName = "bindzoom-" + this.groupCount;
		
		$each(ancs, function(el, i) {
			if (el.hasClass("bindzoom")) {
				el.onclick = this.click.pass(el, this);
				el.setAttribute('rel', groupName);
				
				if (!this.anchors) this.anchors = [];
				this.anchors.push(el);
				
				if (!this.captions) this.captions = [];
				this.captions.push(caps[i]);
			}
		}, this);
		
	},
	
	click: function(link){
		var j, imageNum, images = [];
		this.anchors.each(function(el, i){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, this.captions[i], el.rel]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		
		groupName = link.rel;
		
		if (typeof(this.currentGroup) != 'undefined'
			&& this.currentGroup == groupName
			&& typeof(this.activeImage) != 'undefined'
			&& this.activeImage == imageNum) {
			return false;
		}
		
		if (this.currentGroup != groupName) {
			this.images = images;
		}
		
		this.currentGroup = groupName;
		
		if (this.firstClick)
			return this.open(images, imageNum);
		else
			return this.changeImage(imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		
		var imgSrc = this.images[imageNum][0];
		var imgGrp = this.images[imageNum][2];
		var img = null;
		for (var i=0; i<this.anchors.length; i++) {
			var a = this.anchors[i];
			if (a.href == imgSrc && a.rel == imgGrp) {
				var els = a.childNodes;
				for (var j=0; j<els.length; j++) {
					var e = els[j];
					if (e.tagName=='IMG') {
						img = $(e);
						break;
					}
				}
				break;
			}
		}
		
		var dim = img.getCoordinates();
		this.top = dim.top - 34;
		this.left = dim.left - 34;
		
		this.anchorHeight = dim.height + 64;
		this.anchorWidth = dim.width + 64;
		this.anchorTop = dim.top - 34;
		this.anchorLeft = dim.left - 34;
		
		this.bindbox.setStyles({top: this.top, marginLeft:this.left,
			height: this.anchorHeight, width:this.anchorWidth,
			display: ''});
		
		if (this.options.useOverlay) this.fx.overlay.start(0.8);
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open && el.style.visibility != 'hidden') el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;
		
		this.prevLink.style.visibility = this.nextLink.style.visibility = 'hidden';
		if (this.firstClick) {
			this.firstClick = false;
		} else {
			this.fx.image.hide();
		}
		this.image.className = 'lbLoading';
		
		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		
		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.image.className = '';
			
			var preWidth = this.imageWidth || 0;
			var preHeight = this.imageHeight || 0;
			this.imageWidth = this.preload.width;
			this.imageHeight = this.preload.height;
			if (this.imageWidth > document.body.offsetWidth - 20) {
				var rate = (document.body.offsetWidth - 20) / this.imageWidth;
				this.imageWidth = this.imageWidth * rate;
				this.imageHeight = this.imageHeight * rate;
			}
			
log('imageWidth:' + this.imageWidth + ' imageHeight:' + this.imageHeight);
			
			var img = $('imgContents');
			if (img) img.remove();
			img = new Element('img', {
				'id':'imgContents',
				'src':this.images[this.activeImage][0],
				'styles':{
					'width': this.anchorWidth - 64,
					'height': this.anchorHeight - 64,
					'max-width':this.imageWidth, 'max-height':this.imageHeight}}).injectInside(this.image);
			
			this.comment.setHTML(this.images[this.activeImage][1] || '');
			var msg = (!this.options.showCounter || (this.images.length == 1)) ? '' :
				'Image '+(this.activeImage+1)+' of '+this.images.length + '<br />矢印キーで移動。';
			msg += '画像をクリックかEscで終了。';
			this.number.setHTML(msg);
			
			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			
			if (preWidth != this.imageWidth || preHeight != this.imageHeight) {
//			if (preWidth != this.imageWidth) {
				this.image.setStyles({
					'width' : this.anchorWidth - 64,
					'height' : this.anchorHeight - 64,
					'display' : ''
				});
				
				this.controlDiv.style.display = '';
				this.lineDiv.style.display = '';
				
				this.fx.resize = new Fx.Elements([this.bindbox, img, this.image],
					{duration: this.options.resizeDuration, onComplete: this.nextEffect.bind(this)});
				
				this.fx.resize.start({
					'0':{
						'height': this.imageHeight + 68,
						'width': this.imageWidth + 68,
						'marginLeft': (window.getScrollWidth() - (this.imageWidth + 68)) / 2,
						'top': window.getScrollTop() + (window.getHeight() / 15)
					},
					'1':{
						'height': [this.anchorHeight - 64, this.imageHeight],
						'width': [this.anchorWidth - 64, this.imageWidth]
					},
					'2':{
						'height': [this.anchorHeight - 64, this.imageHeight],
						'width': [this.anchorWidth - 64, this.imageWidth]
					}
				});
				
				break;
			}
			
			this.image.setStyles({
				'width' : this.imageWidth,
				'height' : this.imageHeight
			});
			
			img.setStyles({
				'width' : this.imageWidth,
				'height' : this.imageHeight
			});
			
			this.step++;
		case 2:
			if (!this.firstClick) {
				this.fx.image.start(1);
				break;
			}
		case 3:
			this.comment.style.visibility = 'visible';
			this.number.style.visibility = 'visible';
			this.controlDiv.style.visibility = 'visible';
			this.lineDiv.style.visibility = 'visible';
			if (this.activeImage) this.prevLink.style.visibility = '';
			if (this.activeImage != (this.images.length - 1)) this.nextLink.style.visibility = '';
			this.step = 0;
		}
	},
	
	closeEffect: function(){
		this.comment.style.visibility = 'hidden';
		this.number.style.visibility = 'hidden';
		this.lineDiv.style.display = 'none';
		this.controlDiv.style.display = 'none';
		this.image.style.display = 'none';
		this.fx.close.start({height: this.anchorHeight, width: this.anchorWidth,
			marginLeft: this.anchorLeft,
			top: this.anchorTop});
	},
	
	closeEnd: function() {
		this.bindbox.style.display = 'none';
		this.bindbox.setStyles({'width': this.options.initialWidth, 'height': this.options.initialHeight});
	},
	
	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = Class.empty;
			this.preload = null;
		}
		for (var f in this.fx) this.fx[f].stop();
		this.firstClick = true;
		this.imageWidth = 0;
		this.imageHeight = 0;
		this.activeImage = -1;
		this.currentGroup = '';
		if (this.options.useOverlay) {
			this.bindbox.style.display = 'none';
			this.bindbox.setStyles({'width': this.options.initialWidth, 'height': this.options.initialHeight});
			this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
		} else {
			this.setup.bind(this);
			this.setup(false);
			
			this.closeEffect.bind(this);
			this.closeEffect();
		}
		return false;
	}
});


/*
Script: Accordion.js
	Contains <Accordion>

License:
	MIT-style license.
*/

/*
Class: Accordion
	The Accordion class creates a group of elements that are toggled when their handles are clicked. When one elements toggles in, the others toggles back.
	Inherits methods, properties, options and events from <Fx.Elements>.
	
Note:
	The Accordion requires an XHTML doctype.

Arguments:
	togglers - required, a collection of elements, the elements handlers that will be clickable.
	elements - required, a collection of elements the transitions will be applied to.
	options - optional, see options below, and <Fx.Base> options and events.

Options:
	show - integer, the Index of the element to show at start.
	display - integer, the Index of the element to show at start (with a transition). defaults to 0.
	fixedHeight - integer, if you want the elements to have a fixed height. defaults to false.
	fixedWidth - integer, if you want the elements to have a fixed width. defaults to false.
	height - boolean, will add a height transition to the accordion if true. defaults to true.
	opacity - boolean, will add an opacity transition to the accordion if true. defaults to true.
	width - boolean, will add a width transition to the accordion if true. defaults to false, css mastery is required to make this work!
	alwaysHide - boolean, will allow to hide all elements if true, instead of always keeping one element shown. defaults to false.
	
Events:
	onActive - function to execute when an element starts to show
	onBackground - function to execute when an element starts to hide
*/
var Accordion = Fx.Elements.extend({
	is1st: true,
	
	options: {
		onActive: Class.empty,
		onBackground: Class.empty,
		display: 0,
		show: false,
		height: true,
		width: false,
		opacity: true,
		fixedHeight: false,
		fixedWidth: false,
		wait: false,
		alwaysHide: false,
		useMouseOver: false
	},

	initialize: function(){
		var options, togglers, elements, container;
		$each(arguments, function(argument, i){
			switch($type(argument)){
				case 'object': options = argument; break;
				case 'element': container = $(argument); break;
				default:
					var temp = $$(argument);
					if (!togglers) togglers = temp;
					else elements = temp;
			}
		});
		this.togglers = togglers || [];
		this.elements = elements || [];
		this.container = $(container);
		this.setOptions(options);
		this.previous = -1;
		if (this.options.alwaysHide) this.options.wait = true;
		if ($chk(this.options.show)){
			this.options.display = false;
			this.previous = this.options.show;
		}
		if (this.options.start){
			this.options.display = false;
			this.options.show = false;
		}
		this.effects = {};
		if (this.options.opacity) this.effects.opacity = 'fullOpacity';
		if (this.options.width) this.effects.width = this.options.fixedWidth ? 'fullWidth' : 'offsetWidth';
		if (this.options.height) this.effects.height = this.options.fixedHeight ? 'fullHeight' :
			(window.ie) ? 'originalHeight':'scrollHeight';
		for (var i = 0, l = this.togglers.length; i < l; i++) this.addSection(this.togglers[i], this.elements[i]);
		this.elements.each(function(el, i){
			el.originalHeight = el.scrollHeight;
			
			if (window.ie7) {
log('go ie7 hack');
				//setIE7CoreHeight(el, i, 8);
				setIE7CoreHeight(el, i, -1);
log('ie7 hack ok!');
			}
			
			if (this.options.show === i){
				this.fireEvent('onActive', [this.togglers[i], el]);
			} else {
				for (var fx in this.effects) el.setStyle(fx, 0);
			}
		}, this);
		this.parent(this.elements);
		if ($chk(this.options.display)) this.display(this.options.display);
	},

	/*
	Property: addSection
		Dynamically adds a new section into the accordion at the specified position.

	Arguments:
		toggler - (dom element) the element that toggles the accordion section open.
		element - (dom element) the element that stretches open when the toggler is clicked.
		pos - (integer) the index where these objects are to be inserted within the accordion.
	*/

	addSection: function(toggler, element, pos){
		toggler = $(toggler);
		element = $(element);
		var test = this.togglers.contains(toggler);
		var len = this.togglers.length;
		this.togglers.include(toggler);
		this.elements.include(element);
		if (len && (!test || pos)){
			pos = $pick(pos, len - 1);
			toggler.injectBefore(this.togglers[pos]);
			element.injectAfter(toggler);
		} else if (this.container && !test){
			toggler.inject(this.container);
			element.inject(this.container);
		}
		var idx = this.togglers.indexOf(toggler);
		if (this.options.useMouseOver) {
			toggler.addEvent('mouseover', this.display.bind(this, idx));
		} else {
			toggler.addEvent('mousedown', this.display.bind(this, idx));
		}
		if (this.options.height) element.setStyles({'padding-top': 0, 'border-top': 'none', 'padding-bottom': 0, 'border-bottom': 'none'});
		if (this.options.width) element.setStyles({'padding-left': 0, 'border-left': 'none', 'padding-right': 0, 'border-right': 'none'});
		element.fullOpacity = 1;
		if (this.options.fixedWidth) element.fullWidth = this.options.fixedWidth;
		if (this.options.fixedHeight) element.fullHeight = this.options.fixedHeight;
		element.setStyle('overflow', 'hidden');
		if (!test){
			for (var fx in this.effects) element.setStyle(fx, 0);
		}
		return this;
	},

	/*
	Property: display
		Shows a specific section and hides all others. Useful when triggering an accordion from outside.

	Arguments:
		index - integer, the index of the item to show, or the actual element to show.
	*/

	display: function(index){
log('try display:' + index);
		index = ($type(index) == 'element') ? this.elements.indexOf(index) : index;
		if ((this.timer && this.options.wait) || (index === this.previous && !this.options.alwaysHide)) return this;
		this.previous = index;
		var obj = {};
log('elements');
		this.elements.each(function(el, i){
			obj[i] = {};
			var hide = (i != index) || (this.options.alwaysHide && (el.offsetHeight > 0));
			this.fireEvent(hide ? 'onBackground' : 'onActive', [this.togglers[i], el]);
log('loop start');
			for (var fx in this.effects) {
				if (this.is1st && i == 0) {
					if (fx == 'opacity') {
						el.setOpacity(100);
						continue;
					} else if (fx == 'height') {
						el.setStyle('height', (window.ie) ? el.originalHeight:el.getStyle('scrollHeight'));
						continue;
					}
				}
				obj[i][fx] = hide ? 0 : el[this.effects[fx]];
			}
		}, this);
		
		this.is1st = false;
		
log('effect start');
		
		return this.start(obj);
	},
	
	showThisHideOpen: function(index){return this.display(index);}

});

Fx.Accordion = Accordion;


/*
Class: ToggleAccordion
*/
var ToggleAccordion = Fx.Base.extend({
	is1st: true,
	
	options: {
		onActive: Class.empty,
		onBackground: Class.empty,
		useMouseOver: false,
		open: false
	},

	initialize: function(toggler, element, pos, options){
		this.toggler = $(toggler);
		this.element = $(element);
		this.setOptions(options);
		this.previous = -1;
		
		this.hide = true;
		this.locked = false;
		
		var e = this.setUp(this.toggler, this.element, pos);
		this.fx = this.element.effects({
			duration: 700,
			transition:Fx.Transitions.Expo.easeOut,
			onComplete:this.effectEnd.bind(this)
		});
		
		if (options.open) {
			this.hide = false;
		}
		
		this.display();
	},

	setUp: function(toggler, element, pos){
		if (this.options.useMouseOver) {
			toggler.addEvent('mouseover', this.display.bind(this));
		} else {
			toggler.addEvent('mousedown', this.display.bind(this));
		}
		element.setStyle('overflow', 'hidden');
		
		var dim = element.getCoordinates();
		this.element.originalHeight = dim.height;
		//this.element.originalHeight = element.scrollHeight;
		
		if (window.ie7) {
			//setIE7CoreHeight(element, pos, 3);
			setIE7CoreHeight(element, pos, -1);
		}
		
		return this;
	},
	
	display: function(){
		if (this.options.useMouseOver && this.locked) return;
		
		this.fx.stop();
		
		this.fireEvent(this.hide ? 'onBackground' : 'onActive', [this.toggler, this.element]);
		
		if (this.options.useMouseOver) this.locked = true;
		if (this.is1st) {
			if (this.hide) {
				this.element.setOpacity(0);
				this.element.setStyle('height', 0);
			} else {
				this.element.setOpacity(100);
				if (window.ie) {
					this.element.setStyle('height', this.element.originalHeight);
				} else {
					this.element.setStyle('height', this.element.scrollHeight);
				}
			}
			this.locked = false;
			
		} else {
			if (window.ie) {
				if (this.hide)
					this.fx.start({'height': [this.element.originalHeight, 0], 'opacity': [1, 0]});
				else
					this.fx.start({'height': [0, this.element.originalHeight], 'opacity': [0, 1]});
			} else {
				if (this.hide)
					this.fx.start({'height': [this.element.scrollHeight, 0], 'opacity': [1, 0]});
				else
					this.fx.start({'height': [0, this.element.scrollHeight], 'opacity': [0, 1]});
			}
		}
		this.hide = !this.hide;
		
		if (this.is1st) this.is1st = false;
	},
	
	effectEnd: function(){
		if (this.options.useMouseOver) {
			this.locked = false;
		}
	}
});

/*
Class:BindTab
*/
var BindTab = Fx.Elements.extend({
	is1st: true,
	
	options: {
		onActive: Class.empty,
		onBackground: Class.empty,
		display: 0,
		show: false,
		height: true,
		opacity: true,
		fixedHeight: false,
		fixedWidth: false,
		wait: true,
		alwaysHide: false,
		useMouseOver: false,
		blockOption: ''
	},
	
	initialize: function(){
		var options, togglers, elements, container;
		$each(arguments, function(argument, i){
			switch($type(argument)){
				case 'object': options = argument; break;
				case 'element': container = $(argument); break;
				default:
					var temp = $$(argument);
					if (!togglers) togglers = temp;
					else elements = temp;
			}
		});
		this.togglers = togglers || [];
		this.elements = elements || [];
		this.container = $(container);
		this.setOptions(options);
		this.previous = -1;
		if (this.options.alwaysHide) this.options.wait = true;
		if ($chk(this.options.show)){
			this.options.display = false;
			this.previous = this.options.show;
		}
		if (this.options.start){
			this.options.display = false;
			this.options.show = false;
		}
		this.effects = {};
		if (this.options.opacity) this.effects.opacity = 'fullOpacity';
		if (this.options.height) this.effects.height = this.options.fixedHeight ? 'fullHeight' :
			(window.ie) ? 'originalHeight':'scrollHeight';
		for (var i = 0, l = this.togglers.length; i < l; i++) this.addSection(this.togglers[i], this.elements[i]);
		this.maxHeight = 0;
		this.elements.each(function(el, i){
			el.originalHeight = el.scrollHeight;
			if (this.options.show === i){
				this.fireEvent('onActive', [this.togglers[i], el]);
			} else {
				if (el.scrollHeight > this.maxHeight) this.maxHeight = el.scrollHeight;
				for (var fx in this.effects) el.setStyle(fx, 0);
			}
			
			if (window.ie7) {
				setIE7CoreHeight(el, i, -1);
			}
		}, this);
		this.parent(this.elements);
		this.display(0);
	},
	
	addSection: function(toggler, element, pos){
		toggler = $(toggler);
		element = $(element);
		var test = this.togglers.contains(toggler);
		var len = this.togglers.length;
		this.togglers.include(toggler);
		this.elements.include(element);
		var idx = this.togglers.indexOf(toggler);
		if (this.options.useMouseOver) {
			toggler.addEvent('mouseover', this.display.bind(this, idx));
		} else {
			toggler.addEvent('mousedown', this.display.bind(this, idx));
		}
		if (this.options.height) element.setStyles({'padding-top': 0, 'padding-bottom': 0});
		element.fullOpacity = 1;
		if (this.options.fixedWidth) element.fullWidth = this.options.fixedWidth;
		if (this.options.fixedHeight) element.fullHeight = this.options.fixedHeight;
		element.setStyle('overflow', 'hidden');
		if (!test){
			for (var fx in this.effects) element.setStyle(fx, 0);
		}
		return this;
	},
	
	display: function(index){
		index = ($type(index) == 'element') ? this.elements.indexOf(index) : index;
		if ((this.timer && this.options.wait) || (index === this.previous && !this.options.alwaysHide)) return this;
		this.previous = index;
		var obj = {};
		this.elements.each(function(el, i){
			obj[i] = {};
			var hide = (i != index) || (this.options.alwaysHide && (el.offsetHeight > 0));
			this.fireEvent(hide ? 'onBackground' : 'onActive', [this.togglers[i], el]);
			
			if (!this.is1st) {
				el.setStyle('height', 0);
				el.setOpacity(0);
			}
			
			if (hide) {
				el.originalBorder = el.getStyle('border');
				el.setStyle('border', 'none');
			} else {
				if (el.originalBorder) {
					el.setStyle('border', el.originalBorder);
				}
			}
			
			if (!hide) {
				for (var fx in this.effects) {
					if (this.is1st && i==0) {
						if (fx == 'opacity') {
							el.setOpacity(100);
							continue;
						} else if (fx == 'height') {
							el.setStyle('height', (window.ie) ? this.maxHeight: el.getStyle('scrollHeight'));
							continue;
						}
					}
					
					if (window.ie && fx == 'height')
						obj[i][fx] = this.maxHeight;
					else
						obj[i][fx] = el[this.effects[fx]];
				}
			}
			
		}, this);
		
		this.is1st = false;
		
		return this.start(obj);
	},
	
	showThisHideOpen: function(index){return this.display(index);}
	
});


function processAccordion(b) {
	var opt = getBlockOption(b);
	var cmcs = getCmcs(b);
	if (opt=="opt-1" || opt=="opt-2") {
		for (var i=0; i<cmcs.length; i++) {
			var cmc = cmcs[i];
			var togglers = [];
			var elements = [];
			
			var prevToggler = null;
			var cls = cmc.childNodes;
			for (var j=0; j<cls.length; j++) {
				c = cls[j];
				if (c.tagName=='DIV') {
					if (c.className.indexOf("h2") > -1) {
						prevToggler = c;
						if (opt=="opt-2")
							c.style.cursor = 'default';
						else
							c.style.cursor = 'pointer';
					} else if (c.className.indexOf("box") > -1) {
						// toggle, element pair only.
						if (prevToggler!=null) {
							togglers.push(prevToggler);
							elements.push(c);
							prevToggler = null;
						}
					}
				}
			}
			
			var accordion = new Accordion(togglers, elements, {
				duration: 700,
				transition: Fx.Transitions.Expo.easeOut,
				opacity: true,
				useMouseOver:(opt=="opt-2"),
				onActive: function(t, e){
					t.addClass('cr');
					stopMovies(e, false);
				},
				
				onBackground: function(t, e){
					t.removeClass('cr');
					stopMovies(e, true);
				}
			});
			
		}
		
	} else if (opt=="opt-3" || opt=="opt-4" || opt=="opt-5" || opt=="opt-6") {
		for (var i=0; i<cmcs.length; i++) {
			var cmc = cmcs[i];
			var prevToggler = {};
			var pos = 0;
			
			var cls = cmc.childNodes;
			for (var j=0; j<cls.length; j++) {
				var c = cls[j];
				if (c.tagName=='DIV') {
					if (c.className.indexOf("h2") > -1) {
						prevToggler = c;
						
						if (opt=="opt-4" || opt=="opt-6")
							c.style.cursor = 'default';
						else
							c.style.cursor = 'pointer';
						
					} else if (c.className.indexOf("box") > -1) {
						if (prevToggler) {
							var tglAccordion = new ToggleAccordion(prevToggler, c, pos, {
								useMouseOver:(opt=="opt-4" || opt=="opt-6"),
								onActive: function(t, e){
									t.addClass('cr');
									stopMovies(e, false);
								},
								onBackground: function(t, e){
									t.removeClass('cr');
									stopMovies(e, true);
								},
								open:(pos == 0 && (opt=="opt-5" || opt=="opt-6"))
							});
							prevToggler = null;
							pos++;
						}
					}
				}
			}
		}
	}
	
}

function processTab(b) {
	var opt = getBlockOption(b);
	var cmcs = getCmcs(b);
	for (var i=0; i<cmcs.length; i++) {
		var cmc = cmcs[i];
		var tabs = [];
		var boxes = [];
		
		var twrap = new Element('div', {
			'class':'twrap'
		});
		twrap.injectTop(cmc);
		
		var prevTab = null;
		cmc.getChildren().each(function(e){
			if (e.hasClass("h2")) {
				e.injectInside(twrap);
				prevTab = e;
			}
			
			if (e.hasClass("box")) {
				if (prevTab!=null) {
					tabs.push(prevTab);
					boxes.push(e);
					prevTab = null;
				}
			}
		});
		
		var tab = new BindTab(tabs, boxes, {
//			duration: 700,
//			transition: Fx.Transitions.Bounce.easeOut,
			duration: 500,
			transition: Fx.Transitions.Expo.easeOut,
			opacity: true,
			onActive: function(t, e){
				t.addClass('cr');
				stopMovies(e, false);
			},
			
			onBackground: function(t, e){
				t.removeClass('cr');
				stopMovies(e, true);
			},
			
			useMouseOver: (opt=='opt-2' || opt=='opt-4' || opt=='opt-6' || opt=='opt-8'),
			
			blockOption: opt
		});
		
	}
}

function processImageAndMovie(b) {
	var ancs = [];
	var caps = [];
	var cls = getClassedTags(b, ['SPAN', 'A'],
		['img', 'movieButton', 'bindtexts', 'bindtextm', 'bindtextl'], true);
	for (var i=0; i<cls.length; i++) {
		var cl = cls[i];
		var tagName = cl.tagName;
		var className = cl.className;
//log('cl:'+tagName+'.'+className);
		if (tagName=='SPAN' && className.indexOf('img') > -1) {
			var hasComment = false;
			var imgs = cl.childNodes;
			for (var j=0; j<imgs.length; j++) {
				var e = $(imgs[j]);
				if (e.tagName=='A') {
					ancs.push(e);
//log('href=' + e.href);
				} else if (e.tagName=='SPAN') {
					caps.push(e.getText());
					hasComment = true;
				}
			}
			if (!hasComment) caps.push('');
			
		} else if (tagName=='A' && className.indexOf('movieButton') > -1) {
			processMovieButton(cl);
			
		} else if (tagName=='A') {
			if (className=='bindtexts') cl.onclick = function() {Textsize.resize(10); return false;};
			if (className=='bindtextm') cl.onclick = function() {Textsize.resize(12); return false;};
			if (className=='bindtextl') cl.onclick = function() {Textsize.resize(14); return false;};
		}
		
	}
	
	if (ancs.length > 0) {
		if (myBindZoom==null) {
			myBindZoom = new BiNDZoom(ancs, caps, {});
		} else {
			myBindZoom.addSet(ancs, caps);
		}
	}
}

function processMovieButton(e) {
	if (myBindMovie==null) {
		myBindMovie = new BiNDMovie(e, {});
	} else {
		myBindMovie.addAnchor(e);
	}
}

function getBlockOption(b) {
	var o = b.firstChild;
	if (o) {
		return o.className;
	}
	return "";
}

function getClassedTags(b,names,clazz,deep) {
	var cl = b.childNodes;
	var rtn = [];
	for (var i=0; i<cl.length; i++) {
		var c = cl[i];
		var nmfind = false;
		var nm = c.nodeName;
		var cls = c.className;
		
		if (nm=='#text') continue;
		
		for (var j=0; j<names.length; j++) {
			if (nm == names[j]) {
				nmfind = true;
				break;
			}
		}
		
		var find = false;
		if (nmfind) {
			var clsfind = false;
			
			if (clazz==null) {
				clsfind = true;
			} else {
				for (var j=0; j<clazz.length; j++) {
					if (cls.indexOf(clazz[j]) > -1) {
//log("find! " + nm + "." + clazz[j]);
						clsfind = true;
						break;
					}
				}
			}
			
			if (clsfind) {
				rtn.push(c);
				find = !deep;
			}
		}
		
		if (find == false && c.hasChildNodes) {
			var wkary = getClassedTags(c, names, clazz, deep);
			for (var j=0; j<wkary.length; j++) {
				rtn.push(wkary[j]);
			}
		}
	}
	return rtn;
}

function getCmcs(b) {
	return getClassedTags(b, ['DIV'], ['cmc'], false);
}

function stopMovies(e, sw) {
	var elements = getClassedTags(e, ['object', 'embed'], null, true);
	elements.each(function(el){
		if (window.webkit) {
			el.style.visibility = (sw) ? 'hidden':'';
		} else {
			el.style.display = (sw) ? 'none':'';
		}
		
		if (el.disabled) el.disabled = sw;
		if (window.ie && sw) {
			var mv = document.all(el.id);
			if (mv) {
				if (typeof(mv.stop)=='function') mv.stop();
				if (typeof(mv.Stop)=='function') mv.Stop();
			}
		}
	});
}

function setIE7CoreHeight(el, i, amnt) {
	var xmc = $(getClassedTags(el, ['DIV'], ['xmc'], false)[0]);
	if (amnt == -1) {
		xmc.setStyle('max-height', xmc.scrollHeight - 12);
	} else {
		var perc = Math.round(xmc.scrollHeight / el.originalHeight * 100) - (amnt + i);
		xmc.setStyle('max-height', perc + '%');
	}
}

function dig(p) {
	var cl = p.childNodes;
	for (var i=0; i<cl.length; i++) {
		var c = cl[i];
		
		var nm = c.nodeName;
		var cls = c.className;
		
		switch (nm)
		{
		case '#text': continue;
		case 'DIV':
			if (cls.indexOf("block") > -1) {
//log(">>block:" + c.id);
				if (typeof(Value)=="undefined" || Value.preview) {
					if (cls.indexOf('accordion') > -1) {
						processAccordion(c);
						
					} else if (cls.indexOf('tab') > -1) {
						processTab(c);
					}
					
				}
				
				processImageAndMovie(c);
				
				if (!window.ie6) continue;
			}
			break;
			
		default:
			break;
			
		}
		
		if (window.ie6) {
			clearpng.fixone(c);
		}
		
		if (c.hasChildNodes()) {
			dig(c);
		}
	}
}

function log(msg) {
	if (BiNDFx.debug) {
		var n = document.getElementById("log");
		if (n) {
			var buf = n.innerHTML;
			n.innerHTML = buf + msg + "<br />";
		}
	}
}

function setupLog() {
	if (BiNDFx.debug) {
		var logDiv = document.createElement("div");
		logDiv.setAttribute("id", "log");
		
		var css = "";
		if (window.ie6) {
			css = "position:absolute; height:200px; width:400px; left:0px; top:0px; " +
				"background-color:#ffffff; filter: alpha(opacity=60);" +
				"overflow-y:scroll;";
		} else {
			css = "position:absolute; height:200px; width:400px; left:0px; top:0px; " +
				"background-image:url(sunshine/company/images/acc_box_bg.png);" +
				"overflow:scroll;";
		}
		logDiv.style.cssText = css;
		document.body.appendChild(logDiv);
	}
}

var myBindZoom = null;
var myBindMovie = null;
function initFx() {
	setupLog();
	
	dig(document.body);
	
}

