// Font Replacement
Cufon.replace('#menu a, #side-navigation a, #sub-header ul.tab-navigation li a', { hover: true });
Cufon.replace('#header #menu-tab > a, #header #menu-tab > a span, #header #phone-number, #sub-header span, #middle-column h1, #middle-column h2, #middle-column h3, #middle-column form button.submit, #middle-column form div.uploader button.browse, #right-column .right-nav h3, #right-column .right-nav a, #footer p');

// Encapsulation
(function($) {
	
	// Variables
	var slideSpeed = 500,
		menuHeight = $('#menu > ul').outerHeight(true),
		hoverIntentConfig = {
			over: slideMenu,
			out: slideMenu,
			timeout: 500
		}
	
	// Functions 
	function slideMenu() {
		$('#menu').toggleClass('open').stop(true).animate({
			height: $('#menu').hasClass('open') ? menuHeight : 0
		}, slideSpeed);
	}
	
	// Ready DOM
	$(function() {
		// Gallery items
		$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_square',slideshow:2000, autoplay_slideshow: true});
		$(".gallery a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',slideshow:2000});
			
		// remove no-js class since js will be enabled if this is being run
		$('.no-js').removeClass('no-js');
		
		// Global Navigation
		$('#menu-tab').hoverIntent(hoverIntentConfig);
		$('#menu-tab > a').click(function() { return false; });
		// Uploader
		$('#attachment').change(
			function() {
				$(this).siblings('input').val($(this).val());
			}
		);
		
		$('.yes_no').click(function(){
			if($(this).val() == "1")
			{
				window.location = "https://www.aviaraconnect.com/Login.aspx";
			}
			else if($(this).val() == "2")
			{
				$('.someone').slideDown();
				$('.referred').click(function(){
					if($(this).val() == "1")
					{
						$('.referrer_content').slideDown();
						$('#submit-referred-id').click(function(){
							if($('#rp_id').val() == '')
							{
								$('#rp_id').addClass('error');
							}
							else
							{
								window.location = "https://classic.aviaraconnect.com/memberinfo/signup/joinus.asp?enrollerid=" + $('#rp_id').val() + "&enrollerbid=1";
							}
							return false;
						});
					}
					else if($(this).val() == "2")
					{
						window.location = "https://classic.aviaraconnect.com/memberinfo/signup/joinus.asp?enrollerid=10297&enrollerbid=1";
					}
				});
			}
			return false;
		});
		
		// flash content
		if ($('#flash-content').length > 0) {
			
			var bodyClass = $('body').attr('class'),
				height = $('body').height() - $('#header').height() - $('#footer-wrapper').height();
			
			if (bodyClass != 'health-matrix') {
				$('#flash-content').width($('body').width()).height(height);
				$(window).resize(function() {
					var newHeight = $('body').height() - $('#header').height() - $('#footer-wrapper').height();
					$('#flash-content').width($('body').width()).height(newHeight);
				});
			}
			
			var args = {
				swf: SKIN + '/swf/' + bodyClass + '.swf',
				width: '100%',
				height: '100%',
				hasVersion: 10,
				flashvars: {
					xmlLoc: SKIN + '/xml/' + bodyClass + '.xml'
				}
			}
			
			if ((PARENT == 'lumia' || PARENT == 'somia') && bodyClass == 'health-matrix') {
				$.extend(args,{
					wmode: 'transparent',
					flashvars: {
						xmlLoc: SKIN + '/xml/' + bodyClass + '.xml',
						ingredientType: PARENT
					}
				});				
			}
			
			$('.' + bodyClass + ' #flash-content').flash(args);
			
		}
		
		/* Off-site Links */
		$('a[href^=http]:not([href^=http://' + window.location.host + ']):not([href^=https://' + window.location.host + '])')
			.click(function() {
				window.open($(this).attr('href'), $(this).text());
				return false;
			});
		
		// Collapsible lists
		$('ul.expandable h2')
			.click(function(){
				$(this).toggleClass('open').next().slideToggle('fast');			
			})
	});
	
})(this.jQuery);
