
function validate_email_list() {
	var makeError = false;
	$("#email_form").children("input").each(function (i) {
		if (this.value == "" || this.value == "First Name" || this.value == "Last Name" || this.value == "E-Mail Address" || this.value == "Email Address")
		{
			makeError = true;
		}
	});

	if (makeError) {
		alert("Please fill out the form properly before submitting.");
	} else {
		$("#email_form").submit();
	}
}

var photos = function(){
		var elements = [];
		var curPosition = 0;
		
		return {
			'getCurrent' : function() {
				return elements[curPosition];
			},
			'getPos' : function() {
				return curPosition;
			},
			'setCurrent' : function(elm) {
				/*for(var i=0;i<elements.length;i++){ 
				   if(elements[i]==elm)
						curPosition = i;
				}*/
				if(elm < elements.length) 
					curPosition = elm;
			},
			'clearElements' : function() {
				curPosition = 0;
				elements = [];
			},
			'addElement' : function(elm) {
				
				elements[elements.length] = elm;
			},		
			'nextElement' : function() {
				if(curPosition + 1 == elements.length) {
					var ind = 0;
				} else {
					var ind = curPosition + 1;
				}
				
				curPosition = ind;
				return elements[ind];
			},
			'prevElement' : function() {
				if(curPosition == 0) {
					var ind = elements.length - 1;
				} else {
					var ind = curPosition - 1;
				}
				curPosition = ind;
				return elements[ind];
			},
			'size' : function() {
				return elements.length;
			}		
		};	
}();

// totalShirts from index.phtml
function nextCallback(idx, state) {

	if (state != 'init') {
		
		$('.info_box .info').hide();
		$('.info_box .info:eq(' + idx + ')').show();
		
		var nextPage = parseInt($('.pg_thumb:visible').attr('pg')) + 1;
		var perPage = $('.navdots').attr('rel');
		
	
		//if pagination, check if should move to next page.
		if (state != 'init' && perPage && idx%perPage == 0 &&
			Math.ceil((idx + 1) / perPage) != nextPage - 1) {

			$('.pg_thumb').hide();
			$('.pg_thumb[pg=' + nextPage + ']').show();
			$('.navdots a').removeClass('selected');
			$('.navdots a[rel=' + nextPage + ']').addClass('selected');
		}
		
		
		if (idx == 0 && nextPage > Math.ceil(photos.size()/perPage)) {
			$('.pg_thumb[pg=1]').show();
			$('.navdots a[rel=1]').addClass('selected');
		}
	}
}

function nextPhoto() {
	var curPhoto = photos.getCurrent();
	var nextPhoto = photos.nextElement();
	
	nextCallback(photos.getPos(), 'next');
	curPhoto.hide();
	nextPhoto.fadeIn();
}

function scrollTo(idx, noFade) {
	var curPhoto = photos.getCurrent();
	curPhoto.hide();
	
	
	photos.setCurrent(idx);
	var nextPhoto = photos.getCurrent();
	nextCallback(photos.getPos(), 'next');	
	
	if(noFade) {
		nextPhoto.show();
	} else {
		nextPhoto.fadeIn();
	}
	
}

function prevPhoto() {
	var curPhoto = photos.getCurrent();
	var prevPhoto = photos.prevElement();
	
	nextCallback(photos.getPos(), 'prev');
	curPhoto.hide();
	prevPhoto.fadeIn();	
}

$(document).ready(function() {
	//loadPic();
	
	//$('#mycarousel li').css("display", "block");
	$('.info_box .info').hide();
	$('.info_box .info:first').show();
	
	$('.pg_thumb').hide();
	$('.pg_thumb[pg=1]').show();
	
	$('.navdots a').click(function() {
		$('.pg_thumb').hide();
		$('.pg_thumb[pg=' + ($('.navdots a').index(this) + 1) + ']').show();
		$('.navdots a').removeClass('selected');
		$(this).addClass('selected');
	});

	$('.navdots div:first a').addClass('selected');
	
	//jQuery('#mycarousel').jcarousel();
	
	
	$('#mycarousel li').hide();
	$('#mycarousel li:first').show();
	
	$('#mycarousel li').each(function() {
		photos.addElement($(this));
	});
	
    $('#shirt_rightarrow, .about_rightarrow').bind('click', function() {
	    nextPhoto();
		return false;
    });

    $('#shirt_leftarrow').bind('click', function() {
        prevPhoto();
        return false;
    });

	var hovering = false;
	if ($('#shirtmap area')) {
		$('#shirtmap area').hover(function(){
			//alert($('area').index(this));
			//carousel.scroll(jQuery.jcarousel.intval($('area').index(this)));
			if (!hovering) {
				hovering = true;
				if (parseInt($('area').index(this)) < photos.size()) {
					$('#mycarousel li').hide();
					//alert(parseInt($('area').index(this)) + ' : ' + photos.size())
					scrollTo($('area').index(this), true);
				}
			}
		
			
		}, function() {hovering = false;});

		$('#shirtmap area').click(function(){
			$('#shirt' + $('area').index(this)).click();
		});
	}
	
	
	if ($('.thumbnails')) {
		$('.thumbnails a').click(function() {
			
			//carousel.scroll(jQuery.jcarousel.intval();
			scrollTo($('.thumbnails a').index(this), false);
			//alert('done scolling');
			return false;
		});	
	}	
	/*$('#mycarousel').jcarousel({
		initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null,
		itemVisibleInCallback: {
		  onBeforeAnimation: mycarousel_nextCallback,
		  onAfterAnimation: function() {}
		},
		scroll: 1,
		visible: 1,
		wrap: "both"
	});*/
	

});





/*
function loadPic() {
	$("#shirt_frame").css("background-image", "url(" + shirts[currentPic][1][2] + ")");
	$("#info_box").html('<span class="boldyellow">' + shirts[currentPic][1][0] + '</span><br>' + shirts[currentPic][1][1] + '<br><a href="widgets/overlay?itemID=' + shirts[currentPic][0] + '&KeepThis=true&TB_iframe=true&height=600&width=450" class="thickbox">more info</a>');
	tb_init('a.thickbox, area.thickbox, input.thickbox');
}

function nextPic() {
	currentPic = (currentPic + 1) % totalShirts;
	loadPic();
}

function prevPic() {
	if (currentPic == 0) {
		currentPic = totalShirts - 1;
	} else {
		currentPic--;
	}
	loadPic();
}

function shirtHover(newShirt) {
	if (newShirt < totalShirts) {
		currentPic = newShirt;
		loadPic();
	}
}*/