//JQuery Setup
$(function(){
 
	
  //IE6 duct tape
	$('#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');
  
  
	//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');

	//form validation
	//additional methods
	$.validator.addMethod("phone", function(phone_number, element) {
	    phone_number = phone_number.replace(/\s+/g, ""); 
		return this.optional(element) || phone_number.length > 9 &&
			phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
	}, "Please specify a valid phone number");

	//validator
	$(".validate").each(function() {
		$(this).validate({
			errorElement: "div",
				success: function(label) {
					label.text("ok!").addClass("success");
				},
			rules: {
				Patient_Date: {
					date: true
				},
				Doctor_Date: {
					date: true
				},
				Name: {
					required:true,
					minlength: 5
				},
				Doctor_Name: {
					required:true,
					minlength: 5
				},
				Patient_Name: {
					required:true,
					minlength: 5
				},
				Patient_Patient_Referring: {
					required:true,
					minlength: 5
				},
				Doctor_Patient_Referring: {
					required:true,
					minlength: 5
				},
				Doctor_Email: {
					required: true,
					email:true
				},
				Email: {
					required: true,
					email:true
				},
				Daytime_Phone: {
					required: true,
					phone: true	
				},
				Patient_Phone: {
					required: true,
					phone: true	
				},
				Message: {
					required: true,
					minlength: 10
				},
				txtNumber: {
					required:true,
					minlength: 5
				}
			},
			messages: {
				Name: "Enter your full name.",
				Email: "Enter a valid email address",
				Message: "Enter a message"
			}
		});
	});
  


  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' + '015289' // 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:501, height:231}},
      {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: 'false',
            gold: 'true',
            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: 'before-and-after',
        config: {
          width: 500,
          height: 375,
          flashvars: {
            //set captions for each slide or leave blank if none
            caption01: 'Patient 1 Before',
            caption02: 'Patient 1 After',
            caption03: 'Patient 2 Before',
            caption04: 'Patient 2 After',
            caption05: 'Patient 3 Before',
            caption06: 'Patient 3 After',
			caption07: 'Patient 4 Before',
			caption08: 'Patient 4 After',
			caption09: 'Patient 5 Before',
			caption10: 'Patient 5 After',
			caption11: 'Patient 6 Before',
			caption12: 'Patient 6 After',
			caption13: 'Patient 7 Before',
			caption14: 'Patient 7 After'
			}
        }
      },
      {name: 'patient-comments',
        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: '',
			caption10: '',
			caption11: ''
			}
        }
      },

      {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);
  }
  
});

// 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]);
  };
});

// 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');
	
	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#text div#video-'+ video);
	};
});
