;(function($) {
	$.fn.tq_tabview = function(o)	{
		var options = $.extend({}, $.fn.tq_tabview.defaults, o);
		
		return this.each(function() {
			//get metadata if plugin available
			var opts = $.metadata ? $.extend(options, $.metadata.get(this)): options;
			//set initial menu and content display on page load
			var $tabbar = $(this);
			var $container = $('#'+opts.container_id);
			var hash = 'profile';
			if(window.location.href.indexOf('#') >= 0) {
				hash = window.location.href.split('#')[1].toLowerCase();
			}
			if(hash.length && $('#tab_'+hash, $tabbar).length) {
				$('#tab_'+hash, $tabbar).addClass('current');
				$('div#'+opts.container_id+'_'+hash, $container).addClass('current');
			} else {
				$('a:first', $tabbar).addClass('current');
				$('div:first', $container).addClass('current');
			}
			//set events for menu elements
			$('a', $tabbar)
				.click(function(e) {
					e.preventDefault();
					if(!$(this).is('.current') && !$container.is(':animated')) {
						var $this = $(this);
						var hash = $this.attr('href').split('#')[1];
						var $content = $('div#'+opts.container_id+'_'+hash);
						//remove and set menu current classes
						$('a.current', $tabbar).removeClass('current').css({backgroundPosition: '0px 0px'});
						$this.addClass('current').css({backgroundPosition: '0px -24px'});
						$('div.current', $container).removeClass('current');
						$('div#'+opts.container_id+'_'+hash, $container).addClass('current');
					}
				});
		});
	}
	
	$.fn.tq_tabview.defaults = {
		container_id: 'fitness_content'
	};				 
					 
	$(document).ready(function() {
		
		//Payments/////////////////// Price Reporting. Not actual pricing.
		if($('#payment_plan').length != 0)
		{
			
			$('#joinfee').empty().append('$'+$('#join_'+$('#payment_plan').val()).val());
			$('#recurfee').empty().append('$'+$('#recur_'+$('#payment_plan').val()).val());
			$('.plan_contract').empty().append($('#contract_'+$('#payment_plan').val()).val());
				
			$('#payment_plan').change(function () {
				$('#joinfee').empty().append('$'+$('#join_'+$('#payment_plan').val()).val());
				$('#recurfee').empty().append('$'+$('#recur_'+$('#payment_plan').val()).val());
				$('.plan_contract').empty().append($('#contract_'+$('#payment_plan').val()).val());
			});
			
			/*$('#join_form').submit(function (e) 
			{
				return confirm("You will be charged $"+$('#join_'+$('#payment_plan').val()).val()+ " immediatley. With reccuring monthly fees of $"+
								$('#recur_'+$('#payment_plan').val()).val() + "\n\n Pay and join?");
			});*/
		}
		
		
		//Blog///////////////////////
		
		/*$('#the_blog img').each(function () {
			
			if (!($(this).width() <= 75 && $(this).height() <= 75))
			{
				$(this).attr('orig_height', $(this).height());
				$(this).attr('orig_width', $(this).width());
				
				$(this).attr('sml_width', $(this).width()  * (75 / $(this).height()));
				
				$(this).attr('width', $(this).attr('sml_width'));
				$(this).attr('height', 75);
				$(this).addClass('togglableImage');
			}
			else
			{
				$(this).css({"padding":"0px","border":"none","box-shadow":"none"});
			}
			
		});*/
		
		
		
		/*$('#the_blog img.togglableImage').toggle(function () {			
			$(this).animate({ 'height':$(this).attr('orig_height'), 'width':$(this).attr('orig_width') });
			$(this).addClass('largeImage');
			
		}, function () {			
			$(this).animate({ 'height':75, 'width':$(this).attr('sml_width'), 'position':'static' });
			$(this).removeClass('largeImage');				
		});*/
		//////////////////////////////
		
		// set menu events
		$('ul#menu > li > a')
			.click(function(e) {
				if(!$(this).is('.current')) {
					var $this = $(this);
					$this.parent().siblings().children('a').removeClass('current').css({backgroundPosition: '0px 0px'});
					$this.addClass('current').css({backgroundPosition: '0px -32px'});
				}
			})
			.mouseover(function() {
				if(!$(this).is('.current')) {
					$(this).css({backgroundPosition: '0px -32px'});
				}
			})
			.mouseout(function() {
				if(!$(this).is('.current')) {
					$(this).css({backgroundPosition: '0px 0px'});
				}
			});
		// login form initialization
		
		if($('#login_user').val() != '') $('#login_user').css({background: '#FFF'});
		if($('#login_pass').val() != '') $('#login_pass').css({background: '#FFF'});
		$('#login_user').focus(function(e) {
			$(this).css({background: '#FFF'});
		});
		$('#login_pass').focus(function(e) {
			$(this).css({background: '#FFF'});
		});
		// innerfade plugin initialization
		$('#header_middle_slogan').innerfade({
			speed: 2000,
			timeout: 5000,
			type: 'sequence',
			containerheight: '229px',
			children: 'div'
		});
		$('#health_tips').innerfade({
			speed: 1000,
			timeout: 6000,
			type: 'random',
			containerheight: '40px',
			children: 'div'
		});
		// BMI form initialization
		$('#bmi_left').height($('#bmi_right').height());
		$('#bmi_submit').click(function(e) {
			if ($.browser.msie) { return; }
			e.preventDefault();
			feet = Math.abs(parseInt($('#bmi_feet').val() || 0));
			inches = Math.abs(parseInt($('#bmi_inches').val() || 0));
			height = (feet * 12) + inches;
			weight = Math.abs(parseInt($('#bmi_pounds').val() || 0));
			bmi = ((weight * 703) / (height * height)).toFixed(1);
			bmi = isNaN(bmi) || bmi == Infinity ? 0 : bmi;
			$('#bmi_result div.answer').text(bmi);
			if(bmi != 0) {
				$('#bmi_form').toggle();
				$('#bmi_result').toggle();
			}
		});
		$('#bmi_result').click(function(e) {
		  e.preventDefault();
			$('#bmi_form').toggle();
			$('#bmi_result').toggle();														
		});
		// FitnessPrint tab initialization
		$('#fitness_tabs').tq_tabview();
		$('a.popup_link').fancybox({
		  'width' : 700													 
		});
		// Tooltip Initialization
		$.fn.qtip.styles.tipstyle = { // Last part is the name of the style
      width: 300,
			fontSize: '0.8em',
      background: '#49D8BB',
      color: '#333',
      textAlign: 'left',
      border: {
        width: 7,
        radius: 5,
        color: '#23A38B'
      },
      tip: 'bottomLeft',
			title: {
			  fontSize: '0.8em'
			},
      name: 'dark'
    }
		$('a.tooltip').each(function() {
		  $(this).qtip({
					content: {
            text: $('div.tooltip-content', this).html(),
            title: { text: $('div.tooltip-title', this).html() }
          },
          position: { corner: { target: 'topRight', tooltip: 'bottomLeft'}, adjust: { x: 0, y: 0, screen: true } },
          style: 'tipstyle',
          show: { when: 'mouseover', solo: true},
          hide: { when: 'mouseout', fixed: true }
			});				 
	  });
		// other jquery initialization
	});	
})(jQuery);



