var isBloomingdales = "false";

function setAsBloomingdales() {
    isBloomingdales = "true";
}

//BEGIN - Creation of SlideShow object.  Also new method
//        defintions on this new object.
function SlideShow () {
    this.slideShow = new Array();
    this.counter = 0;
}

if(typeof Array.prototype.copy=='undefined')
    Array.prototype.copy=function(a){
        var
            i=0,
            b=[];
        for(i;i<this.length;i++)
            b[i]=(typeof this[i].copy!='undefined')?
                this[i].copy():
                this[i];
        return b
    };

if(typeof Array.prototype.splice=='undefined') {
    Array.prototype.splice=function(a,c){
        var
            i=0,
            e=arguments,
            d=this.copy(),
            f=a;
        if(!c)
            c=this.length-a;
        for(i;i<e.length-2;i++)
            this[a+i]=e[i+2];
        for(a;a<this.length-c;a++)
            this[a+e.length-2]=d[a-c];
        this.length-=c-e.length+2;
        return d.slice(f,f+c)
    };
}

SlideShow.prototype.size = function () {
    return this.slideShow.length;
}

SlideShow.prototype.increment = function () {
    this.counter += 1;
    if(this.counter > this.size()) {
        this.counter = this.size();
    }
}

SlideShow.prototype.decrement = function () {
    this.counter -= 1;
    if(this.counter < 0) {
        this.counter = 0;
    }
}

SlideShow.prototype.addSlide = function (slide) {
    this.slideShow[this.size()] = slide;
}

SlideShow.prototype.removeSlide = function (slide) {
    var index = -1;
    for(var i=0; i < this.size(); i++) {
        var tempSlide = this.getSlide(i);
        if(slide == tempSlide) {
            index = i;
            break;
        }
    }
    if(index > -1) {
        this.removeSlideAtIndex(i);
    }
}

SlideShow.prototype.removeSlideAtIndex = function (index) {
    this.slideShow.splice(index,1);
    this.decrement();
}

SlideShow.prototype.removeSlideAtIndex = function (index) {
    this.slideShow.splice(index,1);
    this.decrement();
}

SlideShow.prototype.getSlide = function (index) {
    if(index >= 0 && index <= this.size()) {
        this.counter = index;
        return this.slideShow[index];
    } else {
        return null;
    }
}

SlideShow.prototype.getRandomSlide = function (noDuplicates) {
    this.counter = Math.round((this.size()-1) * Math.random());
    if(this.counter > this.size()) {
        this.decrement();
    }
    if(this.counter < 0) {
        this.increment();
    }
    var slide = this.getSlide(this.counter);
    if(noDuplicates) {
        this.removeSlideAtIndex(this.counter);
    }
    return slide;
}

SlideShow.prototype.getNextSlide = function () {
    this.increment();
    return this.getSlide(this.counter);
}

SlideShow.prototype.getPrevSlide = function () {
    this.decrement();
    return this.getSlide(this.counter);
}

SlideShow.prototype.isLastSlide = function (slide) {
    return (this.getSlide(this.size()) == slide);
}

SlideShow.prototype.isFirstSlide = function (slide) {
    return (this.getSlide(0) == slide);
}
//END - Creation of SlideShow object.  Also new method
//      defintions on this new object.

function showMessage(divId, messageText){
    if (document.all){
        document.all(divId).innerHTML = messageText;
    }else if (document.getElementById){
        document.getElementById(divId).innerHTML =  messageText;
    }
}

function writeHTML(slideShow, currentPageNumber) {
    writeZoomObject('zoomObject',slideShow.getSlide(currentPageNumber));
    if(slideShow.size() > 1) {
        writePagination('zoomPagination',slideShow,currentPageNumber);
    }
}






function writeZoomObject(divId, productImage) {
    //create html call to get zoom for image
    var objectString = '';

    if (isBloomingdales == "true") {
       objectString += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="300" HEIGHT="300" id="tsf40722" ALIGN="">';
       objectString += ' <PARAM NAME="movie" VALUE="http://images.bloomingdales.com/is-viewers/flash/zoommx.swf?svr=http://images.bloomingdales.com/is/image/BLM&img=/';
       objectString += productImage;
       objectString += '&bgc=FFFFFF&mz=5,2&ui=1&nv=3&w=300&h=300">';
       objectString += ' <PARAM NAME="menu" VALUE="false">';
       objectString += ' <PARAM NAME="quality" VALUE="high">';
       objectString += ' <PARAM NAME="scale" VALUE="noscale">';
       objectString += ' <PARAM NAME="salign" VALUE="LT">';
       objectString += ' <PARAM NAME="bgcolor" VALUE="#FFFFFF">';
       objectString += ' <EMBED src="http://images.bloomingdales.com/is-viewers/flash/zoommx.swf?svr=http://images.bloomingdales.com/is/image/BLM&img=/';
       objectString += productImage;
       objectString += '&bgc=FFFFFF&mz=5,2&ui=1&nv=3&w=300&h=300" menu="false" quality="high" scale="noscale" salign="LT" bgcolor="#FFFFFF" WIDTH="300" HEIGHT="300" NAME="tsf40722" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>';
       objectString += '</OBJECT>';
    } else {
        objectString += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="300" HEIGHT="365" id="tsf32861" ALIGN="">';
        objectString += '<PARAM NAME=movie VALUE="http://wc.slimages.macys.com/is-viewers/flash/zoommx.swf?svr=http://wc.slimages.macys.com/is/image/&img='
		objectString += removeImagePath(productImage);
		objectString += '&bgc=FFFFFF&mz=5,2&ui=1&nv=3&w=300&h=365">';
        objectString += '<PARAM NAME="menu" VALUE="false">';
        objectString += '<PARAM NAME="quality" VALUE="high">';
        objectString += '<PARAM NAME="scale" VALUE="noscale">';
        objectString += '<PARAM NAME="salign" VALUE="LT">';
        objectString += '<PARAM NAME="bgcolor" VALUE="#FFFFFF">';
        objectString += '<EMBED src="http://wc.slimages.macys.com/is-viewers/flash/zoommx.swf?svr=http://wc.slimages.macys.com/is/image/&img='
		objectString += removeImagePath(productImage);
		objectString += '&bgc=FFFFFF&mz=5,2&ui=1&nv=3&w=300&h=365" menu=false quality=high scale=noscale salign=LT bgcolor=#FFFFFF WIDTH="300" HEIGHT="365" NAME="tsf86444" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>';
        objectString += '</OBJECT>';
    }

    //write html out to div
    showMessage(divId, objectString);
}

function writePagination(divId, slideShow, index) {
    //create html call to get pagination for zoom images
    var size = slideShow.size();
    var paginationString = '';
    if(index > 0) {
        paginationString += '<a class="zoomPagination" href="javascript:writeZoomObject(\'zoomObject\',slideShow.getPrevSlide());writePagination(\'zoomPagination\',slideShow,slideShow.counter);"><b>&lt;</b></a> ';
    }
    for(var i=0; i < size; i++) {
        var j = i+1;
        //don't link if viewing current slide
        if( index != i ) {
            paginationString += '<a class="zoomPagination" href="javascript:writeHTML(slideShow,'+ i +');">';
        }
            paginationString += j;
        //don't link if viewing current slide
        if( index != i ) {
            paginationString += '</a>';
        }
        if(j < size) {
            paginationString += ' | ';
        }
    }
    if( index+1 < size ) {
        paginationString += ' <a class="zoomPagination" href="javascript:writeZoomObject(\'zoomObject\',slideShow.getNextSlide());writePagination(\'zoomPagination\',slideShow,slideShow.counter);"><b>&gt;</b></a>';
    }

    //write html out to div
    showMessage(divId, paginationString);
}

	function removeImagePath(productImagePath) {
		var path = new String(productImagePath);
		return path.replace("http://slimages.macys.com/is/image/","");
	}


