

function picture(square)
{
	this.whereAmI = square;
	this.square=square;
	this.shift = 115;
	this.fromTheEdge = $('#carouselHolder').offset().left + 1;
	this.imageWidth;
	this.imageHeight;
	this.opacity;

	this.setImageSize = function()
	{
		this.getHeightWidth(this.whereAmI);
		$('#img' + square + ' img').animate({ 'height': this.imageHeight + 'px', 'width': this.imageWidth + 'px', 'opacity': this.opacity });
		$('#img' + square).animate({ 'height': this.imageHeight + 'px', 'width': this.imageWidth + 'px', "paddingTop": (300 - this.imageHeight) + "px", 'opacity': this.opacity });
	}

	this.getHeightWidth = function (position) {
		switch(position){
			case 1:
					this.imageWidth = 105;
					this.imageHeight = 125;
					this.opacity = 0.30;
					break;
			case 2:
					this.imageWidth = 145;
					this.imageHeight = 175;
					this.opacity = 0.30;
					break;
			case 3:
					this.imageWidth = 250;
					this.imageHeight = 300;
					this.opacity = 1;
					break;
			case 4:
					this.imageWidth = 145;
					this.imageHeight = 175;
					this.opacity = 0.30;
					break;
			case 5:
					this.imageWidth = 105;
					this.imageHeight = 125;
					this.opacity = 0.25;
					break;
			case 6:
					this.imageWidth = 105;
					this.imageHeight = 125;
					this.opacity = 0;
					break;
			case 7:
					this.imageWidth = 105;
					this.imageHeight = 125;
					this.opacity = 0;
					break;
			default:
					this.imageWidth = 105;
					this.imageHeight = 125;
					this.opacity = 0.30;
		}
	}

	this.getPrevWidthRight = function () {
		switch(this.whereAmI){
			case 1:
					return 105;
					break;
			case 2:
					return 145;
					break;
			case 3:
					return 250;
					break;
			case 4:
					return 145;
					break;
			case 5:
					return 105;
					break;
			case 6:
					return 105;
					break;
			case 7:
					return 105;
					break;
			default:
					return 105;
		}
	}

	this.getPrevWidthLeft = function () {
		switch(this.whereAmI){
			case 1:
					return -100;
					break;
			case 2:
					return 124;
					break;
			case 3:
					return 164;
					break;
			case 4:
					return 269;
					break;
			case 5:
					return 164;
					break;
			case 6:
					return 124;
					break;
			case 7:
					return 124;
					break;
			default:
					return 124;
		}
	}

	this.setImageSize();

	this.getLocation = function(direction) {
	this.fromTheEdge = $('#carouselHolder').offset().left + 1;
	$('#next').hide();
	$('#previous').hide();
		
			this.position = $('#img' + square).offset();


			var moveValue = 0;
	
			if (direction=="R")
			{
				//moveValue = (this.shift - this.fromTheEdge) - ((square-1) * this.shift);
				moveValue = this.getPrevWidthRight();
				if (this.position.left > ((915) + (this.fromTheEdge -10)))
				{
					//$('#img' + square).css({ "left": "-" + (this.shift - this.fromTheEdge) + "px", "opacity": 50 });
					//this.position.left = -(this.shift - this.fromTheEdge);
					$('#img' + square).css({ "left": "-"+(this.shift * this.square)+"px", "opacity": 50 });
					this.position.left = -(this.shift - this.fromTheEdge);
					//alert ('2:' +  this.position.left + "-" + moveValue);
				}
				this.getHeightWidth(this.whereAmI + 1);
				$('#img' + square).animate({ "left": ((this.position.left) - (this.fromTheEdge - 10) + (moveValue)) + "px", "height": this.imageHeight + "px", "width": this.imageWidth + "px", "paddingTop": (300 - this.imageHeight) + "px", "opacity": this.opacity }, 800);
				$('#img' + square + ' img').animate({ "left": ((this.position.left) - (this.fromTheEdge - 10) + (moveValue)) + "px", "height": this.imageHeight + "px", "width": this.imageWidth + "px", "opacity": this.opacity }, 800, function() { $('#next').show(); $('#previous').show(); });
				if (this.whereAmI == 7)
				{
					this.whereAmI = 1;
				} else {
					this.whereAmI++;
				}
				
							

			
			} else {
				//var moveValue = -((square * this.shift) + this.fromTheEdge);
				var moveValue = -(this.getPrevWidthLeft());
				
				if (this.position.left < this.fromTheEdge + 1)
				{
					$('#img' + square).css({ "left": (this.shift * 7) + this.fromTheEdge + "px", "opacity": 50 });
					this.position.left = (this.shift * 7) + this.fromTheEdge;
				}
				this.getHeightWidth(this.whereAmI - 1);
				$('#img' + square).animate({ "left": (this.position.left + moveValue) - (this.fromTheEdge - 10) + "px", "height": this.imageHeight + "px", "width": this.imageWidth + "px", "paddingTop": (300 - this.imageHeight) + "px", "opacity": this.opacity }, 800);
				$('#img' + square + ' img').animate({ "left": ((this.position.left) - (this.fromTheEdge - 10) + (moveValue)) + "px", "height": this.imageHeight + "px", "width": this.imageWidth + "px", "opacity": this.opacity }, 800, function() { $('#previous').show(); $('#next').show(); });
				if (this.whereAmI == 1)
				{
					this.whereAmI = 7;
				} else {
					this.whereAmI--;
				}
				
			}
			this.setImageSize();
	};

}

$(document).ready(function() {

    var pic1 = new picture(1);
    var pic2 = new picture(2);
    var pic3 = new picture(3);
    var pic4 = new picture(4);
    var pic5 = new picture(5);
    var pic6 = new picture(6);
    var pic7 = new picture(7);

    $('#next').click(function() {

        pic1.getLocation("R");
        pic2.getLocation("R");
        pic3.getLocation("R");
        pic4.getLocation("R");
        pic5.getLocation("R");
        pic6.getLocation("R");
        pic7.getLocation("R");
    });


    $('#previous').click(function() {

        pic1.getLocation("L");
        pic2.getLocation("L");
        pic3.getLocation("L");
        pic4.getLocation("L");
        pic5.getLocation("L");
        pic6.getLocation("L");
        pic7.getLocation("L");
    });

    $fire = 1;
    $('#carousel').hover(function() {
        $fire = 0;
    }, function() { $fire = 1;});

    window.setInterval(function() {
        if ($fire == 1) {
            pic1.getLocation("R");
            pic2.getLocation("R");
            pic3.getLocation("R");
            pic4.getLocation("R");
            pic5.getLocation("R");
            pic6.getLocation("R");
            pic7.getLocation("R");
        }
    }, 5000);


});


   
