//alert('javascript included.');
var openSub = null;
var selectedList;
var selectedItem;
var sc;
var lc;
function showSub(o)
{
	$(o).blur();
	thisShell = $(o).next('.subNavShell');
	if($(thisShell).hasClass('openSub') == true){
		$(thisShell).fadeOut(250).removeClass('openSub');
	} else {
		$('.openSub').fadeOut(250).removeClass('openSub');
		$(thisShell).css({'opacity': 0}).show().fadeTo(250, .8).addClass('openSub');
		
	}
}
function showList(listType, ob){
	$('.shopChoice').removeClass('shopChoiceOn');
	sc = $(ob).attr('id');
	$(ob).addClass('shopChoiceOn');
	selectedList = $(ob).attr('id');
	$('.productList').not($('.'+listType)).fadeOut(250, function(){
		$('.'+listType).fadeIn(250);
	});
}
function addScroll(){
	$('.scroller').css('height', $(window).height()+100);
}
function initLines(){
	$('.topRow').removeClass('topRow');
	$('.rightSide').removeClass('rightSide');
	//$('.prodGrid').addClass('bottomLeft');
	$('.prodGrid:visible:last').addClass('rightSide');
	$('.prodGrid:visible').each(function(i, e){
		parseInt(i+1)%3 == 0 ? $(e).addClass('rightSide') : void(0);
		if(i == 1 || i == 2 || i == 0){
			$(e).addClass('topRow');
		}
	});
}
function showTea(tea, choice){
	$('.productList a').not($(choice)).removeClass('choiceOn');
	lc = $(choice).attr('id');
	$(choice).addClass('choiceOn');
	$('.prodGrid').not($('.' + tea)).hide();
	$('.' + tea).children().hide();
	$('.' + tea).show();
	initLines();
	$('.' + tea).children().fadeIn(1000);
}
function changeGalleryMain(imRef){
	$('.loaderGif').show();
	$('.galleryMain').fadeOut(250, function(){
		$('.galleryMain').attr('src', imRef);
	});
}
function showCommerce(qstr, isProd){
	var storeURL;
	if(isProd == true){
		storeURL = 'http://www.mygreentea.com/Merchant2/merchant.mv?Screen=PROD&Store_Code=mygreentea&Product_Code=' + qstr;
	} else {
		storeURL = 'http://www.mygreentea.com/Merchant2/merchant.mv?Screen=SFNT&Store_Code=mygreentea';
	}
	$('.commerceBlocker').show().css('opacity', 0).fadeTo(500, .7, function(){
		$('.commerceFrame').attr('src',  storeURL);
		$('.commerceContainer').show();
	});
}
$(function(){
	$('.topNavShell').click(function(e){
		e.stopPropagation();
	})
	$('body').click(function(x){
		$('.openSub').fadeOut(250).removeClass('openSub');
	});
	addScroll();
	$(window).resize(function(){
		addScroll();
	})
});
