//JQuery Setup
$(document).ready(function(){

  var flashModColor = '9F7F3B'; //background color for all flash modules
  
  
  //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");
      }
    );
  }
   
   
  // random header image
  $(function() {
    var randomImages = ['group1','group2','group3','group4','group5','group6',];
    var rndNum = 7;
    while(rndNum > 6){
      rndNum = Math.floor(Math.random() * randomImages.length) + 1;
    }
    var rndImage = "images/header-photos/group" + rndNum  +".png";
    
    if ($.browser.msie6){
      rndImage = "images/header-photos/group1.gif";
    }
    
    $("img#rotate").attr({
      src: rndImage
    });
  });


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


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


  // home page flash
  $('#flash_home').flash(
  { 
	  src: 'flash/homepage.swf',
	  width: 530,
	  height: 420,
	  wmode: 'transparent'
	},
	{ version: 8 }
	);
  

  // flash modules
  $('#flash-brushing-and-flossing').flash(
  { 
	  src: 'flash/brushing-and-flossing.swf',
	  width: 500,
	  height: 300,
	  wmode: 'transparent',
    flashvars: { 
			autoPlay: 'false',
      thisColor: '0x' + flashModColor,
      brushing: true,
      flossing: true
		  }
	},
	{ version: 8 }
	);
  
  
  $('#anatomy-of-a-tooth-link').click(function() {
    $('#anatomy-of-a-tooth').toggle();
  });
  
  $('#know-your-teeth').click(function() {
    $('#flash-know-your-teeth').toggle().flash(
      { 
        src: 'flash/know-your-teeth.swf',
        width: 500,
        height: 400,
        wmode: 'transparent'
      },
      { version: 8 }
    );
  });
  
  
  // game room
  $(function() {
    // define which games to activate
    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(
          {
          src: 'games/' + game + '.swf',
          width: 400,
          height: 300,
          wmode: 'transparent'
          },
          { version: 8 }
        );
      });
    };
    
    // set the click behavior for each game
    for (var j=0; j<games.length; j++){
      setGameClick(games[j]);
    };
  });


	// office tour
	$('#flash-office-tour').flash(
		{ 
		  src: 'flash/office-tour.swf',
		  width: 465,
		  height: 345,
		  wmode: 'transparent',
		  flashvars: { 
			//change value to false to pause on start
			autoPlay: 'false',
			//set captions for each slide or leave blank if none
      caption01: "",
      caption02: "",
      caption03: "",
      caption04: "",
      caption05: "",
      caption06: ""
		  }
		},
		{ version: 8 }
	);

});//end document.ready
