var rotateLimit = 0;
var picsLength = 0;
var picsIndex = 0;
var fadeInReady = true;
var fadeOutReady = true;

function openWindow() {  popupWin = window.open('http://mail.mailordercentral.com/naturalwellness50/default.asp?item_url=http://shop.naturalwellnessonline.com/prodinfo.asp?number=N200&desc=UltraThistle™', '', 'scrollbars,resizable,width=550,height=450')
}
function openEAS() {  popupWin = window.open('http://www.naturalwellnessonline.com/popeas.html', '', 'scrollbars,resizable,width=600,height=450')
}
function openCourse() {  popupWin = window.open('http://www.naturalwellnessonline.com/popcourse.html', '', 'scrollbars,resizable,width=380,height=610')
}
function openPrivacy() {  popupWin = window.open('http://naturalwellnessonline.com/privacy.htm', '', 'scrollbars,resizable,width=600,height=610')
}
function openSatis() {  popupWin = window.open('https://shop.naturalwellnessonline.com/guarantee.asp', '', 'scrollbars,resizable,width=600,height=610')
}
function openLongTermBen() {  popupWin = window.open('https://shop.naturalwellnessonline.com/guarantee.asp', '', 'scrollbars,resizable,width=600,height=610')
}

function createProdImageRotator() {
	$("#picViews").append("Views: <a href='javascript:rotateImage(&quot;#productImages&quot;,&quot;prev&quot;);'>&laquo;</a>");
	$("#picViews").append("<a href='javascript:rotateImage(&quot;#productImages&quot;,&quot;next&quot;);'>&raquo;</a>");
}


function rotateImage(imgName, direction){
	if (fadeInReady && fadeOutReady) {
		fadeInReady = fadeOutReady = false;
		var tempIndex = picsIndex;
		if (direction == 'next') {
			picToFadeIn = ++picsIndex % picsLength;
			if (picsIndex == picsLength) { picsIndex = 0; }
		} else {
			if (picsIndex == 0) {
				picToFadeIn = picsIndex = picsLength-1;
			} else {
				picToFadeIn = --picsIndex % picsLength;
			}
		}
		$(imgName).children().eq(tempIndex).fadeOut("slow",function () {fadeOutReady = true; });
		$(imgName).children().eq(picToFadeIn).fadeIn("slow",function () {fadeInReady = true; });
	}
}

$(document).ready(function () {
	picsLength = $('div#productImages img').length;
	if (picsLength > 1) {
		createProdImageRotator();
	} else {
		fadeInReady = fadeOutReady = false;
	}
	
	$("a.EASpop").click(function() {
		openEAS();
		return false;
	});
	/*
	var hrefTemp = $("a.EASpop").attr("href") + "?height=300&width=300"
	$("a.EASpop").attr("href",hrefTemp);
	$("a.EASpop").addClass("thickbox");
	*/
	$("a.longTermBen").click(function() {
		openLongTermBen();
		return false;
	});
	/*
	$("form.pricing input:radio").click(function() {
		$("form.pricing input:radio").each(function() {
			if ($(this).attr("checked") == true) {
				$(this).parent().parent().addClass("selected");
			} else {
				$(this).parent().parent().removeClass("selected");
			}
		});
	});
	$("form.pricing input:radio").each(function() {
		if ($(this).attr("checked") == true) {
			$(this).parent().parent().addClass("selected");
		} else {
			$(this).parent().parent().removeClass("selected");
		}
	});
	*/
	$('#tabs').tabs();
});