(function($) {
	// add class functions
	$(function() {
		$('#top-rated .artical-list li:last, #top-read .artical-list li:last').addClass('end');
		$('ul#info-tabs li:last a').addClass('last');
		$('#main-nav .nav-our-products-dd #mega-dd li:nth-child(6n)').addClass('last');
		$('#sub-nav li:first, #checkoutSteps li:first').addClass('first');
		$('#sub-nav li:last, #checkoutSteps li:last').addClass('last');
		$('#quiz tr:even').addClass('odd');
	});
	
	
	// main navigation and search by select dropdowns
	$(function() {
		// main nav drop downs
		$('.main-nav-parent').hover(function() {
			 $(this).children('.main-nav-dropdown-over').slideDown(0);
			 $(this).find('.main-nav-parent-img').attr("src",$(this).find('.main-nav-parent-img').attr("src").replace("-off","-on"));
			 $(this).children('.main-nav-dropdown').slideDown(0);
	 	},function() {
			 $('.main-nav-dropdown-over').slideUp(0);
			 $(this).find('.main-nav-parent-img').attr("src",$(this).find('.main-nav-parent-img').attr("src").replace("-on","-off"));
			 $('.main-nav-dropdown').slideUp(0);
		});
		
		// select drop downs
		$('.select-parent').hover(function() {
			 $(this).children('.select-dropdown-over').slideDown(0);
			 $(this).find('.select-parent-img').attr("src",$(this).find('.select-parent-img').attr("src").replace("-off","-on"));
			 $(this).children('.select-dropdown').slideDown(0);
	 	},function() {
			 $('.select-dropdown-over').slideUp(0);
			 $(this).find('.select-parent-img').attr("src",$(this).find('.select-parent-img').attr("src").replace("-on","-off"));
			 $('.select-dropdown').slideUp(0);
		});
	});
	
	
	// hero slider 
	$(function(){	
		$("#hero-promo-wrap").easySlider({
			auto: true,
			continuous: true,
			numeric: true
		});
	});
	
	
	// anchor scroll
	$(function() {
		$("a.anchor-scroll").anchorAnimate()
	});
	
	jQuery.fn.anchorAnimate = function(settings) {
	
	 	settings = jQuery.extend({
			speed : 1100
		}, settings);	
		
		return this.each(function(){
			var caller = this
			$(caller).click(function (event) {	
				event.preventDefault()
				var locationHref = window.location.href
				var elementClick = $(caller).attr("href")
				
				var destination = $(elementClick).offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
					window.location.hash = elementClick
				});
			  	return false;
			})
		})
	}
	
	
	// top education article and product detail tabs
	$(function() {
		var tabContainers = $('.articles-wrap #article-list-wrap > div, #info-panel-wrap > div');
		
		// hide current panel and fade in the clicked panel
		$('#article-tabs li a, #info-tabs li a').click(function () {
			tabContainers.hide().filter(this.hash).fadeIn(400);
			
			// remove active class and apply to the clicked list item
			$('#article-tabs li a, #info-tabs li a').removeClass('current');
			$(this).addClass('current');
			
			// disables the browser's default action 
			return false;
		
		// shows the first panel on page load
		}).filter(':first').click();
		
		// jumps to reviews tab
		$('#goto-review-tab, #goto-review-tab-stars, #write-review-tab').click(function () {
			tabContainers.hide().filter(this.hash).fadeIn(400);
			
			// remove active class and apply to the reviews tab list item
			$('#info-tabs li a').removeClass('current');
			$('#info-tabs li #reviews-tab').addClass('current');
			if ($(this).attr("id") == "write-review-tab") {
			}
		});

	});
	
	
	// product description tooltip
	$(function() {
		// initialize tooltip
		$("a.image[title]").tooltip({
			// use single tooltip element for all tips
			tip: '#dynatip',
			// one configuration property 
	    	position: "center left", 
			// tweak the position
			offset: [0, 8],
			// use "fade" effect
			effect: 'fade'
			
		// add dynamic plugin 
		}).dynamic( {
			// customized configuration on bottom edge
			bottom: {
				// slide downwards
				direction: 'down',
				// bounce back when closed
				bounce: true
			}
		});
	});
	
	
	// featured customer stories
	$(function() {
		//move he last list item before the first item. The purpose of this is if the user clicks to slide left he will be able to see the last item.
		$('#stories-list li:first').before($('#stories-list li:last')); 
		
		//when user clicks the image for sliding right        
		$('#right-scroll img').click(function() {
		    var item_width = $('#stories-list li').outerWidth() + 10;
		    var left_indent = parseInt($('#stories-list').css('left')) - item_width;
		    $('#stories-list:not(:animated)').animate({'left' : left_indent},500,function() {    
		        $('#stories-list li:last').after($('#stories-list li:first')); 
		        $('#stories-list').css({'left' : '-313px'});
		    }); 
		});
		
		//when user clicks the image for sliding left
		$('#left-scroll img').click(function() {
		    var item_width = $('#stories-list li').outerWidth() + 10;
		    var left_indent = parseInt($('#stories-list').css('left')) + item_width;
		    $('#stories-list:not(:animated)').animate({'left' : left_indent},500,function() {    
			    $('#stories-list li:first').before($('#stories-list li:last')); 
			    $('#stories-list').css({'left' : '-313px'});
		    });
		});
	});
	
	
	// add default text to input fields
	$(function () {
		$('#newsletter, #footer-wrap #newsletter').each(function () {
			if ($(this).val() == '') {
				$(this).val($(this).attr('defaultvalue'));
			}
		}).focus(function () {
			if ($(this).val() == $(this).attr('defaultvalue')) {
				$(this).val('');
			}
		}).blur(function () {
			if ($(this).val() == '') {
				$(this).val($(this).attr('defaultvalue'));
			}
		});
	});
	
	
	// page hierarchy menu
	$(function() {
		$('.cms-menu > li:first').addClass('first');
		$('.cms-menu > li:last').addClass('last');
	});
	
	
	// about renewlife sub menu
	$(function() {
		$('#nested-links').hide();
		$('.cms-about-renewlife #sub-nav .parent #nested-links, .cms-company-history #sub-nav .parent #nested-links, .cms-about-brenda #sub-nav .parent #nested-links, .cms-about-smith #sub-nav .parent #nested-links, .cms-renewlife-mission #sub-nav .parent #nested-links, .cms-the-quality-difference #sub-nav .parent #nested-links, .cms-our-product-selection #sub-nav .parent #nested-links, .cms-clinical-advisory-board #sub-nav .parent #nested-links, .cms-press-releases #sub-nav .parent #nested-links, .cms-jobs #sub-nav .parent #nested-links, .cms-information-for-practitioners #sub-nav .parent #nested-links, .cms-information-for-retailers #sub-nav .parent #nested-links, .cms-international #sub-nav .parent #nested-links').show();
	});
	
	
})(jQuery);

function trackClick(pageName) {
 //do nothing
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+width+', height='+height+', left='+left+', top='+top+', screenX='+left+', screenY='+top+'');
}

