function current_category()
{
	var category = $("h1").attr("category");
	var sub_category = $("h1").attr("sub_category");
	
	if (category)
	{
		//Open current category
		category = '#' + category;
		$(category).addClass("active");
		$(category).next("div.menu_body").show();
	}
	
	if (sub_category)
	{
		sub_category = '#' + sub_category;
		$(sub_category).addClass("active");
	}
}

//Highlight current category
	current_category();

$(document).ready(function() {
	
	
	
	//Apply colorbox
	$('a.lightbox').colorbox();
	
	//Auto input placeholder text	
	var input_type;
	var place_holder;
	$('input').each(function() {
		input_type = $(this).attr('type');
		if (input_type == 'text');
		{
			place_holder = $(this).attr('placeholder');
			if (place_holder)
			{
				$(this).placeHolder({'text': place_holder});
			}
		}
	});
	
	
	/********** Category Menu **********/
	$("a.menu_head").toggle(function(e)
	{
		e.preventDefault();
		$(".menu_head").removeClass("active");
		$(this).addClass("active").next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
	}, function(e) {
		e.preventDefault();
		$(this).removeClass('active').next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
	});
	/********** END Category Menu **********/
	
	
	
	/********** Show More **********/
	$('a.show_more').toggle(function(e) {
		e.preventDefault();
		$(this).parent().next('p.more').slideDown();
		$(this).html('(less)');
	}, function(e) {
		e.preventDefault();
		$(this).parent().next('p.more').slideUp();
		$(this).html('(more)');
	});
	/********** END Show More *********/
		
		
	/********** Opt In Form **********/	
	$('#opt_form').submit(function(e) {
		e.preventDefault();
		$('#opt_form').validate({
			//hide error labels
			errorPlacement: function(error, element) { },
		
			//submit via ajax
			submitHandler: function(e) {
				var form_data = $("#opt_form").serialize();
				$.ajax({
					data: form_data,
					type: "POST",
					url: "http://www.buyers-market.net/optin/ajax_submit",					
					success: function()
					{
						$('#opt_in').fadeOut(function() {
							$('#opt_thanks').fadeIn();
							$(':input', '#opt_in').not('#optSubmit').val(''); 
						});
					}
				});
			}
		});	
	});
	/********** END Opt In Form **********/

		
	//  ****** CATEGORY PAGES *****
	//Show hidden products on category pages
	$("a.show_hidden").toggle(function(e)
	{
		e.preventDefault();
		$(this).closest('.product_group').find('.hidden').fadeIn('fast');
		$(this).text("(hide)");
	}, function(e) {
		e.preventDefault();
		$(this).closest('.product_group').find('.hidden').fadeOut('fast');
		$(this).text("(see more)");
	});
	

	
	
		//Jump to function for category maps
	$('#sel').live("change keyup", function() {
		var category = $('#sel').val();
		if( category != 'NULL' )
		{
			$('#category_jump').submit();
		}
		
	});	
	// ****** END CATEGORY PAGES ******


//END DOCUMENT.READY	
});
