//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').hover(
      function() {
        $(this).addClass("sfhover");
      },
      function() {
        $(this).removeClass("sfhover");
      }
    );
    // Add other IE6 only code here
  }
	
  
  // 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://"]').not('[href*="orthosesame.com"]').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 ($('#main').height() > $(window).height()) {
    $('.sub_nav').prepend('<a href="#">Back to top ^</a> / ');
  }
  
  $('.text-nav').append('/ <a href="http://sesamecommunications.com/tothepoint/sesamedesign/" class="sesame">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: 500,
      height: 300,
      wmode: 'transparent',
      flashvars: {
        autoPlay: 'false', // change value to true to play on start
        thisColor: '0x' + '662007' // 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:356, height:314}},
      {name: 'braces-diagram', config: {height: 375}},
      {name: 'brace-painter', config: {height: 430}},
      
      {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: 'false',
				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: 'true',
            ceramic: 'true',
            invisible: 'true',
            lingual: 'true'
		  }
        }
      },
      
      {name: 'office-tour',
        config: {
          width: 500,
          height: 375,
          flashvars: {
            //set captions for each slide or leave blank if none
            caption01: 'Allen Street behind Dartmouth Bookstore',
            caption02: 'Reception Hall',
            caption03: 'Waiting Room',
            caption04: 'New Patient Board',
            caption05: 'Consultation Room',
            caption06: 'Consultation Room',
			caption07: 'Main Treatment Room',
			caption08: 'Treatment Station',
			caption09: 'Direct Digital X-Ray'
			}
        }
      },

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

// embeded flash video clips
	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 
		  },
		  pluginOptions: {version: 9}
		},
	
		videos: [
			{name: 'anterior-crossbite-appliance',config:{}},
			{name: 'bite-turbo-appliance',config:{}},
			{name: 'brushing-techniques',config:{width:240}},
			{name: 'class-2-elastic-wear',config:{}},
			{name: 'elastic-tooth-separator',config:{}},
			{name: 'eruption-of-teeth',config:{}},
			{name: 'flossing-with-superfloss',config:{width:240}},
			{name: 'forsus-appliance-direct-push-rod',config:{}},
			{name: 'hyrax-rapid-palatal-expansion-braces-after',config:{}},
			{name: 'hyrax-rapid-palatal-expansion-braces-after-small',config:{width:280}},
			{name: 'impacted-cuspid-palatal-treated',config:{}},
			{name: 'lip-bumper',config:{}},
			{name: 'mandibular-advancement-surgery-lips-closed',config:{}},
			{name: 'mandibular-setback-surgery-lips-closed',config:{}},
			{name: 'tad-canine-retraction-screw-therapy',config:{}},
			{name: 'higgins-xbow-class-2-corrector',config:{}},
			{name: 'tmj-anterior-disc-displacement',config:{}},
			{name: 'the-damon-system',config:{}},
			{name: 'in-ovation',config:{}},
			{name: 'invisalign',config:{}},
			{name: 'ibraces-1',config:{}},
			{name: 'ibraces-2', config: {width: 352}},
			{name: 'ibraces-3', config: {width: 352}},
			{name: 'suresmile-01', 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);
	};


// game room
// 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
        },
        { 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 document.ready
