//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) {
			$('#nav li').bind('mouseenter mouseleave', function(){
				$(this).toggleClass('sfhover');
			});	
		// Add other IE6 only code here
		}
  
  // Office Tour Picture Cycle
	$.fn.cycle.defaults.speed   = 900;
	$.fn.cycle.defaults.timeout = 6000;
	
  
	 $('#slideshow-shuffle').cycle({ 
		fx:    'shuffle', 
		delay: -4000,
		before: function() {  
            $('#caption').html(this.alt); 
        } 
	});
  //Slow slide and show
  	$('.anatomy-of-a-tooth-link').click(function() {
		$('#anatomy-of-a-tooth').slideToggle("slow");
	});
	$('.know-your-teeth-link').click(function() {
		$('#flash-know-your-teeth').slideToggle("slow");
	});

	$('.brushing-and-flossing-link').click(function() {
		$('#flash-brushing-and-flossing').slideToggle("slow");
	});
	
	$('.brushing-link').click(function() {
		$('#flash-brushing').slideToggle("slow");
	});
	
	$('.flossing-link').click(function() {
		$('#flash-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");		
		} 
	}  
	
$("button[disabled]").next().text("this button is disabled");
  
  // 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');
  
  // 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()) {
    $('#content').append('<a href="#">Back to top ^</a>');
  }
  
  $.sifr({ 
    font: 'flash/AdobeGaramondProSemiBold.swf', 
    color: '#1a4464',
    textAlign: 'left'});
  $('#content h1').sifr();
 

});//end document.ready

$(function(){

  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' + '116a75' // 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: 'home', config: {width:534, height:271}},
      
      {name: 'brushing-and-flossing',
        config: {
          flashvars: {
            brushing: 'true',
            flossing: 'true',
			autoPlay: 'false'
			}
        }
      },
      
      {name: 'brushing',
        config: {
          flashvars: {
            brushing: 'true',
            flossing: 'false',
			autoPlay: 'false'
			}
        }
      },
	  
      {name: 'flossing',
        config: {
          flashvars: {
            brushing: 'false',
            flossing: 'true',
			autoPlay: 'false'
			}
        }
      },	  
	  
      { 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'
				}
	  		}
		}
    ]
  };

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

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

// embeded flash video clips
$(function() {
	// define which video files to embed
	var clips = Array('');
	
	var embedFlashVideo = function(clip, targetDiv){
	$(targetDiv).flash(
	  {
	  src: 'video/flvPlayer.swf',
	  width: 320,
	  height: 285,
	  wmode: 'transparent',
	  menu: false,
	  flashvars: {
	    flvToPlay: clip + ".flv", //link is relative to SkinPath, not site root
	    autoStart: "false",
	    startImage: 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#content div#video-'+ video);
	};
});
