$(document).ready(function() {
	
	
	/* -- Main Body Slidehow Function -- */
	var _count = 0;
	var _total;
	
	var _slideHeight = $("#img_list img:first").css("height");
	$("#img_wrap").css("height", _slideHeight);
	$("#img_list").css("height", _slideHeight);
	
	$("#slideshow_img").append('<div id="slideshow_ctrl"><span id="ctrl_dots"></span><span id="ctrl_arrows"><img src="images/slideshow_prev.gif" class="prevImg" /><a href="#" class="next"><img src="images/slideshow_next_active.gif" /></a></span>');
	
	$("#img_list img").each(function(){
		_count++;
		if (_count === 1) {
			$("#ctrl_dots").append('<img src="images/slideshow_dot_active.gif" class="activeImg" title="img_1" />');
		} else {
			$("#ctrl_dots").append('<a href="#slide_'+_count+'"><img src="images/slideshow_dot_inactive.gif" /></a>');
		}
	});
	
	_total = _count*340+"px";
	$("#img_wrap").css("width", _total);
	
	_count = 1;
	
	$("#ctrl_dots a").live("click", function(){
		
		var _current = $(".activeImg").attr("title");
		_current = _current.replace("img_", "");
		
		$(".activeImg").before('<a href="#slide_'+_current+'"><img src="images/slideshow_dot_inactive.gif" /></a>');
		$(".activeImg").remove();
		
		var _href = $(this).attr("href");
		var myAnchor = '#' + _href.split('#')[1];
		var _num = myAnchor.replace("#slide_", "");
		_count = _num;
		var _slideTo = -((_num-1)*340)+"px";
		$("#img_wrap").animate({ left: _slideTo });
		
		$(this).before('<img src="images/slideshow_dot_active.gif" title="img_'+_num+'" class="activeImg" />');
		$(this).remove();
		
		checkCount();
		return false;
		
	});
	
	_totalImg = 0;
	$("#img_wrap img").each(function(){
		_totalImg++;
	});
	
	$("#ctrl_arrows .next").live("click", function(){
		
		var _next = _count+1;
		
		$(".activeImg").before('<a href="#slide_'+_count+'"><img src="images/slideshow_dot_inactive.gif" /></a><img src="images/slideshow_dot_active.gif" title="img_'+_next+'" class="activeImg" />');
		$(".activeImg:last").remove();
		$("#ctrl_dots a:last").remove();
		
		var _num = -((_count)*340);
		var _slideTo = _num+"px";
		
		if(_count < _totalImg) {
			$("#img_wrap").animate({ left: _slideTo });
		}
		
		_count++;
		checkCount();
		return false;
	});
	
	$("#ctrl_arrows .prev").live("click", function(){
		
		var _prev = _count-1;
		
		$(".activeImg").after('<img src="images/slideshow_dot_active.gif" title="img_'+_prev+'" class="activeImg" /><a href="#slide_'+_count+'"><img src="images/slideshow_dot_inactive.gif" /></a>');
		$(".activeImg:first").remove();
		$(".activeImg").prev("a").remove();
		
		_count--;
		var _num = -((_count-1)*340);
		var _slideTo = _num+"px";
		
		if(_count > 0) {
			$("#img_wrap").animate({ left: _slideTo });
		}
		
		checkCount();
		return false;
	});
	
	function checkCount() {
		if(_count < _totalImg) {
			$("img.nextImg").before('<a href="#slide_'+_count+1+'" class="next"><img src="images/slideshow_next_active.gif" /></a>');
			$("img.nextImg").remove();
		} else {
			$("a.next").before('<img src="images/slideshow_next.gif" class="nextImg" />');
			$("a.next").remove();
		}
		
		if (_count > 1) {
			$("img.prevImg").before('<a href="#slide_'+_count+'" class="prev"><img src="images/slideshow_prev_active.gif" /></a>');
			$("img.prevImg").remove();
		} else {
			$("a.prev").before('<img src="images/slideshow_prev.gif" class="prevImg" />');
			$("a.prev").remove();
		}
	}
	
	
	/* -- Vendor List Functions -- */
	
	$("ul.plan_tabs a").click(function(){
		var theID = "#" + $(this).attr("class");
		theID = theID.replace(" active", "");
		var theList = theID + "_section";
		$(".planContent h3, .planContent div").not(".event_experts").hide();
		$(".vendor_intro:visible").hide();
		$(theID).fadeIn();
		$(theList).fadeIn();
		$("ul.plan_tabs a").removeClass("active");
		$(this).addClass("active");
		return false;
	});
	$(".planContent h3, .planContent div").not(".event_experts").hide();
	$(".planContent h3:first, .planContent div:first").show();
	
	$("ul.detail_tabs a").click(function(){
		var theID = "#" + $(this).attr("class");
		theID = theID.replace(" active", "");
		var theList = theID + "_section";
		$(".detail_section").hide();
		$(theList).fadeIn();
		$("ul.detail_tabs a").removeClass("active");
		$(this).addClass("active");
		return false;
	});
	$(".detail_section").hide();
	$("#reviews_section").show();
	
	
	/* -- Shop Review and Accolades Function -- */
	
	$("#shop_sub").hide();
	$("#shop_sub li").hide();
	$("#shop_link").hover(function(){
		$(this).stop();
		$("#shop_sub").stop().show();
		$("#shop_sub li").fadeIn();
	}, function(){
		$("#shop_sub").animate({ marginBottom:"0" }, 600, function(){
			$("#shop_sub li").hide();
			$(this).hide();
		});
	});
	
	
	/*  Email Newsletter Signup */
	
	/*$("#newsSignup_name").focus(function(){
		if($(this).attr("value") == "Your Name")
		{
			$(this).attr("value", "");
		}	
	});
	
	$("#newsSignup_name").blur(function(){
		if(!$(this).attr("value"))
		{
			$(this).attr("value", "Your Name");
		}
	});
	
	$("#newsSignup_email").focus(function(){
		if($(this).attr("value") == "Your Email Address")
		{
			$(this).attr("value", "");
		}
	});
	
	$("#newsSignup_email").blur(function(){
		if(!$(this).attr("value"))
		{
			$(this).attr("value", "Your Email Address");
		}
	});
	
	
	$("#newsSignupForm").submit(function(){
		var _this = $(this);
		var _name = $(this).find("input#newsSignup_name").attr("value");
		var _error = "";
		
		if(_name == "Your Name" || !_name)
		{
			_error += "\nPlease enter your name.";
		}
		
		var _email = $(this).find("input#newsSignup_email").attr("value");

		if(_email == "Your Email Address" || !_email)
		{
			_error += "\nPlease enter your email address.";
		}
		
		if(_error != "")
		{	
			alert(_error);
		} else {
			var _data = "fajaSubmit=true";
			$(this).find("input").each(function(){
				_data += "&"+$(this).attr("name")+"="+$(this).attr("value");
			})
			
			$.ajax({
				type: "POST",
				url: "/inc/form_handler.php",
				data: _data,
				success: function(msg){
					if(msg == "SUCCESS")
					{
						$("#newsSignupForm").fadeOut("fast",function(){
							$("#newsSignup_name").attr("value", "Your Name");
							$("#newsSignup_email").attr("value", "Your Email Address");
							$(".success_msg").fadeIn();
						});
					} else {
						alert(msg);
					}
				}, error: function(){
					alert("An Error Occured, please try again later.");
				}
			});
			
		}
		return false;
	});
	*/
	
	/* -- Copy Fields -- */
	
	$("#copyFields").click(function(){
		$("#Shipping_Name").attr("value",$("#Billing_Name").attr("value"));
		$("#Shipping_Address_Line_1").attr("value",$("#Billing_Address_Line_1").attr("value"));
		$("#Shipping_Address_Line_2").attr("value",$("#Billing_Address_Line_2").attr("value"));
		$("#Shipping_City").attr("value",$("#Billing_City").attr("value"));
		$("#Shipping_State").attr("value",$("#Billing_State").attr("value"));
		$("#Shipping_Zip").attr("value",$("#Billing_Zip").attr("value"));
		$("#Shipping_Phone").attr("value",$("#Billing_Phone").attr("value"));
		
		return false;
	});
	
});


/* -- AGE VERIFICATION -- */

var _age;

var _cookie = readCookie('ageVerified');
if (_cookie) {
	_age = 1;

} else {
	$(function(){
		$("html, body").css({ overflow: "auto", height: "100%" });
		$("#ageVerify").fadeIn();
		
	});
	_age = 0;

}


/* -- CALL CUFON TEXT REPLACEMENT -- */

Cufon.replace('#news_signup_invite', { textShadow:'#000 1px 1px' });
Cufon.replace('#content h1, #content h2, #ageVerify h1', { hover:'true' });


