var baseurl="http://www.bobbydiamondsdeals.com/";

//add images to this list to update the slideshow (filename, width, height, desc)
var imglist = new Array(
	{path:"photo1.jpg", w:"571", h:"360", desc:""},	
	{path:"photo3.jpg", w:"276", h:"360", desc:""},
	{path:"photo4.jpg", w:"265", h:"360", desc:""},
	{path:"photo5.jpg", w:"360", h:"360", desc:""},
	{path:"photo6.jpg", w:"360", h:"360", desc:""},
	{path:"photo7.jpg", w:"360", h:"360", desc:""},	
	{path:"photo9.jpg", w:"360", h:"360", desc:""},
	{path:"photo10.jpg", w:"360", h:"360", desc:""},
	{path:"photo11.jpg", w:"360", h:"360", desc:""},
	{path:"photo12.jpg", w:"252", h:"360", desc:""},
	{path:"photo13.jpg", w:"376", h:"360", desc:""},
	{path:"photo14.jpg", w:"331", h:"360", desc:""},
	{path:"photo15.jpg", w:"282", h:"360", desc:""},
	{path:"photo16.jpg", w:"240", h:"360", desc:""},
	{path:"photo17.jpg", w:"240", h:"360", desc:""},
	{path:"photo18.jpg", w:"541", h:"360", desc:""},
	{path:"photo19.jpg", w:"240", h:"360", desc:""},
	{path:"photo20.jpg", w:"221", h:"360", desc:""},
	{path:"photo21.jpg", w:"240", h:"360", desc:""},
	{path:"photo22.jpg", w:"240", h:"360", desc:""},
	{path:"photo23.jpg", w:"240", h:"360", desc:""},
	{path:"photo24.jpg", w:"240", h:"360", desc:""},
	{path:"photo25.jpg", w:"240", h:"360", desc:""},
	{path:"photo26.jpg", w:"240", h:"360", desc:""},
	{path:"photo27.jpg", w:"240", h:"360", desc:""},
	{path:"photo28.jpg", w:"221", h:"360", desc:""},
	{path:"photo29.jpg", w:"240", h:"360", desc:""},
	{path:"photo30.jpg", w:"240", h:"360", desc:""},
	{path:"photo31.jpg", w:"240", h:"360", desc:""},
	{path:"photo32.jpg", w:"240", h:"360", desc:""},
	{path:"photo33.jpg", w:"240", h:"360", desc:""},
	{path:"photo34.jpg", w:"240", h:"360", desc:""},
	{path:"photo35.jpg", w:"239", h:"359", desc:""},
	{path:"photo36.jpg", w:"239", h:"359", desc:""},
	{path:"photo37.jpg", w:"240", h:"360", desc:""},
	{path:"photo38.jpg", w:"539", h:"360", desc:""}
	
);
//------------------------
//ANIMATION FUNCTIONS
//------------------------
var cur = 0;
var moving = false;
var xpos = 0;
var dx = 0;
var targx = -841;
var timer;
var ease = .1;
var speed = 1;
var rampup = 1.2;
var rampdwn = .99;
var flip = false;
var cdir = 1;
//imagelist and theslide are both defined inside an in-page script tag via php
function startAnimation(){
    if (!timer) timer = setInterval(moveSlide, 30);
}

function stopAnimation(){
    if (!timer) return false;
    clearInterval(timer);
    timer = null;
}

function changeSlide(idir){
    if (!moving) {
        cdir = idir;
        speed = 1;
        if (cdir==1) {
            targx = -705;
        } else {
            targx = 705;
        }
        theslide = document.getElementById("photo1");
        cur += idir;
        xpos = 0;
        if (cur > imglist.length - 1) {
            cur = 0;
        } else if (cur < 0) {
            cur = imglist.length - 1
        }
        moving = true;
        startAnimation();
		document.getElementById("slidecount").innerHTML="<strong>"+(cur+1)+ " of "+imglist.length+"</strong>";
		//document.getElementById("photo_desc").innerHTML=imglist[(cur)].desc;	
		
    }
}
//preload rollover images
var tp, tn, tpr, tnr;
if (document.images){
	//normals
	tp = new Image();//tall_prev
  	tn = new Image();//tall_next
  	tp.src = baseurl + "images/prev_norm.jpg";
  	tn.src = baseurl + "images/next_norm.jpg";
	//rollovers
  	tpr = new Image();//tall_prev roll
  	tnr = new Image();//tall_next roll
  	tpr.src = baseurl + "images/prev_roll.jpg";
  	tnr.src = baseurl + "images/next_roll.jpg";
}
//basic rollover
function swap(img,newImg){
	if (document.images) {
		document.getElementById(img).src=eval(newImg).src;
		//document.images[img].src = 
	}
}

function moveSlide(){
    if (moving) {
        //update speed
        if (flip) {
            speed = Math.max(speed * rampdwn, 1);
        } else {
            speed = Math.min(speed * rampup, 75);
        }
        
        //check bounds
        if (cdir==1) {
            //MOVING TO THE NEXT IMAGE
            xpos -= speed;
            if (xpos < targx) {
                if (targx == -705) {
                    xpos = 705;
                    //load new image while offscreen
                    document.getElementById("photodiv").innerHTML = "<img src="+baseurl+"images/photos/" + imglist[cur].path + " width=" + imglist[cur].w + " height=" + imglist[cur].h + " alt=\"\" />";
                    targx = 0;
                    flip = true;
                } else {
                    //we arrived at the viewing location with the new image loaded
                    if (targx == 0) {
                        xpos = 0;
                        moving = false;
                        stopAnimation();
                        flip = false;
                    }
                }
                
            }
        } else {
            //MOVING TO THE PREV IMAGE
            xpos += speed;
            if (xpos > targx) {
                if (targx == 705) {
					//load new image while offscreen
                    xpos = -705;
                    document.getElementById("photodiv").innerHTML = "<img src="+baseurl+"images/photos/" + imglist[cur].path + " width=" + imglist[cur].w + " height=" + imglist[cur].h + " alt=\"\" />";
                    targx = 0;
                    flip = true;
                } else {
                    //we arrived at the viewing location with the new image loaded
                    if (targx == 0) {
                        xpos = 0;
                        moving = false;
                        stopAnimation();
                        flip = false;
                    }
                }
            }
        }
        if (theslide != null) {
            theslide.style.left = xpos + "px";
        }
    }
}
