var $j = jQuery.noConflict();

jQuery.noConflict();
(function($) { 
	$(function() {
  		WellnessRealization.init();
  	
  	
  		//contactid
  		if(arg('contactid').length > 0 && $j('#conversation').length > 0) {
  			document.getElementById('conversation').selectedIndex = arg('contactid');
  		}
  		
  		if($('.quote-text').length > 0) {
  			$('.quote-text .your-say-author').each(function() {
  				if($(this).html().substr($(this).html().length-1, $(this).html().length) == ',') $(this).html($(this).html().substr(0, $(this).html().length-1));
  			});
  		}

		// on the inspiration page can't link the feature image so take the first link and assign it.
		if($('div.inspiration').length > 0) {
			$('div.content-box').each(function() {
				var link = $(this).find('.feature-content').find('a:first');
				if(link.length > 0) {
					var image = $(this).find('.feature-image:first');
					if(image.length > 0) {
						if(link.attr('href').indexOf('youtube') >= 0) 
							image.html('<a href="' + link.attr('href')  + '" rel="shadowbox;width=640;height=385;player=swf;">' + image.html() + '</a>');
						else
							image.html('<a href="' + link.attr('href')  + '" target="_blank">' + image.html() + '</a>');
					}
				}
			});
		}
  	});	
  	
  	var WellnessRealization = {
		init:function() {
			$(".book-reviews").jCarouselLite({
		        btnNext: ".next",
		        btnPrev: ".prev",
		        scroll: 3
		    });
		}
	};
	
})(jQuery);

function addCartItem() {
	var count = $j('#cart .item').length;
	var item = $j('#cart > .item:first').clone();
	item.find('*').each(function() {
		if(typeof($j(this).attr('name')) !== 'undefined' && $j(this).attr('name') !== false)
			if($j(this).attr('name').indexOf('_1')!=-1) 
				$j(this).attr('name', $j(this).attr('name').replace('_1','_'+(count+1)));
				
		if(typeof($j(this).attr('id')) !== 'undefined' && $j(this).attr('id') !== false)
			if($j(this).attr('id').indexOf('_1')!=-1) 
				$j(this).attr('id', $j(this).attr('id').replace('_1','_'+(count+1)));
	});
	$j('#cart').append(item);
	if($j('#cart > .item').length > 1) $j('#remove_item').show();
}

function removeCartItem() {
	$j('#cart > .item:last').remove();
	if($j('#cart > .item').length == 1) $j('#remove_item').hide();
}

function arg(name) {
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return "";
	else
		return results[1];
}

