﻿/******************************************************************************
    * method: slideShow
    * notes:  opens a new window.  the method detects if the window was opened
    *         or blocked by popup blockers.
    * 
    ***/
    
    function slideShowClass(){
    
    this.data;
    this.slides;
    this.currentSlideIndex = 0;
    this.timer = null;
    this.inTransition = false;
    this.featureImg;
    this.storyFlag;
    this.videoLink;
    this.slideTitle;
    this.slideSubTitle;
    this.storyNav;
    this.btnPrev;
    this.btnNext;
    this.navItems;
    this.doStart = false;
    
    this.shows = new Array();
    
    this.imgLoader;
    this.currentLoadIndex;
    
    try{
        this.currentPlaceholder = document.getElementById("loader"); 
    }catch(e){
        //console.log(e.message);
    }
    
    this.add = function(objSettings) {
            //this.shows[this.shows.length] = objSettings;
            this.shows.push(objSettings);
            this.data = objSettings;
            this.data.slides.shift();
            this.slides = this.data.slides;
            
            //this.buildButtons();
            //this.showCurrentSlide();
     
            //if(this.data.auto){ this.start(); }
            //alert("ADD COMPLETE");
        };
        this.addFeature = function(objSettings) {
            objSettings.shift();
            linkNav = new LinkNav(objSettings,false);
        };
    this.init = function(){
        var thisObj = this;
        
        this.featureImg = document.getElementById("featureImg");
        this.storyFlag = document.getElementById("storyFlag");
        this.videoLink = document.getElementById("videoLink");
        this.slideTitle = document.getElementById("slideTitle");
        this.slideSubTitle = document.getElementById("slideSubTitle");
        this.storyNav = document.getElementById("storyNav");
        this.initBackgroundHolder(this.storyFlag, this.data.backgroundUrl, 0);
        this.initBackgroundHolder(this.videoLink, this.data.videoIconUrl, 0);
    
        this.videoLink.onclick = function(){ thisObj.stopShow(); }
        this.videoLink.style.visibility = "hidden";        

        this.buildNav();
        
        if(!isIE){ 
            this.featureImg.style.opacity = 0; 
        }else{
            //this.slideTitle.style.filter = "alpha(opacity=100)";
            //this.slideSubTitle.style.filter = "alpha(opacity=100)";
            this.featureImg.style.filter = "alpha(opacity = 0)";
        }
        this.doStart = this.data.auto;
        //this.setCurrentSlide();
        //this.start();
        
        //if(this.btnPrev != null){ document.getElementById("btnPrev").onnousedown = function(){ thisObj.prevNext("prev"); } }
        //if(this.btnNext != null){ document.getElementById("btnNext").onmousedown = function(){ thisObj.prevNext("next"); } }
        
       // alert(this.btnPrev.onclick+" :::: "+this.btnNext.onclick);
        this.activateNavItems();
        this.currentLoadIndex = this.currentSlideIndex;
        
        this.imgLoader = new ImageLoader();
        this.imgLoader.setImage(this.data.slides[this.currentLoadIndex].image, {scope:this, func:"onImgLoadComplete"});    
        
    }
    
    this.onImgLoadComplete = function(imgObj){
        this.data.slides[this.currentLoadIndex].imgRef = imgObj;
        
        //    
        if(this.currentSlideIndex == this.currentLoadIndex){
            //alert("IMAGE IS LOADED ::: "+this.currentLoadIndex+" ::: "+this.currentSlideIndex);
            //this.featureImg.style.opacity = 0; 
            this.setCurrentSlide();
        }
        this.currentLoadIndex++;
        if(this.currentLoadIndex < this.data.slides.length){
            this.imgLoader.setImage(this.data.slides[this.currentLoadIndex].image, {scope:this, func:"onImgLoadComplete"});    
        }        
        //continue loading!
    }
    
    this.initBackgroundHolder = function(p_element, p_imgurl, p_opacity){
        p_element.style.display = "block";
        if(!isIE){ 
            p_element.style.opacity = p_opacity;
            p_element.style.backgroundImage = 'url('+p_imgurl+') top left non-repeat';
        }else{
            //p_element.style.filter = "alpha(opacity = "+p_opacity+")";
            p_element.style.backgroundImage = "url("+p_imgurl+")";
            p_element.style.backgroundPosition = 'top left';
        }
    }
    
    this.start = function(){
        if(this.slides.length > 1){
            var thisObj = this;
            this.timer = setInterval(function() { thisObj.slideAction(); }, this.data.duration * 1000);
        }
    }
    
    this.stopShow = function(){
        if(this.timer != null){
            clearInterval(this.timer);
            this.timer = null;
        }
    }
    
    this.slideAction = function(){
        //alert("SLIDE ACTION");
        if(!this.doStart){
            this.hideCurrentSlide();
        }else{
           this.doStart = false;     
        }
        this.updateSlideIndex(1);
    }
    
    this.updateSlideIndex = function(p_dir){
        //alert("UPDATE SLIDE INDEX");
        if(p_dir > 0){
            this.currentSlideIndex++;
            if(this.currentSlideIndex >= this.slides.length){ this.currentSlideIndex = 0; }
        }else{
            this.currentSlideIndex--;
            if(this.currentSlideIndex < 0){ this.currentSlideIndex = this.slides.length - 1; }
        }
    }
    
    this.hideCurrentSlide = function(){
        //alert("HIDE CURRENT SLIDE");
        //var thisObj = this;
        
        if(!isIE){ 
            new Tween(this.videoLink, 400, {opacity:0}, {});
        }   
            new Tween(this.slideTitle, 400, {opacity:0}, {});
            new Tween(this.slideSubTitle, 400, {opacity:0}, {});
            new Tween(this.featureImg, 500, {opacity:0}, {delay:400, scope:this, completeListener:"setCurrentSlide"});
         
        //}else{
        //    this.slideTitle.style.filter = "alpha(opacity=0)";   
        //    this.slideSubTitle.style.filter = "alpha(opacity=0)";  
        //    this.featureImg.style.filter = "alpha(opacity=0)";         
        //} 
        
    }
    
    this.hideSlide = function(){
       // var thisObj = this;
       // jQuery("#featureImg").fadeOut('slow', function(){
       //     thisObj.showCurrentSlide();
       // });
    }
    
    this.setCurrentSlide = function(){
       // alert("SET CURRENT SLIDE ::: "+this.slideTitle.style.filter+" ::: "+this.slideSubTitle.style.filter+" :::: "+this.featureImg.style.filter);           
        
        this.setNavState();
        
        //alert("SLIDE INDEX :: "+this.currentSlideIndex);
        var current = this.data.slides[this.currentSlideIndex];
        var thisObj = this;
        
        //if(!isIE){ this.featureImg.style.opacity = 0; }
        
        //this.featureImg.src = current.image;
        document.getElementById("featureImg").src = current.image; 
        new Tween(this.featureImg, 500, {opacity:1}, {delay: 100, scope:this, completeListener:"onFeatureImgFadeInComplete"});
        this.displayCurrentSlide();
    }
    
    this.onFeatureImgFadeInComplete = function(p_obj){
        //alert("ON FEEATURE IMG FADE IN COMPLETE ::: "+this.doStart);
        if(this.doStart){
        //if(this.data.auto){
            this.doStart = false; 
            this.start();
        }
    }
    
    this.displayCurrentSlide = function(){
        var thisObj = this;
        var current = this.data.slides[this.currentSlideIndex];
        
        //if(!isIE && this.storyFlag.style.opacity == 0){ this.storyFlag, 250, {opacity:1}, {delay:500}); }
        if(!isIE){ 
            if(document.getElementById("storyFlag").style.opacity < 1){
                new Tween(document.getElementById("storyFlag"), 250, {opacity:1}, {delay:500});     
            }
        }
        if(current.video != null && current.video != ""){
            this.videoLink.href = current.video;
            jQuery("#videoLink").colorbox({width:"550px", height:"450px", iframe:true});
            //this.videoLink.href = "javascript:void(0);";
            if(!isIE && this.videoLink.style.opacity == 0){ 
                new Tween(this.videoLink, 250, {opacity:1}, {delay:500}); 
            }else{
                this.videoLink.style.visibility = "visible"; 
            }
        }else{
            if(isIE){ this.videoLink.style.visibility = "hidden";  }
        }
        
        this.slideTitle.innerHTML = "<a href='"+current.url+"'>"+current.title+"</a>";
        this.slideSubTitle.innerHTML = current.excerpt;
        //document.getElementById("slideSubTitle").innerHTML = current.excerpt;
        //alert(current.title+" :::: "+current.excerpt);
        
      if(!isIE){
            this.slideTitle.style.opacity = 0;
            this.slideSubTitle.style.opacity = 0;
        }else{
            this.slideTitle.style.filter = "alpha(opacity=0)";
            this.slideSubTitle.style.filter = "alpha(opacity=0)";
            //this.slideTitle.style.filter = "alpha(opacity=100)";
            //this.slideSubTitle.style.filter = "alpha(opacity=100)";
        }
        //alert(this.storyFlag.style.opacity+" ::: "+this.storyFlag.style.filter);
        new Tween(this.slideTitle, 500, {opacity:1}, {delay:750});
        new Tween(this.slideSubTitle, 500, {opacity:1}, {delay:750});
    }
    
    this.onSlideFadeInComplete = function(){
        alert("SLIDE FADE IN COMPLETE ::: "+document.getElementById("slideTitle").style.opacity);
    }
    this.buildNav = function(){
        this.navItems =[];
        var l = this.slides.length;
        var thisObj = this;
        if(l > 1){ this.storyNav.innerHTML += "<a href='JavaScript:void(0);' id='btnPrev' title='Previous Story' onmousedown='prevNext(1);' ></a>"; } 
        
        for(var i=0;i<l;i++){
            var current = i + 1;
            var str = current;
            
            if(i<(l-1)){
                var thisObj = this;
                this.storyNav.innerHTML += "<a id='"+String(i)+"' href='javascript:void(0);' onmousedown='selectNavItem(this);'>"+str+"</a>";
            }else{
                this.storyNav.innerHTML += "<a id='"+String(i)+"' href='javascript:void(0);' onmousedown='selectNavItem(this);' class='last'>"+str+"</a>";
            }
            this.navItems.push(String(i));
        }
        if(l > 1){
            this.storyNav.innerHTML += "<a href='javascript:void(0);' id='btnNext' title='Next Story' onmousedown='prevNext(2);' ></a>";
            this.btnNext = document.getElementById("btnNext");
            this.btnPrev = document.getElementById("btnPrev");
        }
    }
 
    this.activateNavItems = function(){
        var thisObj = this;
        var l = this.navItems.length;
        for(var i=0;i<l;i++){
            //document.getElementById(this.navItems[i]).onclick = function(){ thisObj.selectNavButton(this); }
            //document.getElementById(this.navItems[i]).onclick = function(){ selectNavItem(); }
        }
    }
    
    this.selectNavButton = function(p_obj){
        this.stopShow();
        this.hideCurrentSlide();
        this.currentSlideIndex = p_obj.id;
    }
    
    this.setNavState = function(p_obj){
        var l = this.navItems.length;
        for(var i=0;i<l;i++){
            var c = document.getElementById(this.navItems[i]);
            if(i != this.currentSlideIndex){
                if(i != l-1){
                    c.className = "";
                }else{
                    c.className = "last";
                }
            }else{
                if(i != (l - 1)){
                    c.className = "selected";
                }else{
                    c.className = "selected last";
                }
            }
        }
    }
    
    this.prevNext = function(p_dir){
        if(this.timer != null){ this.stopShow(); }
        if(p_dir == "prev"){
            this.hideCurrentSlide();
            this.updateSlideIndex(-1);
        }else{
            this.hideCurrentSlide();
            this.updateSlideIndex(1);
        }
    }
    
    this.onSelectButton = function(target, p_index){
        if(this.timer != null){ this.stopShow(); }
        this.hideCurrentSlide();
        this.currentSlideIndex = target.id;
    }
    this.go = function(){
        this.init();
    }
    
   // this.init();
    };
    
function prevNext(dir){
    var dirStr = "prev";
    if(dir == 2){ dirStr = "next"; }
    slideShow.prevNext(dirStr);
}
function selectNavItem(obj){
    slideShow.onSelectButton(obj, obj.id);
}    
    
/******************************************************************************
    * method: homepage linkNav
    * notes:  
    * 
    ***/
function LinkNav(p_data, p_random){
    this.linkData = p_data;
    this.randomize = p_random;
    this.btnLeft;
    this.btnRight;
    this.holder;
    this.actualWidth;
    this.visibleWidth = 900;
    //this.firstClick = false;
    this.divWidth = 240    ;
    this.divMargin = 2;
    this.loadTimer;
    this.startPosition;
    this.fadeTime = 250;
    this.endOpacity = 1.0;
    this.initOpacity=0.5;
    
    this.init = function(){
        thisObj = this;
        var banner = document.getElementById("banner");
        banner.innerHTML += "<div id='featureSelector'><a href='JavaScript:void(0);' id='scrollLeft'></a><div id='scrollWindow'><div id='scrollArea'></div></div><a href='JavaScript:void(0);' id='scrollRight'></a></div>";
        this.holder = document.getElementById("scrollArea");
        
        if(this.randomize){ this.linkData = randomizeArray(this.linkData); }
        this.actualWidth = (this.linkData.length * this.divWidth);
        this.holder.style.width = String(this.actualWidth)+"px";
        
        if(this.holder.style.left != null && this.holder.style.left != ""){
            this.startPosition = parseInt(this.holder.style.left);
        }else{
            this.startPosition = 0;
            this.holder.style.left = "0px";
        }
        
        this.btnLeft = document.getElementById("scrollLeft");
        this.btnRight = document.getElementById("scrollRight");
    
        this.btnLeft.onclick = function(){ thisObj.scrollPrev(); }
        this.btnRight.onclick = function(){ thisObj.scrollNext(); }
        
        this.hide(this.btnLeft);
        this.btnLeft.style.visibility = "hidden";
        this.hide(this.btnRight);
        this.btnRight.style.visibility = "hidden";
        
        this.build();
    }
    
    this.build = function(){
        var thisObj = this;
        this.startWidth = this.holder.style.width;
        this.hide(this.holder);
        this.buildNavItem(0);
    }
    
    this.buildNavItem = function(i){
        var thisObj = this;
        this.linkData[i].id = "featureLink"+i;
        this.linkData[i].imgId = "featureImg"+i;
        if(!isIE){
            //{title:'Move to Surrey', image:'/slideshowImages/property-tax.jpg', url:'/culture-recreation/5001.aspx', style:'green'};
            this.holder.innerHTML += "<div id='feature"+i+"' class='featureItem'><img id='featureImg"+i+"' src=''/><a id='featureLink"+i+"' onmouseover='thisObj.onRollItem(this)' onmouseout='thisObj.onRollOutItem(this)' class='"+this.linkData[i].style+"' href='"+this.linkData[i].url+"'>"+this.linkData[i].title+"</a></div>";
            var current = document.getElementById("featureImg"+i);
            current.style.opacity = this.initOpacity;
            current.src=this.linkData[i].image;
            current.onload = this.imageLoaded(i);
        }else{
            this.holder.innerHTML += "<div id='feature"+i+"' class='featureItem'><img id='featureImg"+i+"' src='"+this.linkData[i].image+"' style='filter:progid:DXImageTransform.Microsoft.BasicImage(grayScale=1)  progid:DXImageTransform.Microsoft.Alpha(opacity=50)' /><a id='featureLink"+i+"' onmouseover='thisObj.onRollItem(this)' onmouseout='thisObj.onRollOutItem(this)' class='"+this.linkData[i].style+"' href='"+this.linkData[i].url+"'>"+this.linkData[i].title+"</a></div>";
            
            if(i<this.linkData.length-1){
                this.buildNavItem(i + 1); 
            }else{
                this.holder.style.visibility = "visible";
                this.holder.style.opacity = 1;
                this.onHolderFadeInComplete({});
            }
        }
    }
    
    this.onRollItem = function(p_obj){
        var currentObj = this.getCurrentData(p_obj);
        var currentImg = document.getElementById(currentObj.imgId);
        if(!isIE){
            currentImg.src = currentObj.image;
            currentImg.style.opacity = this.endOpacity;
        }else{
            currentImg.filters.item("DXImageTransform.Microsoft.BasicImage").enabled=false; 
            //currentImg.filters.item("DXImageTransform.Microsoft.BasicImage").grayScale = 0;
            currentImg.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;
        }
    }
    
    this.onRollOutItem = function(p_obj){
        var currentObj = this.getCurrentData(p_obj);
        var currentImg = document.getElementById(currentObj.imgId);
        if(!isIE){
            currentImg.style.left = "0px";
            currentImg.src = currentObj.grayImg;
            currentImg.style.opacity = this.initOpacity;
        }else{
            currentImg.filters.item("DXImageTransform.Microsoft.BasicImage").enabled=true;
            document.getElementById(currentObj.imgId).filters.item("DXImageTransform.Microsoft.Alpha").opacity = 50;
        }
    }
    
    this.imageLoaded = function(i){
        if(this.loadTimer != null){ clearTimeout(this.loadTimer); }
        
        var img = document.getElementById("featureImg"+i);
        if(!img.complete){
            this.loadTimer = setTimeout(function(){ thisObj.imageLoaded(i) }, 3);
        }else{
            this.linkData[i].grayImg = getGrayScale(img);
            this.linkData[i].imgWidth = img.width;
            img.src = this.linkData[i].grayImg;
            
            if(i < this.linkData.length - 1){ 
                this.buildNavItem(i + 1); 
            }else{
                new Tween(this.holder, 250, { opacity:1 }, {delay:0, scope:this, completeListener:"onHolderFadeInComplete" });
            }
        }
    }
    
    this.onHolderFadeInComplete = function(p_obj){
        if(parseInt(this.holder.style.width) > this.visibleWidth){
            this.btnRight.style.visibility = "visible";
            this.btnRight.style.opacity = 1;
        }
    }
    
    this.scrollPrev = function(){
        this.doScroll(1);
    }
    
    this.scrollNext = function(){
        this.doScroll(-1);
    }
    
    this.doScroll = function(p_dir){
        var current = parseInt(this.holder.style.left);
        var future = current + (this.divWidth * p_dir);
        
        var measuredWidth = (this.linkData.length * this.divWidth) - this.divMargin;
        var maxLeft = this.visibleWidth - measuredWidth + this.startPosition;
        
        if((p_dir > 0 && future <= 0)|| p_dir < 0 && future > maxLeft){
            var myTween = new Tween(this.holder,250, { left:future }, {});
        }
        
        if(p_dir < 0 && (future - this.divWidth) < maxLeft){
            //this.hide(this.btnRight);
            new Tween(this.btnRight,250, { opacity:0 }, { scope:this, completeListener:"onButtonFadeOut"});
        }else{
            this.btnRight.style.opacity = 1;
            this.btnRight.style.visibility = "visible";
        }
        
        if(p_dir > 0 && (future + this.divWidth) > 0){
            //this.hide(this.btnLeft);
            new Tween(this.btnLeft,250, { opacity:0 }, { scope:this, completeListener:"onButtonFadeOut"});
        }else{
            this.btnLeft.style.visibility = "visible";
            this.btnLeft.style.opacity = 1;
        }
    }
    
    this.onButtonFadeOut = function(p_obj){
        p_obj.target.style.visibility = "hidden";
    }
    this.hide = function(p_element){
        //p_element.style.visibility = "hidden";
        p_element.style.opacity = 0;
    }
    
    this.getCurrentData = function(p_div){
        var l=this.linkData.length;
        for(var i=0;i<l;i++){
            if(this.linkData[i].id == p_div.id){
                return this.linkData[i];
            }
        }
        return null;
    }
    
    this.init();
}
/********************************************* */
var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isOpera = (navigator.appName == "Opera");
    function randomizeArray(p_array){
        var temp = p_array;
        var newList = [];
        var l = temp.length;
    
        for(var i=0;i<l;i++){
            var rndIndex = Math.floor(Math.random() * (temp.length));
            var spliced = temp.splice(rndIndex,1);
            newList.push(spliced[0]);
        }
    
        return newList;
    }
function getGrayScale(imgObj){
    try {
        var canvas = document.createElement('canvas');
    
        var canvasContext = canvas.getContext('2d');
        
        var imgW = imgObj.width;
    
        var imgH = imgObj.height;
    
        canvas.width = imgW;
        canvas.height = imgH;
        
        canvasContext.drawImage(imgObj, 0, 0, imgW, imgH);
        
        var imgPixels = canvasContext.getImageData(0, 0, imgW, imgH);
        
        for(var y = 0; y < imgPixels.height; y++){
             for(var x = 0; x < imgPixels.width; x++){
                  var i = (y * 4) * imgPixels.width + x * 4;
                  var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
                  imgPixels.data[i] = avg;
                  imgPixels.data[i + 1] = avg;
                  imgPixels.data[i + 2] = avg;
             }
        }
        canvasContext.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
        
        return canvas.toDataURL();
    }catch(err) {
    }
}
/*****************************************/
// JavaScript Document
var fps = 40;
var isIE = (navigator.appName == "Microsoft Internet Explorer");
function Tween(p_target,p_time,p_tweenProps,p_otherProps){
    this.target = p_target;
    this.timer;
    
    this.duration = p_time;
    this.time = 0;
    this.startTime = 0;
    
    this.tweenProps = p_tweenProps;
    this.otherProps = p_otherProps;
    this.tweens;
    this.stepsTaken;
    this.stepsToTake;
    this.ease = "linear";
    
    this.init = function(){
        var thisObj = this;
        this.initTweens(this.stepsToTake);
        
        if(this.otherProps != null){
            if("ease" in this.otherProps){ this.ease = this.otherProps.ease; }
            if("delay" in this.otherProps){ this.timer = setInterval(function(){ thisObj.startTween() }, thisObj.otherProps.delay); }else{ this.startTween(); }
        }else{
            this.startTween();
        }
    }
    
    this.startTween = function(){
        this.startTime = this.getTimer();
        if(this.timer != null){
            clearInterval(this.timer);
            this.timer = null;
        }
        var thisObj = this;
        this.fireCallback("startListener");
        this.timer = setInterval(function(){ thisObj.onEnterFrame() }, 1000/fps);
    }
    
    this.fireCallback = function(p_listener){
        if(this.otherProps != null && this.otherProps.scope != null && this.otherProps[p_listener] != null && this.otherProps[p_listener] != ""){
            this.otherProps.scope[this.otherProps[p_listener]](this);
        }
    }
    
    this.initTweens = function(p_numSteps){
        //this.stepsTaken = 0;
        this.tweens = [];
        for(var n in this.tweenProps){
            var obj = new Object();
            obj.prop = n;
            obj.endVal = this.tweenProps[n];
            
            if(typeof(this.target.style[n] == "string")){
                if(isIE && n == "opacity"){ 
                    var str = this.target.style.filter;
                    if(str != ""){
                        var temp = str.split("=");
                        temp = temp[1].split(")");
                        obj.begin = Number(temp[0])/100;
                    }else{
                        obj.begin = 0;
                    }
                }else if(this.target.style[n] == ""){
                    obj.begin = 0;
                }else{
                    obj.begin = parseInt(this.target.style[n]);
                }
            }else{
                obj.begin = this.target.style[n];
            }
            
            obj.change = obj.endVal - obj.begin;
            obj.distancePerFrame = Math.abs((obj.endVal - obj.begin)/p_numSteps);
            obj.current = obj.begin;
            obj.dir = 1;
            
            if(obj.endVal < obj.begin){ obj.dir = -1; }
            this.tweens.push(obj);
        }
    }
    
    this.onEnterFrame = function(){
        this.setTime((this.getTimer() - this.startTime) / 1000);
        this.fireCallback("progressStartListener");
        //this.stepsTaken++;
        var style = this.target.style;
        //console.log("target ::: "+this.target+" ::: "+style);
        var l = this.tweens.length;
        for(var i = 0;i<l;i++){
            var prop = this.tweens[i].prop;
            var val = Tween[this.ease](this.time,this.tweens[i].begin,this.tweens[i].change,this.duration/1000);
            switch(prop){
                case "left": case "top": case "bottom": case "right": 
                    style[prop] = String(val)+"px";
                    break;
                default:
                    if(isIE && prop == "opacity"){
                        //filter:alpha(opacity=50);
                        style["filter"]  = "alpha(opacity="+(val * 100)+")";
                        //style.filter:alpha(opacity=)
                    }else{
                        style[prop] = val;
                    }
                    break;
            }
        }
        this.fireCallback("progressListener");
        
        if(this.time >= (this.duration/1000)){
            clearInterval(this.timer);
            this.timer = null;
            this.finalize();
        }
    }
    
    this.finalize = function(){
        var style = this.target.style;
        var l = this.tweens.length;
        for(var i = 0;i<l;i++){
            var prop = this.tweens[i].prop;
            //style[prop] = this.tweens[i].endVal;
            switch(prop){
                case "left": case "top": case "bottom": case "right": 
                    style[prop] = String(this.tweens[i].endVal)+"px";
                    break;
                default:
                    if(isIE && prop == "opacity"){
                        style["filter"]  = "alpha(opacity="+(this.tweens[i].endVal * 100)+")";
                    }else{
                        style[prop] = this.tweens[i].endVal;
                    }
                    break;
            }
            
        }
        this.fireCallback("completeListener");
    }
    
    this.getTimer = function(){
        return new Date().getTime() - this.time;
    }
    
    this.setTime = function(p_time){
        this.time = p_time;
    }
    
   
    this.init();
}
/* borrowed easing functionality */
Tween.backEaseIn = function(t,b,c,d,a,p){
    if (s == undefined) var s = 1.70158;
    return c*(t/=d)*t*((s+1)*t - s) + b;
}
Tween.backEaseOut = function(t,b,c,d,a,p){
    if (s == undefined) var s = 1.70158;
    return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
}
Tween.backEaseInOut = function(t,b,c,d,a,p){
    if (s == undefined) var s = 1.70158; 
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}
Tween.elasticEaseIn = function(t,b,c,d,a,p){
        if (t==0) return b;  
        if ((t/=d)==1) return b+c;  
        if (!p) p=d*.3;
        if (!a || a < Math.abs(c)) {
            a=c; var s=p/4;
        }
        else 
            var s = p/(2*Math.PI) * Math.asin (c/a);
        
        return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
    
}
Tween.elasticEaseOut = function (t,b,c,d,a,p){
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
    }
Tween.elasticEaseInOut = function (t,b,c,d,a,p){
    if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) var p=d*(.3*1.5);
    if (!a || a < Math.abs(c)) {var a=c; var s=p/4; }
    else var s = p/(2*Math.PI) * Math.asin (c/a);
    if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
    return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
}
Tween.bounceEaseOut = function(t,b,c,d){
    if ((t/=d) < (1/2.75)) {
        return c*(7.5625*t*t) + b;
    } else if (t < (2/2.75)) {
        return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
    } else if (t < (2.5/2.75)) {
        return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
    } else {
        return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
    }
}
Tween.bounceEaseIn = function(t,b,c,d){
    return c - Tween.bounceEaseOut (d-t, 0, c, d) + b;
}
Tween.bounceEaseInOut = function(t,b,c,d){
    if (t < d/2) return Tween.bounceEaseIn (t*2, 0, c, d) * .5 + b;
    else return Tween.bounceEaseOut (t*2-d, 0, c, d) * .5 + c*.5 + b;
}
Tween.strongEaseInOut = function(t,b,c,d){
    return c*(t/=d)*t*t*t*t + b;
}
Tween.regularEaseIn = function(t,b,c,d){
    return c*(t/=d)*t + b;
}
Tween.regularEaseOut = function(t,b,c,d){
    return -c *(t/=d)*(t-2) + b;
}
Tween.regularEaseInOut = function(t,b,c,d){
    if ((t/=d/2) < 1) return c/2*t*t + b;
    return -c/2 * ((--t)*(t-2) - 1) + b;
}
Tween.strongEaseIn = function(t,b,c,d){
    return c*(t/=d)*t*t*t*t + b;
}
Tween.strongEaseOut = function(t,b,c,d){
    return c*((t=t/d-1)*t*t*t*t + 1) + b;
}
Tween.strongEaseInOut = function(t,b,c,d){
    if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
    return c/2*((t-=2)*t*t*t*t + 2) + b;
}
Tween.linear = function(t,b,c,d){
    return c*(t/=d)+b;
}
/*****************************************/
function getBoolean(p_str){
    return (p_str.toUpperCase() == "TRUE");
}
var linkNav;
var slideShow = new slideShowClass();
 
/***************************************
** ImageLoader Class
*/
function ImageLoader(path, callback){
    this.imgPath = path;
    this.imgObject;
    this.loadTimer;
    this.callbackObj = callback;
    
    this.init = function(){
        //start load!
        if(this.imgPath != null) this.startLoad();
    }
    
    this.setImage = function(path, callback){
        this.imgPath = path;
        this.callbackObj = callback;
        this.startLoad();
    }
    
    this.startLoad = function(){
        this.imgObject = new Image();
        this.imgObject.src = this.imgPath;
        this.imgObject.onLoad = this.onImgLoaded();
    }
    
    this.onImgLoaded = function(){
        if(this.loadTimer != null) clearTimeout(this.loadTimer);
        if(!this.imgObject.complete){
            
            //alert(this.imgObject+" ::: "+this.imgObject.complete);
            var thisObj = this;
            this.loadTimer = setTimeout(function(){ thisObj.onImgLoaded() }, 3);
        }else{
            this.onComplete();
        }
        
    }
    
    this.onComplete = function(){
        if(this.callbackObj != null){
            this.callbackObj.scope[this.callbackObj.func](this.imgObject);
        }
    }
    
    this.init();
}
function onPageReady(){
    if(slideShow) slideShow.go();
}
if(objCommon != null){
    objCommon.addEvent(window, 'load', function() { onPageReady(); });
}
