YUI().use('anim','node','ticker','textShadow','slideshow', function (Y) {
                 
        Y.TextShadow("#titleMain","#boxTitle",0);
        Y.TextShadow("#titleSub","#boxTitle",Y.UA.ie?40:0);
        
        // ticker
        var ticker = new Y.Ticker({
                rotateDelay:1500,
                text: [ "Mapping intelligence",
                        "Explore your data through maps and images",
                        "Open data sets ready to map",
                        "Upload 100,000s of addresses",
                        "Visualise and locate your customers",
                        "Define and map franchise territories",
                        "Publish your data online",
                        "Analyse ABS Census data",
                        "Explore market segments and trends",
                        "Discover patterns and trends"]
        });
        
        // slideshow        
        var slideshow = new Y.Slideshow({
                rotateDelay:1500,
                fromId: "#headerImgFrom",
                toId: "#headerImgTo",
                images: [
               			 "./dmap/support/img/aboutDMap/i2a.jpg",
                		 //"./dmap/support/img/aboutDMap/i2.jpg",
                         "./dmap/support/img/aboutDMap/i3.jpg",
                         "./dmap/support/img/aboutDMap/i3a.jpg",
                         "./dmap/support/img/aboutDMap/i6.jpg",
                         "./dmap/support/img/aboutDMap/i7.jpg",
                         "./dmap/support/img/aboutDMap/i4.jpg",
                         "./dmap/support/img/aboutDMap/i5.jpg",
                         
                         "./dmap/support/img/aboutDMap/i8.jpg",
                         "./dmap/support/img/aboutDMap/i9.jpg",
                         //"./dmap/support/img/aboutDMap/i10.jpg",
                         //"./dmap/support/img/aboutDMap/i11.jpg",
                         "./dmap/support/img/aboutDMap/i12.jpg",
                         "./dmap/support/img/aboutDMap/i13.jpg",
                         "./dmap/support/img/aboutDMap/i14.jpg",
                         "./dmap/support/img/aboutDMap/i1.jpg"
                         
                    ]
        });
        
        Y.later(1500, ticker, ticker.fade);
        Y.later(1500, slideshow, slideshow.fade);
});
                
/*
** YUI Text Shadow
** reproduces text-shadow css for IE and Firefox 3.0 and under 
*/

YUI.add('textShadow', function(Y) {
        Y.TextShadow = function(nodeId,containerId,yCorrection) {
                return;
                if (!(Y.UA.ie || Y.UA.gecko <= 1.9))
                        return;
                
                var node = Y.one(nodeId);
                var container = Y.one(containerId);
                var x = node.getX()-container.getX(), y=node.getY()-container.getY()-yCorrection;  //wtf ie?
                var shadow = Y.Node.create("<div class='shadow'>" + node.get("innerHTML") + "</div>");
                shadow.setX(x+1).setY(y+1);
                shadow.setStyle("fontSize",node.getStyle("fontSize"));
                shadow.setStyle("lineHeight",node.getStyle("lineHeight"));
                container.append(shadow);
                node.shadow = shadow;
        }
},{requires:['node']});           

/* 
** YUI Ticker
*/

YUI.add('ticker', function(Y) {
        Y.Ticker = function(pConfig) {
                var rotateDelay = pConfig.rotateDelay;
                var tickerText = pConfig.text;
                var idx = 0;
                var self = this;
                
                this.fade = function() {
                        var fadeOut = new Y.Anim({node: '#titleSub',   to: {opacity:0},  duration: 1,  easing: Y.Easing.easeIn});
                        var fadeIn  = new Y.Anim({node: '#titleSub', from: {opacity:0}, to: {opacity:100}, duration: 2, easing: Y.Easing.easeIn}); 
                        var rotateText = function() {
                                if (idx == tickerText.length) idx=0;
                                Y.one("#titleSub").set("innerHTML",tickerText[idx++]);
                        };
                        
                        fadeOut.on("start",function() {
                                try{Y.one("#titleSub").shadow.remove()}catch(e){}         // fix this shadow stuff
                        });   
                        
                        fadeOut.on("end", function() {
                                rotateText();
                                Y.later(50, fadeIn, fadeIn.run)
                        });
                        
                        fadeIn.on("end",  function() {Y.later(rotateDelay, self, self.fade), true});
                        fadeOut.run();
                }
                
                this.slide = function() {
                }
                
        }
},{requires:['node','anim']});


/*
** YUI Slideshow
*/

YUI.add('slideshow', function(Y) {
        Y.Slideshow = function(pConfig) {
                var rotateDelay = pConfig.rotateDelay;
                var images = pConfig.images;
                var idx = 0;
                var self = this;
                var from = Y.one(pConfig.fromId);
                var to = Y.one(pConfig.toId)
                
                this.setupCache = function() {
                        var imgs="";
                        for (var i=0;i<images.length;i++) {
                                imgs += "<img src='"+images[i]+"' />";
                        }

                        // attach it to the body of the document
                        Y.one(document.body).append(Y.Node.create("<div style='position:absolute;top:0px;left:0px;height:1px;width:1px;overflow:hidden;'>" + 
                                imgs + "</div>"));
                }
                
                this.fade = function() {
                        var fadeOut = new Y.Anim({node: pConfig.fromId, from: {opacity:100}, to: {opacity:0},  duration: 3,  easing: Y.Easing.easeIn});
                        var fadeIn  = new Y.Anim({node: pConfig.toId,   from: {opacity:0},   to: {opacity:100}, duration: 4, easing: Y.Easing.easeIn}); 
                        var rotate = function() {
                                if (idx == images.length) idx=0;
                                from.set("src",to.get("src"));
                                to.setStyle("opacity",0);
                                to.set("src",images[idx++]);
                        };
                        
                        fadeIn.on("end",  function() {
                                from.setStyle("opacity",50);        
                                Y.later(rotateDelay, self, self.fade);
                        }, true);
                        
                        rotate();
                        fadeOut.run();
                        fadeIn.run();
                        
                }
                
                this.slide = function() {
                }


                // add the cache in once the page has settled down a bit                
                Y.later(1000,self, self.setupCache);
        }                
},{requires:['node','anim']});


