
	// contact form opener
	// legacy code on contact form
// NOTYET - convert to jquery
	function SwitchMenu(obj){
		if (document.getElementById) {
			var el = document.getElementById(obj);
			var ar = document.getElementById("allpagesections").getElementsByTagName("div"); 
			if(el.style.display != "block"){ 
				for (var i=0; i<ar.length; i++){
					if (ar[i].className=="pagesection") 
						ar[i].style.display = "none";
				}
				el.style.display = "block";
			}else{
				el.style.display = "none";
			}
		}
	}

$(document).ready(function(){

	if($.browser.msie && $.browser.version < 7) {
		$('.mnav li').hover(
		   function(){
			  $(this).addClass('sfhover');
		   },
		   function(){
			  $(this).removeClass('sfhover');
		   }
		);
	}


	
	
	// ADD TO CART AJAX	 	
	
	$("#addcart-popup").hover(
	  function () {
		$(this).stop(true);
	  }, 
	  function () {
		$(this).hide();
	  }
	);

	
	$('.addtocart').click( function() {
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object before using
		
		$("#addcart-popup").stop().hide();
		// change add to cart button to rotator gif
		var addelem = $(this);
		var img = jQuery('> img',$(this));
		var img_old = img.attr("src");
		img.attr( { src: '/store/images/indicator.gif' });
		var img_addmore = '/store/includes/templates/crowder/images/add-more.gif';
		
		// get prodid from href
		var href = $(this).attr("href");
		var sTag = 'products_id=';
		var i1 = href.indexOf(sTag)+sTag.length;
		var idProd = parseInt(href.substr(i1),10);
		if (!idProd) {
			alert("Can't add to cart, check Product ID");
			return false;
		}
        $.getJSON("/store/req-cart.php?action=buy_now&products_id="+idProd,
			function(data, status){
        	
        		// if success, put in checkbox, set timer to reset to old value after time
        		// OR add little box above add to cart, Added with checkbox, fade it out
        		
				// textStatus will be one of the following values: 
				//   "timeout","error","notmodified","success","parsererror"
        		if (status=='success' && data.return_value=='ok') {
	        		// fade in/out checkmark
	        		img.hide();
	        		img.attr( { src: '/store/includes/templates/crowder/images/icons/tick.png' } );
					// update cart pane
					$('#pagecart-items').html(data.nitems);
					$('#pagecart-total').html(data.total);
	        		$('#pagecart-add').stop().animate({'bottom': 20},1000);					
	        		img.fadeIn('fast', function() {
	        			img.fadeOut(500, function() {
	        				img.attr( { src: img_addmore } );
	        				img.show();
	        			});
	       			});
	        		$('#pagecart-add').animate({'bottom': 20},2000); // pause
	        		$('#pagecart-add').animate({'bottom': -10},1000); // slide down
					
					// show "view cart" button
					// ? how to position?
					//$('div.tooltip').css({top: tPosY, left: tPosX})};
					//get the position of the placeholder element
					var pos = addelem.offset();  
					var width = addelem.width();
					//show the menu directly over the placeholder
					$("#addcart-popup").css( { "left": (pos.left + width+4) + "px", "top":(pos.top-12-4) + "px" } );
	        		$("#addcart-popup").show().animate({"top":"+=4"},500).animate({"top": "+=0"},6000,function() {
						$(this).hide(); 
					});
	        		//$("#addcart-popup").animate({"top":"+=4","opacity":1},500).animate({"opacity": 1},6000).animate({"opacity":0},500);
	       			//ie7 doesn't do transparent pngs right if opacity messed with, so just show and ease in
					
					
					
        		} else {
        			// error - put same button back
					img.attr( { src: img_old } );
        		}
        		
		});
		return false;
	});

	
	$('#pagecart-signin').click( function() {
		$('#pagecart-login').stop().animate({'top': '-50px'},500);
		$('#login-email-address').focus();
		return false;
	});
	
	
	
});
