// Copyright (c) 2006 Robert Madaj
//
// See http://spravodaj.madaj.net/ for more info
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


var cd = {
	codes : Array,
	init : function() {
		cd.codes = document.getElementsByClassName('code','contentBody');
		cd.attach();
	},
	attach : function() {
		var i;
		for ( i=0;i<cd.codes.length;i++ ) {
			Event.observe(cd.codes[i],'click',cd.collapse,false);
			Element.cleanWhitespace(cd.codes[i].parentNode);
		}
	},
	getEventSrc : function (e) {
		if (!e) e = window.event;
		if (e.originalTarget)
			return e.originalTarget;
		else if (e.srcElement)
		return e.srcElement;
	},
	collapse : function(e) {
		var el = cd.getEventSrc(e).nextSibling;
		if ( Element.hasClassName(el,'closed') ) {
			new Effect.Parallel(
				[
					new Effect.DropOut(el,{sync:true}),
					new Effect.Fade(el,{sync:true})

				],
				{
					duration:0.5,
					fps:20
				}
			);
			Element.removeClassName(el,'closed');
			new Effect.Move('star',{ x: 0, y: -10 });

		} else {
			new Effect.Parallel(
				[
					new Effect.Appear(el,{sync:true}),
					new Effect.BlindDown(el,{sync:true})

				],
				{
					duration:0.5,
					fps:20
				}
			);
			Element.addClassName(el,'closed')
			new Effect.Move('star',{ x: 0, y: 10 });

		}
	}
};
Event.observe(window,'load',cd.init,false);




