// JavaScript Document

function simpleGalleryInit () {
	var mygallery=new simpleGallery({
		wrapperid: "simplegallery1", //ID of main gallery container,
		dimensions: [550, 305], //width/height of gallery in pixels. Should reflect dimensions of the images exactly
		imagearray: [
			["/v/vspfiles/templates/trv1/images/v1/spotlight/2010_06_icedteas.jpg", "/Iced-Loose-Tea-s/20.htm?searching=Y&sort=2&cat=20&show=90&page=1&brand=Tea Forte", "_self", "Cool off with Tea Forte Iced Tea products!"],
			["/v/vspfiles/templates/trv1/images/v1/spotlight/2010_03_mighty_leaf_tea.jpg", "/Mighty-Leaf-Tea-s/24.htm", "_self", "New on TeaRocket.com Mighty Leaf Tea!"],
			["/v/vspfiles/templates/trv1/images/v1/spotlight/2010_02_loose_tea.jpg", "/Loose-Leaf-Tea-s/119.htm", "_self", "Exquisite Premium Loose Leaf Teas on TeaRocket.com!"],
			["/v/vspfiles/templates/trv1/images/v1/spotlight/2010_02_accessories.jpg", "/tea-accessories-s/117.htm", "_self", "Tea Acessories on TeaRocket.com!"],
			["/v/vspfiles/templates/trv1/images/v1/spotlight/2010_02_teaforte.jpg", "/Tea-Forte-s/22.htm", "_self", "New on TeaRocket.com Tea Forte!"],
			["/v/vspfiles/templates/trv1/images/v1/spotlight/2010_02_twoleaves.jpg", "/Two-Leaves-and-a-Bud-s/110.htm", "_self", "New on TeaRocket.com Two Leaves and a Bud!"]
			
		],
		autoplay: [true, 6000, 6], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]
		persist: true, //remember last viewed slide and recall within same session?
		fadeduration: 800, //transition duration (milliseconds)
		oninit:function(){ //event that fires when gallery has initialized/ ready to run
			//Keyword "this": references current gallery instance (ie: try this.navigate("play/pause"))
		},
		onslide:function(curslide, i){ //event that fires after each slide is shown
			//Keyword "this": references current gallery instance
			//curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)
			//i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)
		}
	})	
}


function checkCartForFreeShip () {
	var myURL = document.URL;
	myURL = myURL.toLowerCase();
	if (myURL.search("shoppingcart.asp") > 0) {
			var priceString = $('#content_area font.pricecolor b:contains("$")').text();
			var priceString2 = 50.00 - priceString.substr(priceString.indexOf("$")+1,5);
			if (priceString2 > 0) {
				$('#content_area div').eq(0).after('<div class="InfoMessage">Free domestic shipping on orders over <strong>$50</strong>. Add <strong>$' + priceString2.toFixed(2) + '</strong> more to ship free!</div>');
			}
		//remove volusion shipping calculator
		//$('#content_area h3:contains("Shipping")').parent('b').parent('font').parent('td').parent('tr').parent('tbody').parent('table').addClass("foobarfoo").hide();
	} // end top if
	
	
	
}


function gNavSetup () {
	
	$('.gNavBtn').hover (
		function () {
			$(this).addClass('rollOver');
		}, 
		function () {
			$(this).removeClass('rollOver')
		}
	);
	
	$('.gNavBtn').click(function () {
		
		var index = $(".gNavBtn").index(this);
		
		//set the width of the colums based on how many they're are
		var megaMenuListWrapperWidth = 965 / $('.megaMenuContent').eq(index).find('.megaMenuListWrapper').length - 20;
		$('.megaMenuContent').eq(index).find('.megaMenuListWrapper').width(megaMenuListWrapperWidth);
		
		
		if (!$("#megaMenuWapper").hasClass("megaOpen")) {
			//container IS CLOSED
			//set relative content
			$("#megaMenuWapper .megaMenuContent").hide().eq(index).show();
			//open container
			$("#megaMenuWapper").slideDown();
			
			//set this link active
			$(this).addClass("active");
			//set arrow
			$(this).find('.gNavBtnText').addClass("active");
			//set all others inactive
			$(".gNavBtn").not(this).removeClass("active");
			
			
			//set container open now
			$("#megaMenuWapper").addClass("megaOpen");
			
		} else if ($("#megaMenuWapper").hasClass("megaOpen") && $(this).hasClass("active")) {
			//container IS OPEN and link is ACTIVE
			//set this link inactive
			$(this).removeClass("active");
			//set arrow
			$(this).find('.gNavBtnText').removeClass("active");
			//set all others inactive
			$(".gNavBtn").not(this).removeClass("active");
			$(".gNavBtn").not(this).find('.gNavBtnText').removeClass("active");
			
			//set relative content
			$("#megaMenuWapper .megaMenuContent").hide().eq(index).show();
			//close container
			$("#megaMenuWapper").slideUp();
			//set conatiner CLOSED
			$("#megaMenuWapper").removeClass("megaOpen");
				
		} else if ($("#megaMenuWapper").hasClass("megaOpen") && !$(this).hasClass("active")) {
			//container IS OPEN and link is INACTIVE
			//set this link inactive
			$(this).addClass("active");
			//set arrow
			$(this).find('.gNavBtnText').addClass("active");
			//set all others inactive
			$(".gNavBtn").not(this).removeClass("active");
			$(".gNavBtn").not(this).find('.gNavBtnText').removeClass("active");
			
			
			//set relative content
			$("#megaMenuWapper .megaMenuContent").hide().eq(index).show();
		}
			
			
			
			

	});

	
}



function removeVolusionJunk () {
	
	$("b:contains('New Products')").parent("font").parent("td").parent("tr").parent("tbody").hide();
	
}

function rollMe () {
	
	$(".rollMe").hover(over, out);
		
	function over (event) {
		$(this).attr('src', $(this).attr('src').replace('_a', '_b'));
	} 
	
	function out (event) {
		$(this).attr('src', $(this).attr('src').replace('_b', '_a'));
	}
	
	
}


function myAccountController () {
	
	$(".myAccountBtn").click(function () {
		$("#myAccountWrapper").slideToggle("fast", function() {
			$("body").toggleClass("moveBodyBg");
		});

	  
    });

}


function cartSummary () {
	var miniCartText = $(".cartsummary_full").text();
	if (miniCartText) {
		var miniCartTextArray = miniCartText.split(" ");
		var myItems = miniCartTextArray[4];
		var myTotalArray1 = miniCartText.split("$");
		var myTotalArray = myTotalArray1[1].split(")");
		var myTotal = myTotalArray[0];
		
		var myText = "Shopping Cart (" + myItems + ") $" + myTotal;
		
		$(".myMiniCart").text(myText);
	
	}
	
	
	
	//alert(myTotalArray[1]);
}