//JQuery Setup
$(document).ready(function(){
 
	// ***** IE6 Duct Tape *****
	$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);
	if ($.browser.msie6) {
		// Hover fix, adds .sfhover class on rollover
		$('#nav li').bind('mouseenter mouseleave', function(){
			$(this).toggleClass('sfhover');
		});
		// Add other IE6 only code here
	}
	
	// ***** 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 (remove '@' for jquery v.1.3 and up)
	$('a[href^="http://"]').addClass('external').attr('target', '_blank');
	
	// Open pdf links in new windows (remove '@' for jquery v.1.3 and up)
	$('a[href$=".pdf"]').addClass('pdf').attr('target', '_blank');

	// Add 'back to top' link when the content is taller than the window
	if ($('#content').height() > $(window).height()) {
		$('#content').append('<p class="back-to-top"><a href="#hd">Back to top</a> &uarr;</p>');
	}
	
	$('#anatomy-of-a-tooth-link').click(function() {
    $('#anatomy-of-a-tooth').toggle();
  });
  
  $('#know-your-teeth').click(function() {
    $('#flash-know-your-teeth').toggle();
  });
	
	// ***** 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' + '0060aa' // change global hex color (default=639CCE)
			},
			pluginOptions: {version: 8}
		},
		
		modules: [
			// Change item values in any 'flashvars' section to false to omit,
			// Add any value to override the default.
			
			{name: 'homepage', config: {width:562, height:256}},
			
			{name: 'brushing-and-flossing-ortho',
			config: {
			  flashvars: {
				brushing: 'true',
				flossing: 'true'
			  }
			}
		  },
		  {name: 'brace-painter', config: {height: 430, wmode:'opaque'}},
		  
		  {name: 'common-treatments',
			config: {
			  flashvars: {
				crowding: 'true',
				openbite: 'true',
				deepOverbite: 'true',
				missing: 'true',
				underbite: 'true',
				spacing: 'true',
				overbite: 'true',
				nonBraces: 'true',
				phaseI: 'true'
			  }
			}
		  },
	
			{name: 'office-tour',
				config: {width:500, height:375, wmode:'opaque',
				  flashvars: { 
					caption01: 'Reception Lobby',
					caption02: 'Office Lobby',
					caption03: 'Game Area',
					caption04: 'Toothbrushing Center',
					caption05: 'New Patient Room',
					caption06: 'Adult Room',
					caption07: 'Operatory Room',
					caption08: 'Operatory Room',
					caption09: 'Records Room',		  
					caption10: 'X-Ray Area',		  
					caption11: 'Patient Bulletin Boards',
					caption12: 'Prize Case',
					caption13: '',
					caption14: '',
					caption15: '',
					caption16: ''		  
				  }	  
				}
			  },
			  {name: 'patient-care', config: {height: 375}},
			  
			  {name: 'emergency-care',
				config: {
				  flashvars: {
					pokingWire: 'true',
					bracket: 'true',
					looseWire: 'true',
					appliance: 'true',
					headgear: 'true',
					soreness: 'true'
				  }
				}
			  },

			{name: 'smile-gallery',
				config: {
					flashvars: {
						bonding: "true",
						bridges: "true",
						crowns: "true",
						fillings: "true",
						implants: "true",
						invisalign: "true",
						veneers: "true",
						whitening: "true"
					}
				}
			}
		]
	};
	
	// Flash Video functions
//-------------------------------------------------------------------------------

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, // Must add 26px to height to accomodate for the UI controls
		  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 
		  	hiddenGui: "false"
			},
		  pluginOptions: {version: 9}
		},
	
		videos: [
			{name: 'the-damon-system',config:{width: 240, height: 206}},
			{name: 'the-damon-system-2',config:{width: 400, height: 330}},
			{name: 'in-ovation',config:{}},
			{name: 'invisalign',config:{height: 239}},
			{name: 'ibraces-1',config:{}},
			{name: 'ibraces-2', config: {width: 352}},
			{name: 'ibraces-3', config: {width: 352}},
			{name: 'opalescense', config: {width: 400, height: 251}},
			{name: 'suresmile', config: {height: 206}}
		]
	};
	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);
	};
	

	// 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);
	}

});//end document.ready