//	cameron isiminger
// reference for jQuery Intellisense for VS
/// <reference path="jquery-1.3.2.js" />

//Jquery Shuffle Plugin
(function($) {
	$.fn.shuffle = function() {
		return this.each(function() {
			var items = $(this).children();
			return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
		});
	}

	$.shuffle = function(arr) {
		for (
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
		return arr;
	}
})(jQuery);

var intVal;
var winking;
function lazarusEffect(type) {
/*	if (type == "lazarusEffect") {
		$('#lazarusBanner').removeClass('hidden');
		$('#cartDiv').addClass('hidden');
	}
	else {
		$('#lazarusBanner').addClass('hidden');
		$('#cartDiv').removeClass('hidden');
	}*/
}

$(function() {
    //detect IOS device
    var isiPad = navigator.userAgent.match(/iPad/i) != null;
    var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
    if (isiPhone) {
        $("#iphoneMsg").show();
    }
    else if (isiPad) {
        $("#ipadMsg").show();
    }
	LoadEvents();
	$("#grid").empty();
	//lets populate grid on detected hash in url
	var hashes = window.location.hash.split('_');
	var urlHash = hashes.length == 2 ? hashes[0] : window.location.hash;
	var type = urlHash.replace("#", "");
	if (type == "")
		type = window.location.pathname.split('/')[2];

	//lazarusEffect(type);
	switch (type) {
		case "shopred":
			PopulateGrid(type);
			$('#navigation h2').text('BUY (RED) SAVE LIVES');
			break;
		case "redwire":
			PopulateGrid(type);
			$('#navigation h2').text('GREAT MUSIC SAVES LIVES');
			break;
		case "rednights":
			PopulateGrid(type);
			$('#navigation h2').text('GREAT CONCERTS SAVE LIVES');
			break;
		case "aboutred":
			PopulateGrid(type);
			$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
			break;
		case "impact":
			PopulateGrid(type);
			$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
			break;
		case "news":
			PopulateGrid(type);
			$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
			break;
		case "lazarusEffect":
			PopulateGrid(type);
			$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
			break;
		case "home":
			PopulateGrid(type);
			$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
			break;
		case "red2015":
			PopulateGrid(type);
			$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
			break;
		default:
		    PopulateGrid("home");
			$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
			break;
	}

	if (hashes.length == 2)
		DisplayBox(hashes[1]);

	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('h4');
	Cufon.replace('.button');
	Cufon.replace('.rollover');
	Cufon.replace('.popupBtn');
	Cufon.replace('.redwireBtn');
	Cufon.replace('.cartTotal');
	Cufon.replace('p.download');
	Cufon.replace('.mainButton');
	Cufon.replace('.viewCartBottom');
	Cufon.replace('.cartTotals');
	Cufon.replace('.checkoutTip');
	Cufon.replace('.loginCreate');
	Cufon.replace('.dlText');
	Cufon.replace('.shopRed dd');


	$(".joinBtn").click(function(e) {
		e.preventDefault();
		pageTracker._trackPageview('/email_signup/index');
		$("#joinred").fadeIn(250);
	});

	$(".closeBtnJoin").click(function(e) {
		e.preventDefault();
		$("#joinred").hide();
	});

	$("#backTo").click(function(e) {
		$(".modalVideo").fadeOut(250);
		$(".modalPopup").fadeTo(250, 1, function() {
			$(".modalPopup").fadeIn(250);
		})
	})

	$("#btnShop").click(function(e) {
		e.preventDefault();
		RemovePopup();
		RedirectToGrid("shopred");
		$('#navigation h2').text('BUY (RED) SAVE LIVES');
		Cufon.replace('h2');
	});

	$("#btnRedWire").click(function(e) {
		e.preventDefault();
		RemovePopup();
		RedirectToGrid("redwire");
		$('#navigation h2').text('GREAT MUSIC SAVES LIVES');
		Cufon.replace('h2');
	});

	$("#btnRedNights").click(function(e) {
		e.preventDefault();
		RemovePopup();
		RedirectToGrid("rednights");
		$('#navigation h2').text('GREAT CONCERTS SAVE LIVES');
		Cufon.replace('h2');
	});

	$("#btnNews,#readAboutRed").click(function(e) {
		e.preventDefault();
		RemovePopup();
		RedirectToGrid("news");
		$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
		Cufon.replace('h2');
	});

	$("#btnImpact").click(function(e) {
		e.preventDefault();
		RemovePopup();
		RedirectToGrid("impact");
		$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
		Cufon.replace('h2');
	});

	$(".btnHome").click(function(e) {
		e.preventDefault();
		RemovePopup();
		RedirectToGrid("home");
		$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
		Cufon.replace('h2');
	});

	$("#btnLazarus").click(function(e) {
		e.preventDefault();
		RemovePopup();
		RedirectToGrid("lazarusEffect");
		$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
		Cufon.replace('h2');
	});
	
	$("#btn2015Red").click(function(e) {
		e.preventDefault();
		RemovePopup();
		RedirectToGrid("red2015");
		$('#navigation h2').text('DESIGNED TO HELP ELIMINATE AIDS');
		Cufon.replace('h2');
	});

	$("#signupinputs input").focus(function() {
		if (this.defaultValue == this.value)
			this.value = "";
	});
	$("#signupinputs input").blur(function() {
		if (this.value == "")
			this.value = this.defaultValue;
	});

	$(".TwoColumn input").focus(function() {
		if (this.defaultValue == this.value)
			this.value = "";
	});
	$(".TwoColumn input").blur(function() {
		if (this.value == "")
			this.value = this.defaultValue;
	});

	//	$(".shopBtn").hover(function() {
	//		$(".shopHover").html("PRODUCTS");
	//		Cufon.replace('.shopHover');
	//	}, function() {
	//		$(".shopHover").html("&nbsp;");
	//	});

	$(".wireBtn").hover(function() {
		$(".wireHover").html("DOWNLOAD&nbsp;MUSIC");
		Cufon.replace('.wireHover');
	}, function() {
		$(".wireHover").html("&nbsp;");
	});

	$(".nightsBtn").hover(function() {
		$(".nightsHover").html("SEE&nbsp;CONCERTS");
		Cufon.replace('.nightsHover');
	}, function() {
		$(".nightsHover").html("&nbsp;");
	});

	//	$(".aboutBtn").hover(function() {
	//		$(".aboutHover").html("LEARN&nbsp;MORE");
	//		Cufon.replace('.aboutHover');
	//	}, function() {
	//		$(".aboutHover").html("&nbsp;");
	//	});

	$(".impactBtn").hover(function() {
		$(".impactHover").html("RESULTS&nbsp;IN&nbsp;AFRICA");
		Cufon.replace('.impactHover');
	}, function() {
		$(".impactHover").html("&nbsp;");
	});

	$('#Flowered').click(function(e) {
		pageTracker._trackEvent('Flowered', 'footer', 'link');
	});

	$('#Blog').click(function(e) {
		pageTracker._trackEvent('Blog', 'Blog link', 'home top right');
	});
	var country = get_cookie("country");
	if (get_cookie("country") == null) {
		$.post("/Checkout/DetectCountry/", {}, function() {
			var country = get_cookie("country");
			if (country == "us" || country == "gb" || country == "ca") {
				$("#cartColumn").show();
			}
		}, "text");
	}
	else if (country == "us" || country == "gb" || country == "ca") {
		$("#cartColumn").show();
	}
});
function LoadEvents(type) {

	Cufon.replace('.rollover');

	$(".colDiv").hover(function() {
		$(this).children(".rollover").fadeIn(250);
	}, function() {
		$(this).children(".rollover").fadeOut(250);
	});

	$(".colDivAbout").hover(function() {
		$(this).children(".rollover").fadeIn(250);
	}, function() {
		$(this).children(".rollover").fadeOut(250);
	});
	
	$(".colDiv").click(function(e) {
		e.preventDefault();
		var itemID = this.id.split('_')[1]
		DisplayBox(itemID);
	});

	$(".featuredImg").hover(function() {
		$(this).children(".rollover").fadeIn(250);
	}, function() {
		$(this).children(".rollover").fadeOut(250);
	});

	$(".featuredImg").click(function(e) {
		e.preventDefault();
		var itemID = this.id.split('_')[1];
		DisplayBox(itemID);
	});
}

function get_cookie(cookie_name) {
	var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

	if (results)
		return (unescape(results[2]));
	else
		return null;
}
function DisplayBox(itemID) {		
	$.ajax({
		type: "POST",
		url: path + "grid",
		data: ({ id: itemID }),
		success: function(html) {
			$("#gridPop").fadeOut(250);
			$('#popup').empty();
			$('#popup').attr('class', 'modalPopup'); ;
			$('#popup').html(html);

			Cufon.replace('h2');
			Cufon.replace('h3');
			Cufon.replace('h4');
			Cufon.replace('.button');
			Cufon.replace('.rollover');
			Cufon.replace('.popupBtn');

			$("#gridPop").fadeIn(250);
			$("#popup").fadeTo(250, 1, function() {
				$("#popup").fadeIn(250);
			});
			var country = get_cookie("country");
			if(country == "us" || country == "gb" || country == "ca")
			{
				$(".cartBtns").show();
				$(".cartNAMsg").hide();
			}

			ClosePopup();
			InitDots(itemID, ".dots li a", "#fullView img.itemImg");
			DisplayVideo(itemID);
			DisplayFullView(itemID);

			$.ajax({
				type: "POST",
				url: path + "grid/MakeTinyURL",
				data: ({ url: $("a#Twitter").attr("alt") }),
				success: function(html) {
					$("a#Twitter").attr("href", $("a#Twitter").attr("href") + html);
				}
			});

			$('#mycarousel').easySlider({
				controlsShow: $('#mycarousel li').length > 1 ? true : false,
				nextText: 'Read More',
				prevText: 'Back'
			});
			$('#mycarousel').css('height', 'auto');
			$('#mycarousel').css('width', 'auto');
			//			$('#mycarousel').jcarousel({
			//				buttonNextHTML: "<a>Read More</a>",
			//				buttonPrevHTML: "<a>Back</a>",
			//				scroll: 1,
			//				wrap: 'both',
			//				itemFirstOutCallback: function(a, b, c, d) {
			//				},
			//				itemFirstInCallback: function(a, b, c, d) {
			//				if (c == 1)
			//					$('.jcarousel-prev').css('display', 'none');
			//				else
			//					$('.jcarousel-prev').css('display', 'block');
			//				},
			//				itemLastInCallback: function(a, carousel, c, d) {

			//				if (c == a.size())
			//					$('.jcarousel-next').css('display', 'none');
			//				else
			//					$('.jcarousel-next').css('display', 'block');
			//				},
			//				itemLastOutCallback: function(a, carousel, c, d) {
			//					
			//				}

			//			});

		}
	});
}
function InitDots(itemID, dotSelector, imgSelector) {
    $(".dots li a").click(function(e) {
        e.preventDefault();
        var imgID = this.id.split('_')[1]
        $.getJSON(path + "grid/imageswitch", { id: itemID, imageID: imgID }, function(data) {
            $(dotSelector).removeClass("current");
            $(dotSelector + "#img_" + imgID).addClass("current");
            var img = $(imgSelector);
            img.attr("src", "/"+data.Image);
            $("#caption").html(data.Text);
        });
    });
}
function DisplayVideo(itemID) {
    $("#playVideo").click(function(e) {
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: path + "grid/video",
            data: ({ id: itemID }),
            success: function(html) {
                $('#popup').empty();
                $('#popup').attr('class', 'modalVideo');
                $('#popup').html(html);

                ClosePopup();
                Cufon.replace('.popupBtn');
                //				$(".closeBtn").click(function(e) {
                //					e.preventDefault();
                //					DisplayBox(itemID);
                //				});

                //				var flashVars =
                //				{
                //					source: $("#videoPath")[0].value
                //				};
                //				var params =
                //				{
                //					movie: '/flash/videoplayer.swf',
                //					bgcolor: "#000000",
                //					quality: "high",
                //					menu: false,
                //					wmode: "transparent",
                //					allowScriptAccess: "always",
                //					allowFullScreen: true
                //				};
                //				var videoPlayer = new VideoPlayer(path + "flash/VideoPlayer.swf", "videoHolder", "431", "259", "10.0.0", flashVars, params);

                $("#backTo").click(function(e) {
                    $(".modalVideo").fadeOut(250);
                    e.preventDefault();
                    DisplayBox(itemID);

                })
            }
        });
    });
}
function DisplayFullView(itemID) {
	$("#fullView").click(function(e) {
		e.preventDefault();
		var imgID = $(".dots li a.current")[0].id.split('_')[1];
		$.ajax({
			type: "POST",
			url: path + "grid/imagelarge",
			data: ({ id: itemID, imageID: imgID }),
			success: function(html) {
				$('#popup').empty();
				$('#popup').attr('class', 'modalFullImg');
				$('#popup').html(html);

				InitDots(itemID, ".dots li a", "#slider img");
				ClosePopup();
				Cufon.replace('.popupBtn');
				$(".closeBtn").click(function(e) {
					e.preventDefault();
					DisplayBox(itemID);
				});
			}
		});
	});
}
function ClosePopup() {
	$(".closeBtn").click(function(e) {
		e.preventDefault();
		RemovePopup();
	});
}
function RemovePopup() {
	RemoveAudio();
	$("#modalVideoArea").remove();
	$("#gridPop").hide();
}
function RemoveAudio() {
	$('.audio_flash').each(function() {
		try
		{
			var x = $(this).find('object');
			if(x.length > 0)
				x[0].SetVariable("closePlayer", 1);
		}
		catch(e){}
	});
}
function RedirectToGrid(type) {
	window.location.replace("/red/#" + type);
    if ($("#grid").length == 0) {
        if (type.length > 0 & type != "home") {
        	window.location.replace("/red/#" + type);
        }
        else {
            window.location.replace("/red/");
        }
        return;
    }
    else {
        PopulateGrid(type);
    }
}
function PopulateGrid(type) {
	lazarusEffect(type);
	try {
	    pageTracker._trackPageview(type);
	}
	catch (e) { }
	$("#grid").fadeOut(250, function() {
		$.getJSON(path + "grid/items?type=" + type, function(data) {
			if (type == 'news')
				$('#moreNewsLink').fadeIn(200);
			else
				$('#moreNewsLink').fadeOut(20);

			if (type == 'lazarusEffect')
				$('#readAboutRed').fadeIn(200);
			else
				$('#readAboutRed').fadeOut(20);
				
			var randomData = (type == 'home') ? data : $.shuffle(data);
			$("#grid").empty();
			$("#grid").fadeIn(0);

			var counter = 1;
			var column1Div = $('<div></div>').addClass("column");
			var column2Div = $('<div></div>').addClass("column");
			var column3Div = $('<div></div>').addClass("column");
			var column4Div = $('<div></div>').addClass("column");
			var column5Div = $('<div></div>').addClass("column");
			var column6Div = $('<div></div>').addClass("column");
			var featuredDiv = $('<div></div>').addClass("featured");
			var gutterDiv = $('<div></div>').addClass("gutter").append("&#160");
			var featuredItem;
			var imgPath = (path == '/') ? '' : path;

			$.each(randomData, function(i, item) {
				if (!item.IsFeatured) {
					//not featured
					switch (counter) {
						case 1:
						case 5:
						case 9:
						case 15:
							column1Div.append(AppendData(item, type, imgPath));
							break;
						case 2:
						case 6:
						case 10:
						case 16:
							column2Div.append(AppendData(item, type, imgPath));
							break;
						case 11:
						case 17:
							column3Div.append(AppendData(item, type, imgPath));
							break;
						case 12:
						case 18:
							column4Div.append(AppendData(item, type, imgPath));
							break;
						case 3:
						case 7:
						case 13:
						case 19:
							column5Div.append(AppendData(item, type, imgPath));
							break;
						case 4:
						case 8:
						case 14:
						case 20:
							column6Div.append(AppendData(item, type, imgPath));
							break;
					}

					counter++;
				}
				else if (item.IsFeatured) {
					//featured
					//populate the featured item and store in variable for later use

					featuredItem = $('<div></div>').addClass("featuredContainer").append(
                    $('<div></div>').attr("id", type + "_" + item.id).addClass("featuredImg").append(
                        $('<a></a>').attr("href", "#").append(
                            $('<img></img>').attr("src", imgPath + item.ImageSmall).attr("alt", "")
                            )
                        ).append(item.HoverText != '' ?
                            $('<a></a>').addClass("rollover").append("&#160").append(item.HoverText).appendTo("#grid")
                            : ''
                        )
                    );
				}
			});

			column1Div.appendTo("#grid");
			$('<div></div>').addClass("gutter").append("&#160").appendTo("#grid");
			column2Div.appendTo("#grid");
			$('<div></div>').addClass("gutter").append("&#160").appendTo("#grid");
			column3Div.appendTo(featuredDiv);
			$('<div></div>').addClass("gutter").append("&#160").appendTo(featuredDiv);
			column4Div.appendTo(featuredDiv);
			featuredDiv.appendTo("#grid");
			$('<div></div>').addClass("gutter").append("&#160").appendTo("#grid");
			column5Div.appendTo("#grid");
			$('<div></div>').addClass("gutter").append("&#160").appendTo("#grid");
			column6Div.appendTo("#grid");
			$('<div></div>').addClass("gutter").append("&#160").appendTo("#grid");
			$(".featured").prepend(featuredItem);
			$(".colDiv").hide();
			$(".featuredImg").hide();
			animateGridItems(".colDiv");
			LoadEvents(type);
			if (type == 'shopred')
				winking = setInterval("WinkImages()", 5000);
			else 
				clearInterval(winking);
		});
	});
}
function animateGridItems(div) {

    //show featured item first
    $(".featuredImg").fadeIn(500);
    var elementArray = $(div);
    fadeInNextElement(jQuery.makeArray($.shuffle(elementArray)).reverse());
}
function fadeInNextElement(elementArray) {
	if (elementArray.length > 0) {
		var element = elementArray.pop();

		$(element).fadeIn(80, function() {
			fadeInNextElement(elementArray);
		});
	}
}
function AppendData(item, type, imgPath) {

	return $('<div></div>').addClass("gridItemContainer").append(
		$('<div></div>').attr("id", type + "_" + item.id).addClass("colDiv").append(
			$('<a></a>').attr("href", "#").append(
				$('<img></img>').attr("src", imgPath + item.ImageSmall).attr("alt", "").attr("class", "wink_" + item.Wink).attr("rel", imgPath + item.WinkImage)
				)
			).append(item.HoverText != '' ?
				$('<a></a>').attr("href", "#").addClass("rollover").append(item.HoverText)
				: ''
			)
		);
}
function AppendData2(item, type, imgPath, controller) {

	return $('<div></div>').addClass("gridItemContainer").append(
		$('<div></div>').attr("id", type + "_" + item.id).addClass("colDivAbout").append(
			$('<a></a>').attr("href", path + controller + "/" + item.Url).append(
				$('<img></img>').attr("src", imgPath + item.ImageSmall).attr("alt", "")
				)
			).append(item.HoverText != '' ?
				$('<a></a>').attr("href", path + controller + "/" + item.Url).addClass("rollover").append(item.HoverText)
				: ''
			)
		)
}
function CreateAccount() {
	$.ajax({
		type: "POST",
		url: path + "signup/createaccount",
		data: ({
			FirstName: $("#FirstName").val(),
			LastName: $('#LastName').val(),
			Email: $("#Email").val(),
			Password1: $("#Password1").val(),
			Password2: $("#Password2").val()
		}),
		dataType: "json",
		success: function(data) {
			if (data.success) {
				$("#createAccountError").text("Your account has been created successfully!");
				$("#createAccountError").removeClass("hidden");
				$("#createAccount").addClass("hidden");
				pageTracker._trackPageview('/email_signup/create_account/thanks');
			}
			else {
				$("#createAccountError").text(data.error);
				$("#createAccountError").removeClass("hidden");
			}
		}
	});
}
function SignupSubmit() {
	$.ajax({
		type: "POST",
		url: path + "signup/submit",
		data: ({
			FirstName: $("#FirstName").val(),
			LastName: $('#LastName').val(),
			Email: $("#Email").val(),
			EmailConfirmation: $("#EmailConfirmation").val(),
			Country: $("#Country").val(),
			ZipCode: $("#ZipCode").val(),
			ConfirmAge: $("#ConfirmAge").is(":checked") ? "on" : ""
		}),
		dataType: "json",
		success: function(data) {
			if (data.success == 'true') {
				$("#signupfields").addClass("hidden");
				$("#thankyou").removeClass("hidden");
				pageTracker._trackPageview('/email_signup/thanks');
			}
			else {
				$("#signupstatus").addClass("error");
				$("#signupstatus").text(data.error);
			}
		}
	});
}
function SignupSubmit2() {
    $.ajax({
        type: "POST",
        url: path + "signup/submit",
        data: ({
            FirstName: $("#FirstName2").val(),
            LastName: $('#LastName2').val(),
            Email: $("#Email2").val(),
            EmailConfirmation: $("#Email2").val(),
            Country: $("#Country2").val(),
            ZipCode: $("#ZipCode2").val(),
            ConfirmAge: $("#ConfirmAge2").is(":checked") ? "on" : ""
        }),
        dataType: "json",
        success: function(data) {
            if (data.success == 'true') {
                //$("#signupstatus2").addClass("error");
                $("#signupstatus2").text("You're finished.  You're now signed up for the (RED) Newsletter.");
                pageTracker._trackPageview('/takeaction/index/thanks');
                $('#joinNowFormArea').empty();
            }
            else {
                $("#signupstatus2").addClass("error");
                $("#signupstatus2").text(data.error);
            }
        }
    });
}
function InitLogin() {
	$('#loginForm').submit(function(e) {
		e.preventDefault();
		$.getJSON(path + "home/login", { Email: $('#AccountEmail').val(), Password: $('#AccountPassword').val() }, function(data) {
			if (data.result == 'fail') {
				$('#loginForm').before('<p class="error">Username or password is incorrect.</p>');
			}
			else {
				$('.accountBtn').each(function(e) {
					if (e.css('display') == 'none')
						e.css('display', 'block');
					else
						e.css('display', 'none');
				});
			}
		});
	});
}
function MiniGrid() {
    $.getJSON(path + "grid/items?type=home", function(data) {

        var randomData = $.shuffle(data);
        $("#gridTemplate").empty();
        $("#gridTemplate").fadeIn(0);

        var counter = 1;
        var column1Div = $('<div></div>').addClass("column");
        var column2Div = $('<div></div>').addClass("column");
        var gutterDiv = $('<div></div>').addClass("gutter").append("&#160");
        var imgPath = (path == '/') ? '' : path;

        $.each(randomData, function(i, item) {
            switch (counter) {
                case 1:
                case 2:
                case 3:
                case 4:
                    column1Div.append(AppendData(item, "home", imgPath));
                    break;
            }

            counter++;
        });

        column1Div.appendTo("#gridTemplate");
        $('<div></div>').addClass("gutter").append("&#160").appendTo("#gridTemplate");
        //column2Div.appendTo("#gridTemplate");
        $(".colDiv").hide();
        animateGridItems(".colDiv");
        LoadEvents();
    });
}
function MiniGrid2() {
	$.getJSON(path + "grid/AboutItems?type=aboutred", function(data) {
		$("#gridTemplate").empty();
		$("#gridTemplate").fadeIn(0);

		var counter = 1;
		var imgPath = (path == '/') ? '' : path;

		$.each(data, function(i, item) {
			var block = AppendData2(item, "aboutred", imgPath, "aboutred");

			//	add the ajaxiness
			block.click(function(e) {
				e.preventDefault();
				var id = $(this).find('.colDivAbout').attr('id').split('_')[1];

				$.ajax({
					type: 'POST',
					url: path + 'aboutred/articleajax',
					data: { id: id },
					success: function(html) {
						$('#subContent').html(html);
						Cufon.replace('h3');
						Cufon.replace('.shopRed dd');
						Cufon.replace('h4');
					}
				});

			});

			$("#gridTemplate").append(block);

//			if ((counter % 2) == 1) {
//				$("#gridTemplate").append($('<div></div>').addClass("gutter2").append("&#160"));
//			}

			counter++;
		});

		$('#subContent').load(path + '/aboutred div.colDivAbout');

		$(".colDivAbout").hide();
		animateGridItems(".colDivAbout");
	});
}
function TakeActionMiniGrid() {
	$.getJSON(path + "takeaction/ActionItems?type=aboutred", function(data) {
		$("#gridTemplate").empty();
		$("#gridTemplate").fadeIn(0);

		var counter = 1;
		var imgPath = (path == '/') ? '' : path;

		$.each(data, function(i, item) {
			var block = AppendData2(item, "aboutred", imgPath, "takeaction");

			//	add the ajaxiness
			block.click(function(e) {
				e.preventDefault();
				var id = $(this).find('.colDivAbout').attr('id').split('_')[1];

				$.ajax({
					type: 'POST',
					url: path + 'takeaction/articleajax',
					data: { id: id },
					success: function(html) {
						$('#subContent').html(html);
						Cufon.replace('h3');
						Cufon.replace('h4');
					}
				});

			});

			$("#gridTemplate").append(block);

			//			if ((counter % 2) == 1) {
			//				$("#gridTemplate").append($('<div></div>').addClass("gutter2").append("&#160"));
			//			}

			counter++;
		});

		$('#subContent').load(path + '/aboutred div.colDivAbout');

		$(".colDivAbout").hide();
		animateGridItems(".colDivAbout");
	});
}
var ele;
function WinkImages() {
	var random = Math.floor(Math.random() * ($("img.wink_true").length));
	ele = $("img.wink_true")[random]
	if (ele) {
		SwapImage(ele);

		setTimeout("SwapImage(ele)", 2000);
	}
}
function SwapImage(ele) {
	var image = ele.src;
	ele.src = ele.getAttribute("rel");
	ele.setAttribute("rel", image);
}
function initSignup() {
	$('#joinNowForm').submit(function(e) {
		e.preventDefault();
		$('#joinred').fadeIn(100);

		$('#FirstName').val(e.currentTarget.elements[0].value);
		$('#Email').val(e.currentTarget.elements[1].value);
		pageTracker._trackPageview('email_signup');
	});
}

function verifyCode(e, isBtn) {
	if (!isBtn && e.keyCode != 13) { return; }

	$.getJSON(path + 'checkout/verifycode', { code: $('#promoCode').val() },
				function(data, textStatus) {

					//promoCodeMsg
					if (data.result == "valid") {
						$('.totalAmount').text(data.newTotal);
						Cufon.replace('.totalAmount');
						$('#promoCodeMsg > span').text("");
						if (data.reloadCart) {
							location.reload();
						}
					}
					else if (data.result == "invalid") {
						$('#promoCodeMsg > span').text("That's an invalid promo code.");

					}
				}
			);
		
	}
function initVerifyCodeTxt(verifyTxt) {
	verifyTxt.keydown(function(e) { verifyCode(e, false); });
}
function initVerifyCodeBtn(verifyBtn) { 
	verifyBtn.click(function(e) { verifyCode(e, true); });
}
function modifyFBlike(layout, faces, width, action, font, colorScheme, url) {

    var frame = $("#AjaxIcons a.addthis_button_facebook_like iframe");
    var frameSrc = $("#AjaxIcons a.addthis_button_facebook_like iframe").attr("src");

	// set iframe width
    $("#AjaxIcons a.addthis_button_facebook_like iframe").css("width", width + "px");
	// set height for "faces"

	frameSrc = "//www.facebook.com/plugins/like.php?href=" + url + "&layout=" + layout + "&show_faces=" + faces + "&width=" + width + "&action=" + action + "&font=" + font + "&colorscheme=" + colorScheme;
	$("#AjaxIcons a.addthis_button_facebook_like iframe").attr("src", frameSrc);
}
function modifyFBlike2(layout, faces, width, action, font, colorScheme, url) {

    var frame = $("#AjaxIcons2 a.addthis_button_facebook_like iframe");
    var frameSrc = $("#AjaxIcons2 a.addthis_button_facebook_like iframe").attr("src");

    // set iframe width
    $("#AjaxIcons2 a.addthis_button_facebook_like iframe").css("width", width + "px");
    // set height for "faces"

    frameSrc = "//www.facebook.com/plugins/like.php?href=" + url + "&layout=" + layout + "&show_faces=" + faces + "&width=" + width + "&action=" + action + "&font=" + font + "&colorscheme=" + colorScheme;
    $("#AjaxIcons2 a.addthis_button_facebook_like iframe").attr("src", frameSrc);
}
function SubmitAge() {
    $('#verifyBtn').click(function(e) {
        e.preventDefault();
        var itemID = $("#aID").val();
        $.ajax({
            type: "POST",
            url: path + "grid/verify",
            data: ({
                month: $("#aMonth").val(),
                day: $('#aDay').val(),
                year: $("#aYear").val(),
                country: $("#aCountry").val(),
                id: $("#aID").val()
            }),
            success: function(html) {
                if (html != '') {
                    $("#gridPop").fadeOut(250);
                    $('#popup').empty();
                    $('#popup').attr('class', 'modalPopup'); ;
                    $('#popup').html(html);
                    
                    Cufon.replace('h2');
                    Cufon.replace('h3');
                    Cufon.replace('h4');
                    Cufon.replace('.button');
                    Cufon.replace('.rollover');
                    Cufon.replace('.popupBtn');

                    $("#gridPop").fadeIn(250);
                    $("#popup").fadeTo(250, 1, function() {
                        $("#popup").fadeIn(250);
                    });
                    var country = get_cookie("country");
                    if (country == "us" || country == "gb" || country == "ca") {
                        $(".cartBtns").show();
                        $(".cartNAMsg").hide();
                    }

                    ClosePopup();
                    InitDots(itemID, ".dots li a", "#fullView img.itemImg");
                    DisplayVideo(itemID);
                    DisplayFullView(itemID);

                    $.ajax({
                        type: "POST",
                        url: path + "grid/MakeTinyURL",
                        data: ({ url: $("a#Twitter").attr("alt") }),
                        success: function(html) {
                            $("a#Twitter").attr("href", $("a#Twitter").attr("href") + html);
                        }
                    });

                    $('#mycarousel').easySlider({
                        controlsShow: $('#mycarousel li').length > 1 ? true : false,
                        nextText: 'Read More',
                        prevText: 'Back'
                    });
                    $('#mycarousel').css('height', 'auto');
                    $('#mycarousel').css('width', 'auto');
                }
                else {
                    $("#signupstatus").addClass("error");
                    $("#signupstatus").text("You must be of legal drinking age to enter this page.");
                }
            }
        });
    });
}
function TextFocus() {
    $(".verify input").focus(function() {
        if ($(this).val() == $(this)[0].defaultValue)
            $(this).val('');
    });

    $(".verify input").blur(function() {
        if ($(this).val() == '')
            $(this).val($(this)[0].defaultValue);
    });
}
