
top_mnu_txt_fix = "";

$(document).ready(function(){

	//Check For Confirmation Page
	var URLTxt = window.location.toString();
	//alert(URLTxt.indexOf('action=sendContactForm'));
	if(URLTxt.indexOf('action=sendContactForm') > 5){
		document.location = '/contact-thanks/';
	}

	//Fixes Top Menu
	$('#mn-nv li div').hide();

	$('#SimilarProductsByCustomerViews').hide();

	$('#mn-nv li .SideCategoryListClassic').each(function(){
		 top_mnu_txt_fix = "<ul>";
		$(this).find('ul').each(function(){
			top_mnu_txt_fix +=	$(this).html();
		});
		 top_mnu_txt_fix += "</ul>";
		$(this).parent().append(top_mnu_txt_fix );
	});

	$('#bottom_payment_button').live('click', function(){
		if($('#checkout_provider_checkout_eway:checked').length > 0){
			$('#CheckoutStepPaymentDetails').show();
			//alert('credit payment');
		}else{
			//alert('fail');
		}
	});
	
				
	$("#user-nv li:first").addClass('first');

	$("#mn-nv").superfish({autoArrows: false});
	
	$(".blog-list li:last").addClass('last');
	
	// Where anchor used for submit button
    $("a[title=submit]").click( function(){
		$(this).parents("form").submit();
    });
    
    



 	 
 	 // Header cart pop up
 		jQuery.fn.fadeToggle = function(speed, easing, callback) {
  			return this.animate({opacity: 'toggle'}, speed, easing, callback);  
		};
	
	$("#cart-btn").click(function(){
	  	$("#cart-items").fadeToggle("slow");
	  	$(this).toggleClass("cart-btn-active");
	});
	
	// Set the cart count in header
	if(cartCount == '') {
		$('#cart-status span').html('is empty');
		$('.in-cart p').html('Your cart is currently empty.');
	} else if(cartCount == '1') {
		$('#cart-status span').html('1 item');
		$('.in-cart p').html('Your cart currently contains 1 item.');
	} else {
		$('#cart-status span').html(cartCount + ' items');
		$('.in-cart p').html('Your cart currently contains '+cartCount+' items.');
	}
	var counter = 1;
	$('.side-nv > ul > li').each(function() {
		$(this).attr('id', '_'+counter);
		counter++;
	});
	
	/*var current_menu_item = '';
	$('.side-nv > ul > li > a').click(function() {
		if($(this).parent().attr('id') != current_menu_item) {
			current_menu_item = $(this).parent().attr('id');
			$('.side-nv > ul > li > ul').slideUp();
			$(this).next('ul').slideDown();
		}
		console.log(current_menu_item);
		return false;
		
	});*/

	//$('.prod-cats > div > ul').hide();
	
	//Home Page Upgrade Fix

	$('.prod-cats  .SideCategoryListClassic').css('width', '628px');
	$('.prod-cats  .SideCategoryListClassic').css('overflow', 'hidden');
	$('.prod-cats .SideCategoryListClassic ul').css('width', '205px');
	$('.prod-cats .SideCategoryListClassic ul').css('float', 'left');
	$('.prod-cats .SideCategoryListClassic ul').css('margin', '0px');


	
	$('.prod-cats > div > ul > li > a').each(function() {

		var slug = $(this).text().replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase();
		$(this).css('background', 'url("/content/img/categories/'+slug+'.jpg") no-repeat scroll 0 0 transparent');
	});
	
	/*$('.SubCategoryList > ul > li > a').each(function() {
		var slug = $(this).text().replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase();
		$(this).css('background', 'url("/content/img/sub_categories/'+slug+'.jpg") no-repeat scroll 0 0 transparent');
	});*/

	$('#SubCatImageDisp').each(function() {
		var slug = $('.b-crumb li:eq(1)').text().replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase();
		if($('.b-crumb li:eq(2)').text() != ''){
			var slug = $('.b-crumb li:eq(2)').text().replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase();
			$(this).attr('src', '/content/img/sub-cat-big/'+slug+'.jpg');

		}else{
			$(this).attr('src', '/content/img/categories/header/hd-img-'+slug+'.jpg');
		}
	});

	$('#CatImageDisp').each(function() {
		var slug = $(this).attr("src").replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase();
		$(this).attr('src', '/content/img/categories/header/hd-img-'+slug+'.jpg');
	});


	/*$('#cartForm .FloatLeft input').attr('src', '');
	$('#cartForm .FloatLeft input').attr('alt', '');
	$('#cartForm .FloatLeft input').attr('background-image', '/content/img/buttons/update-qty.png');
	$('#cartForm .FloatLeft input').hover(
		function (){
			$(this).css('background-position', '0 24px');
		},
		function (){
			$(this).css('background-position', '0 0');
		}
	);*/

	var Cnt = 1;
	$('.AccountOrderStatusList form').each(function (){
		if(Cnt % 2 == 0){
			$('input:eq(2)', this).css('float', 'right').css('margin', '-23px 0 20px 0');
			$('input:eq(2)', this).attr('src','/content/img/buttons/order-reorder.png');
			$('input:eq(2)', this).hover(
				function (){$(this).attr('src','/content/img/buttons/order-reorder-hover.png');},
				function(){$(this).attr('src','/content/img/buttons/order-reorder.png');}
			);
		}else{
			$('input:eq(2)', this).attr('src','/content/img/buttons/view-order-details.png');
			$('input:eq(2)', this).hover(
				function (){
					$(this).attr('src','/content/img/buttons/view-order-details-hover.png');
				},
				function(){
					$(this).attr('src','/content/img/buttons/view-order-details.png');
				}
			);	
		}
		Cnt++;
	});

	$('.AccountOrdersList form').each(function (){

		$('input:eq(2)', this).attr('src', '/content/img/buttons/view-order-details.png');
		$('input:eq(2)', this).hover(
			function (){$(this).attr('src','/content/img/buttons/view-order-details-hover.png');},
			function(){$(this).attr('src','/content/img/buttons/view-order-details.png');}
		);

		$('.ReturnLink img', this).attr('src', '/content/img/buttons/return-items.png');
		$('.ReturnLink img', this).css('float', 'right');
		$('.ReturnLink img', this).css('margin-top', '-30px');
		$('.ReturnLink img', this).hover(
			function (){$(this).attr('src','/content/img/buttons/return-items-hover.png');},
			function(){$(this).attr('src','/content/img/buttons/return-items.png');}
		);

	});

	$('.AccountOrdersList from').each(function (){
		$('input:eq(2)').attr('src', '');
	});

	$('#SaveAddressBtn').hover(
		function (){$(this).attr('src','/content/img/buttons/save-address-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/save-address.png');}
	);

	$('#submit').hover(
		function (){$(this).attr('src','/content/img/buttons/signin-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/signin.png');}
	);	

	$('#CreateAccountBtn').hover(
		function (){$(this).attr('src','/content/img/buttons/create-account-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/create-account.png');}
	);

	$('#SendMessageBtn').hover(
		function (){$(this).attr('src','/content/img/buttons/send-message-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/send-message.png');}
	);

	$('#UpdateDetailsBtn').hover(
		function(){$(this).attr('src','/content/img/buttons/update-my-details.png');},
		function(){$(this).attr('src','/content/img/buttons/update-my-details-hover.png');}
	);

	$('#ReorderBtn').hover(
		function(){$(this).attr('src','/content/img/buttons/order-reorder-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/order-reorder.png');}
	);

	$('#UpdateQtyBtn').hover(
		function(){$(this).attr('src','/content/img/buttons/update-qty-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/update-qty.png');}
	);

	$('#bottom_payment_button').hover(
		function(){$(this).attr('src','/content/img/buttons/continue-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/continue.png');}
	);



	$('#ContinueBtn').hover(
		function(){$(this).attr('src','/content/img/buttons/continue-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/continue.png');}
	);


	$('#BillingNShipBtn').hover(
		function(){$(this).attr('src','/content/img/buttons/bill-and-ship-hover.png');},
		function(){$(this).attr('src','/content/img/buttons/bill-and-ship.png');}
	);



	$('.item-more-info h4').each(function() {
		if($(this).text() == 'Ingredients 1' || $(this).text() == 'Ingredients' ){
			$(this).text('Ingredients');
			$(this).next('p').attr('id', 'MainIng');
		}else if($(this).text().substr(0,11) == 'Ingredients'){
			$('#MainIng').text($('#MainIng').text() + ' ' + $(this).next('p').text());
			$(this).next('p').remove();
			$(this).remove();

		}
		
	});


	if($('.b-crumb li:eq(1)').text().replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase() == 'about-us'){
	}
	if($('.b-crumb li:eq(1)').text().replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase() == 'contact-us'){
		$('.page-header-cotton').empty();
		$('.page-header-cotton').css('background-image', 'url("/content/img/contact-img.jpg")');
	}

	if($('.b-crumb li:eq(1)').text().replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase() == 'medicinal-nutritional-teas'){
		//alert('here');
		$('.ct-block-wp').append("<p style=\"padding: 10px; font-size: 0.9em;\"> * Herbal teas have been known to have medicinal benefits since the days of the ancient egyptians. A herbal tea is simply the combination of boiling water and dried fruit, flowers or herbs and many are rich in antioxidants. They have many health benefits and most taste good too! They can be used for so many illnesses and common conditions, though they should be used in moderation. Remember though, that even though our herbs may provide wonderful benefits, they are still chemical substances and can sometimes have side effects or interact with mainstream medicines. So the information on our website should not be substituted or used to alter medial therapy without your doctors advice. Remember too for a specific health problem it is always wise to consult your doctor, particularly for pregnant and breastfeeding women, children under 16 or anyone with a chronic health problem. Please ensure your specialist or family doctor is aware of any herbs that you are taking to ensure they do not react with medications that you may be on. Any references or advice given on this website does not imply a recommendation or that it is a substitute to your doctors advice.</p>");
		$('.prod-cats').append("<p style=\"padding: 10px; font-size: 0.9em;\"> * Herbal teas have been known to have medicinal benefits since the days of the ancient egyptians. A herbal tea is simply the combination of boiling water and dried fruit, flowers or herbs and many are rich in antioxidants. They have many health benefits and most taste good too! They can be used for so many illnesses and common conditions, though they should be used in moderation. Remember though, that even though our herbs may provide wonderful benefits, they are still chemical substances and can sometimes have side effects or interact with mainstream medicines. So the information on our website should not be substituted or used to alter medial therapy without your doctors advice. Remember too for a specific health problem it is always wise to consult your doctor, particularly for pregnant and breastfeeding women, children under 16 or anyone with a chronic health problem. Please ensure your specialist or family doctor is aware of any herbs that you are taking to ensure they do not react with medications that you may be on. Any references or advice given on this website does not imply a recommendation or that it is a substitute to your doctors advice.</p>");

		$('#ct-lt').append('<div style="" id="Disclaimer" class="the-panel"><h2>Disclaimer</h2><p> information on our website should not be substituted or used to alter medial therapy without your doctors advice. Remember too for a specific health problem it is always wise to consult your doctor, particularly for pregnant and breastfeeding women, children under 16 or anyone with a chronic health problem.</p></div>');
		//$('#Disclaimer').show();
	}

	$('.SubCategoryList ul li').each(function(){
	     	$('#QuickSearchOption').append($("<option></option>").attr("value", $('a', this).attr('href')).text($('a', this).text()));

		$('#QuickSearch').show();
	});

	$('#QuickSearchOption').change(function(){
		window.location = $(this).val();
	});

	$('#checkout_type_guest').click(function(){
		$('.AccountLogin').hide();
	});


	$('#checkout_type_register').click(function(){
		$('.AccountLogin').show();
	});

	$('#CheckoutStepShippingAddress .ChangeLink').click(function(){
		if($('#FormField_15_0').attr("checked")==true){
			//First Name
			if($('#FormField_16').val() == '') 	$('#FormField_16').val($('#FormField_4').val()) ;

			//Last Name
			if($('#FormField_17').val() == '') 	$('#FormField_17').val($('#FormField_5').val()) ;

			//Company
			if($('#FormField_18').val() == '') 	$('#FormField_18').val($('#FormField_6').val()) ;

			//Phone
			if($('#FormField_19').val() == '') 	$('#FormField_19').val($('#FormField_7').val()) ;

			//Address 1
			if($('#FormField_20').val() == '') 	$('#FormField_20').val($('#FormField_8').val()) ;

			//Address 2
			if($('#FormField_21').val() == '') 	$('#FormField_21').val($('#FormField_9').val()) ;

			//Suburb
			if($('#FormField_22').val() == '') 	$('#FormField_22').val($('#FormField_10').val()) ;

			//Country
			if($('#FormField_23').val() == '') 	$('#FormField_23').val($('#FormField_11').val()) ;

			//State
			if($('#FormField_24').val() == '') 	$('#FormField_24').val($('#FormField_12').val()) ;

			//Zip
			if($('#FormField_25').val() == '') 	$('#FormField_25').val($('#FormField_13').val()) ;


		}else{
			//alert(' dont use using shipping');			
		}
	});

			
	if($('.VariationSelect').length < 2){
		$('.VariationSelect').parent().prepend('Select Size');
	}

	$('#ProductBreadcrumb ul').hide();
	$('#ProductBreadcrumb ul:first').show();


	//Fix ClassicCategoryList
	$('.SideCategoryListClassic').css('width', '619px');
	$('.SideCategoryListClassic').css('border-right', '1px solid #3D2205');
	$('.SideCategoryListClassic').css('border-top', '1px solid #3D2205');
	$('.prod-cats .SideCategoryListClassic ul').css('border-top','solid 0px #FFF');
		


});


