1/*
2Presentacular. v 0.1
3http://labs.cavorite.com/presentacular/
4(c) 2005, Juan Manuel Caicedo
5
6This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
7
8See http://www.gnu.org/copyleft/gpl.html for more information
9
10*/
11
12/*
13Creates a chain function.
14
15Todo:
16	Handle return values
17	Add a chained property with a reference to the original function
18
19Static method
20*/
21Function.chain = function(from,ext){
22	return function() {
23		from.apply(this,arguments)
24		ext.apply(this,arguments)
25	}
26}
27
28/*
29Creates a chained function
30Instance method
31*/
32Function.prototype.chain = function(){
33	var __source = this
34	var exts = arguments
35	return function(){
36		__source.apply(this,arguments)
37		for (e = 0; e < exts.length; e++){
38			exts[e].apply(this,arguments)
39		}
40	}
41}
42
43/*
44Applies function f to each element of the list
45*/
46function Map(list,f){
47	var r = []
48	for (var i=0; i < list.length; i++){
49		r.push(f.call(this,list[i]))
50	}
51	return r
52}
53
54
55
56var Presentacular = {}
57
58/*
59Available effects
60TODO: Provide a function to add effects
61*/
62Presentacular.effects = {
63	blinddown: Effect.BlindDown,
64	blindup: Effect.BlindUp,
65	appear: Effect.Appear,
66	puff: Effect.Puff,
67	shake: Effect.Shake,
68	pulsate: Effect.Pulsate,
69	slidedown: Effect.SlideDown,
70	slideup: Effect.SlideUp,
71	highlight: Effect.Highlight,
72	grow: Effect.Grow,
73	fade: Effect.Fade,
74	fold: Effect.Fold,
75	shrink: Effect.Shrink,
76        dropout: Effect.DropOut,
77        switchoff: Effect.SwitchOff,
78        squish: Effect.Squish
79}
80
81/*
82Apply effects to element elm.
83
84parentClasses: If true, include effects defined in the parent element. Used for lists (ul, ol)
85
86*/
87Presentacular.applyEffects = function(elm,parentClasses){
88
89	if (!elm.className) return
90	var c = []
91	if (parentClasses)
92		c = c.concat(elm.parentNode.className.split(' '))
93	c = c.concat(elm.className.split(' '))
94	Map(c, function(cl){
95		if (!cl) return
96
97
98		//Proof of concept. this code could (and should) be more elegant
99		cl = cl.toLowerCase().split('_')
100
101		var opts = {duration: 1}
102		if (cl.length > 1){
103			opts.duration = cl[1]
104		}
105
106		if (Presentacular.effects[cl[0]]){
107			Presentacular.effects[cl[0]].call(this,elm,opts)
108		}
109		return
110	})
111}
112
113
114/*
115Chained function
116*/
117function ChangeSlide(step){
118
119	var ce = $('slide' + snum)
120
121	//Apply slide effects
122	Presentacular.applyEffects(ce)
123
124	//Apply effects to all elements but the incrementals
125	try {
126		Map(ce.getElementsByTagName('*'), function(elm){
127			if (!hasClass(elm,"incremental")){
128				Presentacular.applyEffects(elm)
129			}
130		})
131	} catch (err) {}
132}
133
134
135/*
136Chained function
137*/
138function ApplyCurrentElement(elm,className){
139	if (className == "current"){
140		Presentacular.applyEffects(elm,true)
141	}
142}
143
144/*
145Function chaining: execute the second function after the first one has finished
146
147This was necesary in order to keep the same function names and because I want
148to *extend* S5 instead of *edit* it.
149
150*/
151window.addClass = addClass.chain(ApplyCurrentElement)
152window.go = go.chain(ChangeSlide)
153