﻿(function($){
var msie6 = $.browser.msie && (parseInt($.browser.version) < 7);
var msie7 = $.browser.msie && (parseInt($.browser.version) < 8);
var ytplayer;
var OPT_ID = 0;
var OPT_TITLE = 1;
var OPT_VOTES = 2;
var pid = 0;
var votedID;

$(document).ready(function(){	
	init();
});

function init(){
	
	if ($("#page.home").length) {
		$("#banner img").attr("src","http://www.royalpetclub.com/00189-1/design/images/categories/bannerFeb.jpg");
		$("#page.home #banner .caption h2").hide();
		$("#page.home #banner .caption p").html($("#page.home #banner .caption p").html().replace("Shampoo and Conditioner*",""));	
		$("#page.home #banner .caption p a").attr("href","http://www.royalpetclub.com/Italian-Olive-Oil-Shampoo-Two-Pack.html").attr("title","Shop Now").find("span").text("Shop Now");
		var $emailsignup = $('<div id="emailsignup"></div>');
		$emailsignup.html('<form action="http://RoyalPetClub.us1.list-manage.com/subscribe/post?u=3e6ac8a1348febcc911d087f1&amp;id=a0ad9bce62" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank"><label for="mce-EMAIL">Enter Email Below to Get <span class="red">Members Only Deals</span>:</label><input type="text" value="" maxlength="80" size="26" name="EMAIL" id="mce-EMAIL" class="txt" /><input type="submit" value="Subscribe" name="subscribe" class="submit" /></form>');
		$("#page.home #banner").append($emailsignup);
		
	/*
		$("#page.home #banner .caption h2").text("Organic Coconut and Vanilla");
		$("#page.home #banner .caption p").html($("#page.home #banner .caption p").html().replace("Shampoo and Conditioner*","Shampoo and Conditioner Bundle*"));	
		$("#page.home #banner .caption p a").attr("href","javascript:addMe('364');");
	*/
	/*
		$('#banner').empty().append('<iframe id="banneriframe" scrolling="no" frameborder="0" width="960" height="600" />').prev().remove();
		$('#banneriframe').attr('src', 'http://www.royalpetclub.com/00189-1/design/html/custom.banner.html'); 
	*/	
		$('#poll-wrapper').empty().append('<iframe id="polliframe" scrolling="no" frameborder="0" width="270" height="270" />').prev().remove();
		$('#polliframe').attr('src', 'http://www.royalpetclub.com/00189-1/design/html/custom.poll.html'); 
	
		$("#banners div.petguide a").attr("href","mailto:Dara@royalpetclub.com").attr("title","Click here to email Dara");
	}
		
	$("#footer .partners ul li:last").removeClass("np");
	$("#footer .partners ul").append('<li class="fl np"><a rel="_blank" title="Animal Aid" href="http://www.animalaidconcert.com/" class="animalaid">Animal Aid</a></li>')
	$("#footer .separator").click(function(){
		window.location.href='/animal-aid';
	});
	
	/*
	if ($("#page.home").length) {
		$("#page.home #banner .caption h2").text("Chamomile and Shea Butter");
		$("#page.home #banner .caption p").html($("#page.home #banner .caption p").html().replace("Shampoo and Conditioner*","Shampoo and Conditioner Bundle*"));	
		$("#page.home #banner .caption p a").attr("href","javascript:addMe('297');");	
	
		$('#poll-wrapper').empty().append('<iframe id="polliframe" scrolling="no" frameborder="0" width="270" height="180" />').prev().remove();
		$('#polliframe').attr('src', 'http://www.royalpetclub.com/00189-1/design/html/custom.poll.html'); 
	
		$("#banners div.petguide a").attr("href","mailto:Dara@royalpetclub.com").attr("title","Click here to email Dara");
	}
	*/
	
	if ($(".salePrice").length) {
		replaceSalePrice();
	}

	$("p:empty").remove();

	if ($("#tblProducts").length) {
		$('#tblProducts').dataTable({
			"oLanguage": {
				"sInfo": "Showing _TOTAL_ products",
				"sSearch": "<label>Filter products</label>"
			},
			"sScrollY": "400px",
			"bPaginate": false,
			"bAutoWidth": false,
			"aoColumns": [{"sWidth":"590px"},{"sWidth":"100px"},{"sWidth":"200px"}],
			"aoColumns": [ 
				{"bSearchable": true, "bVisible":true},
				{"bSearchable": false, "bSortable":true},
				{"bSearchable": false, "bSortable":false}
			],
			"aaSorting": [[0, "asc" ]]
		});
	}
		
	if ($("#existingCustomer,#customerLogin,#clientAccount,#newCustomer,#billAddress,#shipAddress,#paymentInfo").length) {
		$("#existingCustomer,#customerLogin,#clientAccount,#newCustomer,#billAddress,#shipAddress,#paymentInfo").find("input:text,input:password,textarea").each(function() {	
			$(this).addClass("txt");
		});
	}
	
	if ($("#divForm").length) {
		$("#divForm").find("input:text,textarea,select").each(function() {	
			$(this).hideLabels();
		});
	}
	
	if ($("#cartCoupon").length) {
		$("#cartCoupon").html($("#cartCoupon").html().replace("Coupon Code:",""));
		$("#cartCoupon").prepend('<div class="form-label">Coupon Code:</div>');
		$("#cartCoupon").find(".cartCouponInput").addClass("form-field");
	}
	
	if ($("#productReviews,#divCustomForm,#allproducts,#passwordRemindCustomer").length) {
		$("#productReviews,#divCustomForm,#allproducts,#passwordRemindCustomer").find("input:text,textarea").each(function() {	
			$(this).addClass("txt").hideLabels();
		});
	}
	
	if ($("#cartCoupon").length) {
		$("#cartCoupon").find("input:text,textarea").each(function() {	
			$(this).addClass("txt");
		});
	}
	
	$('a[href^="mailto"]').each(function() {	
		$(this).attr("href",$(this).attr("href").replace("[at]","@"));
		$(this).html($(this).html().replace("[at]","@"));
	});
	
	$('a[rel="_blank"],a.-blank').click(function(e) {
		this.target = "_blank";
	});
	
	if (!$("#content .cart_home").length) {
		if ($("#productGrid").length) {
			$("#productGrid h2").html($("#productGrid h2").html().replace(/ &gt;/g,"<strong>&nbsp;/&nbsp;</strong>")).find("a:last").addClass("last");
			$("#content .frame").prepend($("<div class='breadcrumb'></div>").append($("#productGrid h2")));
			$(".separator:first").remove();
		}		
		if ($("#categoryGrid").length) {			
			switch (location.pathname.toLowerCase()) {
				case "/wellness/supplements/":
					$("#content .frame").prepend($("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of supplements</span><span class='captionbg'></span><div id='banner' class='supplements'><div class='caption'><h2>60-Count Multi-Vitamin Chewable Treats for Dogs</h2><p>(4 pack)</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Supplements.jpg' alt='' /></div></a>"));showOurProductsMenu();
					break;
				case "/grooming/":
					$("#content .frame").prepend($("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of grooming products</span><span class='captionbg'></span><div id='banner' class='supplements'><div class='caption'><h2>From our home in Italy to yours.</h2><p>Enjoy the world&rsquo;s most luxurious pet grooming products</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Grooming.jpg' alt='' /></div></a>"));showOurProductsMenu();
					break;
				case "/wellness/":
					$("#content .frame").prepend($("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of supplements</span><span class='captionbg'></span><div id='banner' class='supplements'><div class='caption'><h2>Tear Stain Removal</h2><p>90 Pads</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Wellness.jpg' alt='' /></div></a>"));showOurProductsMenu();
					break;
				case "/common-conditions/":
					$("#content .frame").prepend($("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of common conditions products</span><span class='captionbg'></span><div id='banner' class='conditions'><div class='caption'><h2>Ear Wash</h2><p>For Dogs and Cats</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Conditions.jpg' alt='' /></div></a>"));showOurProductsMenu();
					break;				
			}			
			$("#categoryGrid h2").html($("#categoryGrid h2").html().replace(/ &gt;/g,"<strong>&nbsp;/&nbsp;</strong>")).find("a:last").addClass("last");
			$("#content .frame").prepend($("<div class='breadcrumb'></div>").append($("#categoryGrid h2")));
			$(".separator:first").remove();		
			
			if (location.pathname.toLowerCase() != "/wellness/supplements/") {
				showOurProductsMenu();	
			}
		}
		else
		if ($("#productGrid").length) {			
			switch (location.pathname.toLowerCase()) {
				case "/grooming/shampoos/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of shampoos</span><span class='captionbg'></span><div id='banner' class='shampoos'><div class='caption'><h2>Organic Chamomile and Shea Butter</h2><p>Shampoo</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Shampoos.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;
				case "/grooming/conditioners/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of conditioners</span><span class='captionbg'></span><div id='banner' class='conditioners'><div class='caption'><h2>Organic Honey and Oatmeal</h2><p>Conditioner</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Conditioners.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;					
				case "/grooming/bath-spritzes/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of bath spritzes</span><span class='captionbg'></span><div id='banner' class='spritz'><div class='caption'><h2>Organic Italian Milk and Vanilla</h2><p>Spritz</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Spritzes.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;
				case "/grooming/bundles/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of bundles</span><span class='captionbg'></span><div id='banner' class='bundles'><div class='caption dno'><h2>Organic Chamomile and Shea Butter</h2><p>Shampoo and Conditioner Bundle</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Bundles.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;
				case "/grooming/wipes/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of wipes</span><span class='captionbg'></span><div id='banner' class='wipes'><div class='caption'><h2>Organic Lavender and Cashmere</h2><p>Wipes</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Wipes.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;
				case "/grooming/groomers-only/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of groomers only products</span><span class='captionbg'></span><div id='banner' class='groomers'><div class='caption'><h2>Organic Italian Virgin Olive Oil</h2><p>Shampoo</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Groomers.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;
				case "/special-occasions-and-gifts/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of special occasions and gifts products</span><span class='captionbg'></span><div id='banner' class='gifts'><div class='caption'><h2>Organic Coconut and Vanilla</h2><p>Shampoo and Conditioner Bundle</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Gifts.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;
				case "/what-is-new/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of new products</span><span class='captionbg'></span><div id='banner' class='bundles'><div class='caption'><h2>Organic Chamomile and Shea Butter</h2><p>Instant Dry Bath Powder</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Whatisnew.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;
				case "/food/":
					$("<a href='#content-middle' id='autoscroll'><span class='captiontxt'>Scroll down or click on the image to see our list of new products</span><span class='captionbg'></span><div id='banner' class='food'><div class='caption'><h2>Gourmet, All Natural, Grass Fed Black Angus Beef Treats</h2><p>Only the best!</p></div><img src='http://www.royalpetclub.com/00189-1/design/images/categories/Food.jpg' alt='' /></div></a>").insertAfter($("#content .breadcrumb"));showOurProductsMenu();
					break;
			}
			
			if (location.pathname.toLowerCase() != "/grooming/shampoos/" &&
				location.pathname.toLowerCase() != "/grooming/conditioners/" &&
				location.pathname.toLowerCase() != "/grooming/bath-spritzes/" &&
				location.pathname.toLowerCase() != "/grooming/bundles/" &&
				location.pathname.toLowerCase() != "/grooming/wipes/" &&
				location.pathname.toLowerCase() != "/grooming/groomers-only/") {
				showOurProductsMenu();	
			}	
		}
		else {
			if (location.pathname.toLowerCase() == "/why-royal-pet-club.html" ||
				location.pathname.toLowerCase() == "/our-heritage.html" ||
				location.pathname.toLowerCase() == "/our-products.html" ||
				location.pathname.toLowerCase() == "/our-charities.html" ||
				location.pathname.toLowerCase() == "/join-our-membership-club.html" ||
				location.pathname.toLowerCase() == "/our-press.html" ||
				location.pathname.toLowerCase() == "/testimonials.html" ||
				location.pathname.toLowerCase() == "/contact-us.html") {
				showOurStoryMenu();	
			}
		}
	}
	
	if ($("#banner").length && $("#page").hasClass("home")) {
		$("#ourproductsmenu").addClass("bottom").insertAfter($("#banner"));
	}
	$('#nav a[href$="our-products.html"]').click(function(e){
		e.preventDefault();
		if ($("#ourproductsmenu").css("display")=="none" || $("#ourproductsmenu").hasClass("bottom")) {
			showOurProductsMenu();
		}
		else {
			hideOurProductsMenu();
		}
	});	
	
	$('#nav a[href$="our-story.html"]').click(function(e){
		e.preventDefault();
		if ($("#ourstorymenu").css("display")=="none") {
			showOurStoryMenu();
		}
		else {
			hideOurStoryMenu();
		}
	});
		
	if ($(".colorbox").length) {		
		$(".colorbox").colorbox({innerWidth:"800px", innerHeight:"600px", iframe:true});
	}
		
	$('#topNav ul').lavaLamp({
		fx: 'easeOutExpo',
		speed: 700,
		returnHome:true,
		homeLeft: -100,
		homeTop: -300,
		homeWidth:940,
		homeHeight:30
	});
	
	pid = $("#poll-container input:hidden").val();
    
	$("#poll").submit(formProcess).find("a").click(function(e){
		e.preventDefault();
		$("#poll").submit();
	});
	

	if ($("#poll-results").length > 0 ) {
		animateResults();
	}

	if ($.cookie('vote_id'+pid)) {
		$("#poll-container").empty();
		votedID = $.cookie('vote_id'+pid);
		$.getJSON("http://www.royalpetclub.com/00189-1/lib/poll/poll.php?vote=none&pid="+pid,loadResults);
	}
	if (!$("#content .frame").hasClass("search_results")) {
		$(".breadcrumb").html("<div class='header'>Categories</div><div class='bcwrapper'>"+$( ".breadcrumb" ).html()+"</div>");
		$(".breadcrumb").accordion({ header: '.header', collapsible: true, animated: true}).find(".header").click().blur();
		$(".breadcrumb").accordion('option', 'animated', true);
	}
	
	$('#footer .directory a[href$="Our-Story.html"]').click(function(e){
		e.preventDefault();
		$.scrollTo("#topNav",600,{
			onAfter:function(){$('#nav a[href$="our-story.html"]').click();}
		});
	});
	
	if ($('#autoscroll').length) {
		$('#autoscroll').click(function(e){			
			e.preventDefault();
			$.scrollTo("#content-middle",300);
		});
	}
	
	$("a[href^='http://blog.royalpetclub.com']").attr("target","_blank");
	$("#banner img").attr("alt","Natural Dog Shampoo");
	$("#customerLogin input[type='checkbox']").addClass("form-checkbox");

	if ($(".directory").length) {
		$(".directory .fl:last ul").append($('<li><h3><a title="Return Policy" href="http://www.royalpetclub.com/return-policy.html">RETURN POLICY</a></h3></li>'));
	}
}

function showOurProductsMenu() {
	if ($("#ourstorymenu").css("display")!="none") {
		hideOurStoryMenu(function(){
			if ($("#banner").length && $("#page").hasClass("home") && $("#ourproductsmenu").hasClass("bottom")) {
				$("#ourproductsmenu").slideUp( 600, 'easeInBack', function() {
					$("#ourproductsmenu").removeClass("bottom").insertAfter($("#nav")).slideDown( 600, 'easeOutBack');
				});
			}
			else {
				$("#ourproductsmenu").slideDown( 600, 'easeOutBack');
			}
		});
	}
	else {
		if ($("#banner").length && $("#ourproductsmenu").hasClass("bottom")) {
			$("#ourproductsmenu").slideUp( 600, 'easeInBack', function() {
				$("#ourproductsmenu").removeClass("bottom").insertAfter($("#nav")).slideDown( 600, 'easeOutBack');				
			});
		}
		else {
			$("#ourproductsmenu").slideDown( 600, 'easeOutBack');
		}
	}
}

function hideOurProductsMenu(callback) {
	if ($("#banner").length && $("#page").hasClass("home") && !$("#ourproductsmenu").hasClass("bottom")) {
		$("#ourproductsmenu").slideUp( 600, 'easeInBack', function() {
			$("#ourproductsmenu").addClass("bottom").insertAfter($("#banner")).slideDown( 600, 'easeOutBack', function(){
				if (isFunction(callback)) {
					callback();
				}
			});
		})
	}
	else {
		$("#ourproductsmenu").slideUp( 600, 'easeInBack', function() {
			if (isFunction(callback)) {
				callback();
			}
		});
	}
}

function showOurStoryMenu() {
	if ($("#ourproductsmenu").css("display")!="none" && !$("#ourproductsmenu").hasClass("bottom")) {		
		hideOurProductsMenu(function() {
			$("#ourstorymenu").slideDown( 600, 'easeOutBack');
		});
	}
	else {
		$("#ourstorymenu").slideDown( 600, 'easeOutBack');
	}
}

function hideOurStoryMenu(callback) {
	$("#ourstorymenu").slideUp( 600, 'easeInBack', function() {
		if (isFunction(callback)) {
			callback();
		}
	});
}

function isFunction(possibleFunction) {
  return (typeof(possibleFunction) == typeof(Function));
}


function loadVideo(id){
	$('#divLastVideo').empty().youTubeEmbed({
		video			: 'http://www.youtube.com/watch?v='+id,
		width			: 853,
		height			: 510
	});
	
	setTimeout(function(){$('.controlDiv.play').eq(0).click();},1000);
}

function stopVideo(){
	$('.controlDiv.pause').eq(0).click();
}

$.fn.hideLabels = function() {
	var input = $(this);
	var label;
	if (input.parent().hasClass("form-field")) {
		label = input.parent().parent().find(".form-label,.form-label-required");		
	}
	else {
		label = input.parent().find("label");
	}
	label.html(label.html().replace(/^\s*|\s*$/g,"").replace(/&nbsp;/g,"")).hide();
	if (input.is("input") && input.attr("type") == "password") {
		input.val("");
	}
	else {
		if (!input.is("select")) {
			if (input.val() == "") {
				input.val(label.html());
			}
			input.focus(function(){
				if (input.val() == label.html()) input.val("");
			}).blur(function(){
				if (input.val() == "") input.val(label.html());
			});
		}
		else {
			input.prepend("<option value=''>"+label.html()+"</option>").get(0).selectedIndex = 0;
		}
	}
	return input;
}

function formProcess(event){
	event.preventDefault();
  
	if ($("input[@name='poll']:checked").length) {

		var id = $("input[@name='poll']:checked").attr("value");
		id = id.replace("opt",'');

		$("#poll-container").fadeOut("slow",function(){
			$(this).empty();

			votedID = id;
			$.getJSON("http://www.royalpetclub.com/00189-1/lib/poll/poll.php?vote="+id+"&pid="+pid,loadResults);

			$.cookie('vote_id'+pid, id, {expires: 30});
		});
	}
}

function animateResults(){
  $("#poll-results div").each(function(){
	  var percentage = $(this).next().text();
	  $(this).css({width: "0%"}).animate({
				width: percentage}, 'slow');
  });
}

function loadResults(data) {
  var total_votes = 0;
  var percent;
  
  for (id in data) {
	total_votes = total_votes+parseInt(data[id][OPT_VOTES]);
  }
  
  var results_html = "<div id='poll-results'>\n<dl class='graph'>\n";
  for (id in data) {
	percent = Math.round((parseInt(data[id][OPT_VOTES])/parseInt(total_votes))*100);
	if (data[id][OPT_ID] !== votedID) {
	  results_html = results_html+"<dt class='bar-title'>"+data[id][OPT_TITLE]+"</dt><dd class='bar-container'><div id='bar"+data[id][OPT_ID]+"'style='width:0%;'>&nbsp;</div><strong>"+percent+"%</strong></dd>\n";
	} else {
	  results_html = results_html+"<dt class='bar-title'>"+data[id][OPT_TITLE]+"</dt><dd class='bar-container'><div id='bar"+data[id][OPT_ID]+"'style='width:0%;background-color:#183D6A;'>&nbsp;</div><strong>"+percent+"%</strong></dd>\n";
	}
  }
  
  results_html = results_html+"</dl><p>Total Votes: "+total_votes+"</p></div>\n";
  
  $("#poll-container").append(results_html).fadeIn("slow",function(){
	animateResults();});
}

function replaceSalePrice(){
	$(".salePrice").parent().parent().find("#priceLabel").hide();
	$("#productDetail #addToCartButton").css("padding","50px 0 0 20px");

/*
	$(".salePrice").each(function(){
		var auxhtml = $(this).parent().html().replace("Retail Price:","").replace("<br>Our Price:","");
		$(this).parent().html(auxhtml);		
	});
*/
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

function encode64(input) {
	input = escape(input);
	var keyStr = "0123456789";
	var output = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;

	do {
		chr1 = input.charCodeAt(i++);
		chr2 = input.charCodeAt(i++);
		chr3 = input.charCodeAt(i++);

		enc1 = chr1 >> 2;
		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		enc4 = chr3 & 63;

		if (isNaN(chr2)) {
		   enc3 = enc4 = 64;
		} else if (isNaN(chr3)) {
		   enc4 = 64;
		}

		output = output +
		keyStr.charAt(enc1) +
		keyStr.charAt(enc2) +
		keyStr.charAt(enc3) +
		keyStr.charAt(enc4);
		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";
	} while (i < input.length);

	return output;
}

function addGAItems() {
	$("#cartItems tr:not(:first)").each(function(){
		var $this = $(this);
		var $tds = $this.find("td");
		var quantity = parseInt($tds.eq(0).text())+"";
		var name = $.trim($tds.eq(1).text());
		var price = parseFloat($tds.eq(2).text().replace("$",""))+"";
		
		_gaq.push(['_addItem',
			order,           // order ID - required
			encode64(name), // SKU/code - required
			name,        // product name
			'',   // category or variation
			price,  // unit price - required
			'1'     // quantity - required
		]);
	});
}
}(jQuery));

