//JQuery Setup
$(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) {
		$('#nav li').bind('mouseenter mouseleave', function(){
			$(this).toggleClass('sfhover');
		});	

	  }
	
  	

	// Some effects rely on an element to be initially hidden,
	// but we only hide them if the user has javascript
	$('.jshide').addClass('hide');
	
	// show elements only when javasript is available
	$('.jsshow').addClass('show');
  
  
	//clear form fields
	$('.clearme').one("focus", function() {
		$(this).val("");
	});
  


	// 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 ($('#main').height() > $(window).height()) {
		$('#text').append('<a href="#" class="top-link">Back to the top ^</a>');
	}
  
	$('.sub_nav').prepend('<h3>MORE TOPICS:</h3>');
  
  	$('.text-nav').append('&nbsp;&nbsp;<a href="http://sesamecommunications.com/tothepoint/sesamedesign/" style="color:#fff;">Orthodontic Web Site by Sesame Design &trade;</a>');
  

  var flashModules = {
  
	defaults: {
	  // Define the configuation values applied to each module.
	  // Each module in flashModules can override these values.
	  
	  width: 460,
	  height: 300,
	  wmode: 'transparent',
	  flashvars: {
		autoPlay: 'false', // change value to true to play on start
		thisColor: '0x' + '003d69' // 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: 'logo', config: {width:200, height:203}},
	  {name: 'home', config: {width:780, height:282}},
	  {name: 'braces-diagram', config: {height: 375}},
	  {name: 'brace-painter', config: {height: 430}},
	  {name: 'smartclip', config: {width: 520,height: 390}},
	  
	  {name: 'brushing-and-flossing',
		config: {
		  flashvars: {
			brushing: 'true',
			flossing: 'true',
			autoPlay: 'false'
			}
		}
	  },
	  
	  {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: 'the-damon-system-comparison', config: { width: 250, height: 165}},
	  
	  {name: 'emergency-care',
		config: {
		  flashvars: {
			pokingWire: 'true',
			bracket: 'true',
			looseWire: 'true',
			appliance: 'true',
			headgear: 'true',
			soreness: 'true'
		  }
		}
	  },
	  
	  { name: 'know-your-teeth', config: {width:460, height:400}},
	  
	  {name: 'smile-gallery', 
		config: {
			flashvars: {
				bonding: 'true',
				bridges: 'true',
				crowns: 'true',
				fillings: 'true',
				imlants: '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'
		  }
		}
	  },
	  
	  {name: 'office-tour',
		config: {
		  width: 500,
		  height: 375,
		  flashvars: {
			//set captions for each slide or leave blank if none
			caption01: '',
			caption02: '',
			caption03: '',
			caption04: '',
			caption05: '',
			caption06: '',
			caption07: '',
			caption08: '',
			caption09: ''
			}
		}
	  },

	  {name: 'palatal-expander', config: {width: 200, height: 150}},
	  {name: 'patient-care', config: {height: 375}}
	]
  };

  for (var j=0; j < flashModules.modules.length; j++) {
	var module = flashModules.modules[j];
	// combine default config settings with 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);
  }
  
 var flashVideos = {
					
						defaults: {
						  // Define the configuation values applied to each module.
						  // Each module in flashModules can override these values.
						  
						  'src': 'video/flvPlayer.swf',
						  'dir': 'http://media.sesamehost.com/video/',//location of video and image files
						  '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 
						  }
						},
					
						videos: [
							{name: 'invisalign-best-friends', config: {'width': 320, 'height': 206}},
							{name: 'invisalign-news-travels-fast', config: {'width': 320, 'height': 206}},
							{name: 'invisalign-lobby', config:{}},
							{name: 'the-damon-system',config:{'width': 240, 'height': 206}},
							{name: 'the-damon-system-2',config:{'width': 400, 'height': 330}},
							{name: 'in-ovation',config:{}},
							{name: 'opalescence', config: {'width': 400, 'height': 251}},
							{name: 'invisalign', 
								config: {
									//dir: 'video/',//override location of video and image file
									'width': 360
								}
							},
							{name: 'suresmile', config: {'height': 206}},
							{name: 'suresmile-robot', config: {'height': 242, flashvars: {startImage: 'none', autoStart: 'true'}}}
						]
					};
					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 = vidConfig.dir + video.name + '.flv';
						vidConfig.flashvars.startImage = vidConfig.dir + video.name + '.jpg';
						$('#video-' + video.name).flash(vidConfig, flashVideos.defaults.pluginOptions);
					};
			   
  
		  //PrettyPhoto modal windows
		//---------------------------------------------------------------------------------
		$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		default_width: 900,
		default_height: 700,
		opacity: 0.65, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'transparent', /* Set the flash wmode attribute */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false /* If set to true, only the close button will close the window */
		}); 
		
		// jQuery Cycle Before and After //-------------------------------------------------
		$('#before-after-cycle') // Give this ID a unique name if more than one office tour is needed on a page
		.before('<div class="before-after-nav">') // Ditto for this ID
		.cycle({
		cleartype: true, // true if clearType corrections should be applied (for IE)
		cleartypeNoBg: true, // Set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
		speed: 500, // This controls speed of transition
		timeout: 0, // This controls delay between slides. Set to 0 if more than one office tour on a page, so they don't auto-play
		pager: '.before-after-nav',
		before: function() {
		$('.cycle-detail span').fadeOut(); // Give this ID a unique name if more than one office tour is needed on a page
		},
		after: function(curr, next, opts) {
		var cycle_alt = $(next).find('img').attr('alt'); // This grabs the image alt text
		$('.cycle-detail span').html(cycle_alt).fadeIn(); // This puts alt text into the caption span
		}
		});
  
}); // end function

// game room
$(function() {
  // list the games that we want activated on click
  var games = Array('asteroids', 'frogger', 'pong', 'simon', 'snake', 'space-invaders', 'tetris', 'tic-tac-toe');

  // set the click behavior for a game link
  var setGameClick = function(game){
	$("a." + game).click(function(){
	  $('#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 }
	  );
	});
  };
  
  // loop through the games array and
  // set the click behavior for each game link
  for (var j=0; j<games.length; j++){
	setGameClick(games[j]);
  };
}); // end function

// embeded flash video clips
//$(function() {
//	// define which video files to embed
//	var clips = Array('the-damon-system', 'in-ovation', 'ibraces-1', 'ibraces-2', 'ibraces-3', 'suresmile-1', 'suresmile-2', 'invisalign-best-friends', 'invisalign-lobby', 'invisalign-news-travels-fast');
//	
//	var embedFlashVideo = function(clip, targetDiv){
//	$(targetDiv).flash(
//	  {
//	  src: 'video/flvPlayer.swf',
//	  width: 310,
//	  height: 259,
//	  wmode: 'transparent',
//	  menu: false,
//	  flashvars: {
//		flvToPlay: clip + ".flv", //link is relative to SkinPath, not site root
//		autoStart: "false",
//		startImage: "video/" + clip + ".jpg",//image will be name of movie + .jpg
//		allowFullScreen: "true" //set to false to disable full-screen
//		}
//	  },
//	  { version: 8 }
//	);
//	};
//	
//	// enable each video clip
//	for (var j=0; j<clips.length; j++){
//	var video = clips[j];
//	embedFlashVideo(video, 'div#video-'+ video);
//	};
//});
