$(document).ready(function() {
	var imgPath = "http://glenechoglassworks.com/wordpress/wp-content/themes/glenechoglassworks/images/";
	var imgWidth = "15";
	var imgHeight = "13";
	var slideCurrent = 1;

	var html = "";
	html += "<a href=\"#\" class=\"btn previous\"><img src=\""+imgPath+"arrow_left.png\" class=\"left\" alt=\"previous\" width=\""+imgWidth+"\" height=\""+imgHeight+"\" border=\"0\"></a>";
	html += "<div class=\"count\">";
	$('#slide_container > div').each(function(i) {
		html += "<div id=\"num"+(i+1)+"\" class=\"slidecount\">" + (i + 1) + "</div>";
	});
	html += " of ";
	html += $('#slide_container > div').length;
	html += "</div>";
	html += "<a href=\"#\" class=\"btn next\"><img src=\""+imgPath+"arrow_right.png\" class=\"right\" alt=\"next\" width=\""+imgWidth+"\" height=\""+imgHeight+"\" border=\"0\"></a>";

	$("#arrows").html(html);
	changeNum(1);
	
	$('.btn').click(function(e) {
		e.preventDefault();
		var slidesCount = $('#slide_container').children().length;
		if ( $(this).hasClass('next') ) {
			if (slideCurrent >= slidesCount) {
				slideCurrent = 1;
			} else {
				slideCurrent++;
			}
		} else if ( $(this).hasClass('previous') ) {
			if (slideCurrent <= 1) {
				slideCurrent = slidesCount;
			} else {
				slideCurrent--;
			}
		}
		changeSlide(slideCurrent);
	});

	function changeSlide(slideCurrent) {
		var $active = $('#slide_container DIV.active');
		if ( $active.length == 0 ) $active = $('#slide_container DIV:last');
		var $next =  $('#slide'+slideCurrent);
		$active.addClass('last-active');
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 800, function() {
				$active.removeClass('active last-active');
		});
		changeNum(slideCurrent);
	}

	function changeNum(id) {
		$('.count > div').each(function() {
			$(this).css('display','none');
		});
		$('#num'+id).css('display','inline');
	}

});
