//JQuery Setup
$(function(){

//IE6 duct tape
	$('#nav li').bind('mouseenter mouseleave', function(){
			$(this).toggleClass('sfhover');
	});
	$('#subnav li').bind('mouseenter mouseleave', function(){
			$(this).toggleClass('sfhover2');
	});	

	$('.ie-alert-link').click(function() {
		$('#alert').slideToggle("slow");
	});

// ***** Utilities *****
	
// Some effects rely on an element to be initially hidden,
// but we only hide them if the user has javascript
	$('.jshide').addClass('hide');


	
//Clear form fields
	$('.clearme').one("focus", function() {
			$(this).val("");
	});

// Open external links in new windows
	$('a[@href^="http://"]').addClass('external').attr('target', '_blank');

	$('a[@rel^="external"]').addClass('external').attr('target', '_blank');
	
	
	
// Open pdf links in new windows
	$('a[@href$=".pdf"]').addClass('pdf').attr('target', '_blank');
	
// add 'back to top' link when the content is taller than the window
// this has to be done after flash replacement because the content height changes
	if ($('#content').height() > $(window).height()) {
	$('#content').append('<p class="top-link"><a href="#container">Back to top &uarr;</a></p>');
	}

//Teeth for life
	$('.anatomy-of-a-tooth-link').click(function() {
		$('#anatomy-of-a-tooth').slideToggle("slow");
	});
	$('.flash-know-your-teeth-link').click(function() {
		$('#flash-know-your-teeth').slideToggle("slow");
	});
	$('.flash-brushing-and-flossing-link').click(function() {
		$('#flash-brushing-and-flossing').slideToggle("slow");
	});


//Toggle hidden form elements
	$(".toggle-field").change(onSelectChange);
	
//Hide div w/id extra
    $("#schedule-other").css("display","none");
    $("#found-other").css("display","none");

	function onSelectChange(){  
		var selected = $(this);       
		if(selected.val() == 'Other'){  
            //show the hidden field
            $(this).next(".other").css("display","block");
		} else {
			//otherwise, hide it 
            $(this).next(".other").css("display","none");		
		} 
	}



// ***** Game Room *****
	$('ul#sesame-games a').click(function(e){
		var game = $(e.target).attr('class'); // infers the game name from the class of the <a> tag
		// not sure why, but if the link is an image,
		// we have to get the link's class name as the parent of the <img> tag
		game = game ? game : $(e.target).parent().attr('class');
		$('#sesame-game').flash(  // #sesame-game is the empty div that will contain the active game
			{
			src: 'games/' + game + '.swf',
			width: 400,
			height: 300,
			wmode: 'transparent'
			},
			{ version: 8 }
		);
	});

	


// ***** Standard Flash Modules *****
	
	// Define the default configuation values
	// followed by individual module configuration.
	// Values for individual modules will override the defaults
	var flashModules = {
		
		defaults: {			
			width: 500,
			height: 300,
			wmode: 'transparent',
			flashvars: {
				autoPlay: 'false', // change value to 'true'to play on start
				thisColor: '0x' + '254d7c' // change global hex color (default=639CCE)
			},
			pluginOptions: {version: 8}
		},
	
	modules: [
	  // Define the configuration values for each flash module.
	  // Change item values in any 'flashvars' section to false to omit,
	  // Add any value to override the default value in flashModuleDefaults.
	  
	  {name: 'homepage', config: {width:588, height:295}},
	  {name: 'braces-diagram', config: {height: 375}},
	  {name: 'brace-painter', config: {height: 430, wmode:'opaque'}},
	  
	  	
	  {name: 'brushing-and-flossing',
	    config: {
	      flashvars: {
	        brushing: 'true',
	        flossing: 'true'
	      }
	    }
	  },
	  
	  {name: 'color-your-retainer', config: {width: 300, height: 300}},
	  
	  {name: 'common-treatments',
	    config: {
	      flashvars: {
	        crowding: 'true',
	        openbite: 'true',
	        deepOverbite: 'true',
	        missing: 'true',
	        underbite: 'true',
	        spacing: 'true',
	        overbite: 'true',
	        nonBraces: 'true',
	        phaseI: 'true'
	      }
	    }
	  },
	  
	  {name: 'damon-system-comparison', config: {width:250, height:165, wmode:'opaque'}},
	  
	  {name: 'emergency-care',
	    config: {
	      flashvars: {
	        pokingWire: 'true',
	        bracket: 'true',
	        looseWire: 'true',
	        appliance: 'true',
	        headgear: 'true',
	        soreness: 'true'
	      }
	    }
	  },
	  
	  {name: 'ibraces-logo', config: {width:200, height:135, wmode:'opaque'}},
	  
	  {name: 'know-your-teeth', config: {width:500, height:400}},
	  
	  {name: 'office-tour',
	    config: {width:500, height:375,	 
		  flashvars: { 
			caption01: '',
			caption02: '',
			caption03: 'Reception Desk',
			caption04: 'Veterans Stadium Seating',
			caption05: 'Consultation Room',
			caption06: 'Teeth Brushing Station',		  
			caption07: 'X-Ray Station',		  
			caption08: 'Private TX Room',		  
			caption09: 'Ortho Bay',		  
			caption10: ''		  
	      }	  
	    }
	  },
	
	  {name: 'palatal-expander', config: {width: 200, height: 150}},
	  {name: 'patient-care', config: {height: 375}},

		{name: 'smile-gallery',
	    config: {
	      flashvars: {
	        bonding: "true",
	        bridges: "true",
	        crowns: "true",
	        fillings: "true",
	        implants: "true",
	        invisalign: "true",
	        veneers: "true",
	        whitening: "true"
	      }
	    }
	  },
	  
	  {name: 'types-of-appliances',
	    config: {
	      flashvars: {
	        elastics: 'true',
	        headgear: 'true',
	        herbst: 'true',
	        palatal: 'true',
	        positioners: 'true',
	        separators: 'true'
	      }
	    }
	  },
	  
	  {name: 'types-of-braces',
	    config: {
	      flashvars: {
	        metal: 'true',
	        gold: 'false',
	        ceramic: 'true',
	        invisible: 'true',
	        lingual: 'false'
	      }
	    }
	  }
	]
	};
	
	// Loop through the defined modules 
	// and do flash replacement for any that are on the current page
	for (var j = flashModules.modules.length - 1; j >= 0; j--){
		var module = flashModules.modules[j];
		// combine default config settings with individual module config settings
		var modConfig = $.extend({}, flashModules.defaults, module.config);
		// combine default flashvars with module flashvars
		modConfig.flashvars = $.extend({}, flashModules.defaults.flashvars, module.config.flashvars);
		modConfig.src = 'flash/' + module.name + '.swf';
		$('#flash-' + module.name).flash(modConfig, flashModules.defaults.pluginOptions);
	}
  
// ***** Flash Video *****
var flashVideos = {

defaults: {
// Define the configuation values applied to each module.
// Each module in flashModules can override these values.
 
src: 'video/flvPlayer.swf',
width: 320,
height: 266,
wmode: 'transparent',
menu: false,
allowFullScreen: true,
flashvars: {
	autoStart: "false", // change value to true to play on start
	showScaleModes: "false", //set to false to disable scale modes menu
	smoothVideo: "true", //set to false to disable video smoothing 
	allowFullScreen: "true",
	hiddenGui: "true"
 },
 pluginOptions: {version: 9}
},

videos: [
{name: 'the-damon-system',config:{}},
{name: 'in-ovation',config:{}},
{name: 'ibraces-1',config:{}},
{name: 'ibraces-2', config: {width: 352}},
{name: 'ibraces-3', config: {width: 352}},
{name: 'suresmile-01', config: {height: 206}},
{name: 'testimonial-teen', config: {width: 306, height: 180}},
{name: 'testimonial-adult', config: {width: 306, height: 180}}
]
};
for (var j=0; j < flashVideos.videos.length; j++) {
var video = flashVideos.videos[j];
// combine default config settings with module config settings
var vidConfig = $.extend({}, flashVideos.defaults, video.config);
// combine default flashvars with module flashvars
vidConfig.flashvars = $.extend({}, flashVideos.defaults.flashvars, video.config.flashvars);
vidConfig.flashvars.flvToPlay = video.name + '.flv';
vidConfig.flashvars.startImage = 'video/' + video.name + '.jpg';
$('#video-' + video.name).flash(vidConfig, flashVideos.defaults.pluginOptions);
}

// Fancybox Videos =================== >
$("a.fancy-video").fancybox({
	'frameWidth': 420,
	'frameHeight': 236,
	'zoomSpeedIn': 0,
	'zoomSpeedOut': 0,
	'overlayShow': true
});


$('#video-welcome-video').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'welcome-video.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-about-our-office').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'about-our-office.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-adult-treatment').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'adult-treatment.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-testimonials-teen').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'testimonials-teen.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-testimonials-adult').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'testimonials-adult.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-teen-2').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'teen-2.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-teen-5').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'teen-5.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-teen-6').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'teen-6.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-teen-7').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'teen-7.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-teen-8').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'teen-8.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-adult-1').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'adult-1.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-adult-3').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'adult-3.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-adult-4').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'adult-4.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);

$('#video-adult-9').flash(
	{ 
	  src: 'video/flvPlayer.swf',
	  width: 420,
	  height: 236,
	  wmode: 'transparent',
	  flashvars: { 
		flvToPlay: 'adult-9.flv',
		autoStart: 'true',
		scaleMode: 'full',
		hiddenGui: 'true',
		showScaleModes: 'false'
	  }
	},
	{ version: 8 }
);


});//end document.ready