function picture(square) {

    if ($('#home-gallery').length > 0) {
        $('#home-gallery').show();

        this.whereAmI = square;
        this.square = square;
        this.fromTheEdge = $('#carouselHolder').offset().left + 1;
        this.imageWidth;
        this.imageHeight;
        this.opacity;

        this.setImageSize = function() {
            this.getHeightWidth(this.whereAmI);
            $('#img' + square).animate({ 'height': (this.imageHeight + 20) + 'px', 'width': (this.imageWidth + 20) + 'px', "paddingTop": (this.getTopPadding()) + "px", 'opacity': this.opacity });
            $('#img' + square + ' img.border').animate({ 'height': this.imageHeight + 'px', 'width': this.imageWidth + 'px' });

        }

        this.setTitleText = function() {
            this.title = $('#img' + square + ' img.border').attr('title');
            if (this.imageWidth == 295) {
                $('#pic-desc').html(this.title);
            }
        }

        this.getHeightWidth = function(position) {
            switch (position) {
                case 1:
                    this.imageWidth = 594;
                    this.imageHeight = 306;
                    this.opacity = 1;
                    break;
                case 2:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.70;
                    break;
                case 3:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.5;
                    break;
                case 4:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.30;
                    break;
                case 5:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.5;
                    break;
                case 6:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.7;
                    break;
                case 7:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.7;
                    break;
                case 8:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.7;
                    break;
                case 9:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.7;
                    break;
                case 10:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.7;
                    break;
                case 11:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 0.7;
                    break;
                default:
                    this.imageWidth = 390;
                    this.imageHeight = 200;
                    this.opacity = 1;
            }
        }

        this.getPrevWidthRight = function () {
            switch (this.whereAmI) {
                case 1:
                    return 420;
                    break;
                case 2:
                    return 270;
                    break;
                case 3:
                    return 177;
                    break;
                case 4:
                    return 177;
                    break;
                case 5:
                    return 177;
                    break;
                case 6:
                    return 177;
                    break;
                case 7:
                    return 177;
                    break;
                case 8:
                    return 177;
                    break;
                case 9:
                    return 177;
                    break;
                case 10:
                    return 0;
                    break;
                case 11:
                    return 103;
                    break;
                default:
                    return 0;
            }
        }

        this.getPrevWidthLeft = function() {
            switch (this.whereAmI) {
                case 1:
                    return 0;
                    break;
                case 2:
                    return 103;
                    break;
                case 3:
                    return 420;
                    break;
                case 4:
                    return 270;
                    break;
                case 5:
                    return 177;
                    break;
                case 6:
                    return 177;
                    break;
                case 7:
                    return 177;
                    break;
                case 8:
                    return 177;
                    break;
                case 9:
                    return 177;
                    break;
                case 10:
                    return 177;
                    break;
                case 11:
                    return 177;
                    break;
                default:
                    return 0;
            }
        }

        this.getZIndex = function() {
			switch (this.whereAmI) {
                case 1:
                    return 11;
                    break;
                case 2:
                    return 10;
                    break;
                case 3:
                    return 9;
                    break;
                case 4:
                    return 8;
                    break;
                case 5:
                    return 7;
                    break;
                case 6:
                    return 6;
                    break;
                case 7:
                    return 6;
                    break;
                case 8:
                    return 7;
                    break;
                case 9:
                    return 8;
                    break;
                case 10:
                    return 9;
                    break;
                case 11:
                    return 10;
                    break;
                default:
                    return 99;
            }
        }

        this.getTopPadding = function() {
            switch (this.whereAmI) {
                case 1:
                    return 7;
                    break;
                case 2:
                    return 60;
                    break;
                case 3:
                    return 60;
                    break;
                case 4:
                    return 60;
                    break;
                case 5:
                    return 60;
                    break;
                case 6:
                    return 60;
                    break;
                case 7:
                    return 60;
                    break;
                case 8:
                    return 60;
                    break;
                case 9:
                    return 60;
                    break;
                case 10:
                    return 60;
                    break;
                case 11:
                    return 60;
                    break;
                default:
                    return 0;
            }
        }

        this.setImageSize();
        //this.setTitleText();

        this.getLocation = function (direction) {
            this.fromTheEdge = $('#carouselHolder').offset().left;
            
            this.position = $('#img' + square).offset();

            var moveValue = 0;
            var topPad = 0;

            if (direction == "R") {
                moveValue = this.getPrevWidthRight();

                if (this.whereAmI == 11) {
                    this.whereAmI = 1;
                } else {
                    this.whereAmI++;
                }

                topPad = this.getTopPadding();

                this.getHeightWidth(this.whereAmI);

                $('#img' + square).stop(true, true).animate({ "left": ((moveValue)) + "px", "height": (this.imageHeight+20) + "px", "width": (this.imageWidth+20) + "px", "paddingTop": (topPad) + "px", "opacity": this.opacity }, 800).css({ "z-index": this.getZIndex() });
                $('#img' + square + ' img.border').stop(true, true).animate({ "height": this.imageHeight + "px", "width": this.imageWidth + "px" }, 800, function () { $('#next').show(); $('#previous').show(); });

            } else {
                moveValue = this.getPrevWidthLeft();

                if (this.whereAmI == 1) {
                    this.whereAmI = 11;
                } else {
                    this.whereAmI--;
                }

                topPad = this.getTopPadding();

                this.getHeightWidth(this.whereAmI);

                $('#img' + square).stop(true, true).animate({ "left": moveValue + "px", "height": (this.imageHeight+20) + "px", "width": (this.imageWidth+20) + "px", "paddingTop": (topPad) + "px", "opacity": this.opacity }, 800).css({ "z-index": this.getZIndex() });
                $('#img' + square + ' img.border').stop(true, true).animate({"height": this.imageHeight + "px", "width": this.imageWidth + "px" }, 800, function () { $('#previous').show(); $('#next').show(); });
            }
            this.setImageSize();
            //this.setTitleText();
        };
    }
}

$(document).ready(function() {

    if ($('#home-gallery').length > 0) {
		var pic1 = new picture(11);
		var pic2 = new picture(1);
		var pic3 = new picture(2);
		var pic4 = new picture(3);
		var pic5 = new picture(4);
		var pic6 = new picture(5);
		var pic7 = new picture(6);
		var pic8 = new picture(7);
		var pic9 = new picture(8);
		var pic10 = new picture(9);
		var pic11 = new picture(10);

		pic1.getLocation("R");
		pic2.getLocation("R");
		pic3.getLocation("R");
		pic4.getLocation("R");
		pic5.getLocation("R");
		pic6.getLocation("R");
		pic7.getLocation("R");
		pic8.getLocation("R");
		pic9.getLocation("R");
		pic10.getLocation("R");
		pic11.getLocation("R");

		$('#next').click(function() {

			pic1.getLocation("R");
			pic2.getLocation("R");
			pic3.getLocation("R");
			pic4.getLocation("R");
			pic5.getLocation("R");
			pic6.getLocation("R");
			pic7.getLocation("R");
			pic8.getLocation("R");
			pic9.getLocation("R");
			pic10.getLocation("R");
			pic11.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");
			pic8.getLocation("L");
			pic9.getLocation("L");
			pic10.getLocation("L");
			pic11.getLocation("L");
		});

		$fire = 1;
		$('#home-gallery').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");
                pic8.getLocation("R");
                pic9.getLocation("R");
                pic10.getLocation("R");
                pic11.getLocation("R");
            }
        }, 5000);
		
    }
});
