//JQuery Setup
jQuery.noConflict()(function(){
 
//Important functions to fire first!
//-------------------------------------------------------------------------------


  	
  	//IE6 duct tape
  	//detects if browser is IE by checking leadingWhitespace property. 
  	//See: http://docs.jquery.com/Utilities/jQuery.support
	var fancyHover = jQuery.support.leadingWhitespace;
	if(fancyHover == false) {//browser is IE, use script
		jQuery('#nav ul li').bind('mouseenter mouseleave', function(){
			jQuery(this).toggleClass('sfhover');
		});	
	}	
	
	//png fix
	//must reference jquery.pngFix1.2.js in order to work
	jQuery(document).pngFix();
	
	
	//IE6 Upgrade Warning
	//set cookie handler
	var alertBox = jQuery.cookie('ie_alert');
	//if cookie val "noshow" then hide message - user has already seen this message!
	if(alertBox == 'noshow') {
		jQuery('#alert').css('display', 'none');
	}else{
		jQuery('#alert').css('display', 'block');
	}
	
	//click to close behavior
	jQuery('.ie-alert-link').click(function() {
		jQuery('#alert').slideToggle("slow");
		jQuery.cookie('ie_alert', 'noshow', { expires: 14 });
	});
	
	//-- /end ie6 warning


// Utilities
//-------------------------------------------------------------------------------
	
	
// Standard Flash Modules
//-------------------------------------------------------------------------------
	
	// Define the default configuation values
	// followed by individual module configuration.
	// Values for individual modules will override the defaults
	var flashModules = {
		
		defaults: {			
			width: 500,
			height: 300,
			wmode: 'transparent',
			flashvars: {
				autoPlay: 'false', // change value to 'true' to play on start
				thisColor: '0x' + '016a5b' // change global hex color (default=639CCE)
			},
			pluginOptions: {version: 9}
		},
	
	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: 'homepage', config: {width:700, height:270}},
	  {name: 'braces-diagram', config: {height: 375}},
	  {name: 'brace-painter', config: {height: 430, wmode:'opaque'}},
	  
	  {name: 'brushing-and-flossing-ortho',
	    config: {
	      flashvars: {
	        brushing: 'true',
	        flossing: 'true'
	      }
	    }
	  },

		{name: 'brushing-and-flossing-dental',
	    config: {
	      flashvars: {
	        brushing: 'true',
	        flossing: 'true'
	      }
	    }
	  },

		{name: 'clarity', config: {width: 520, height: 390}},

		{name: 'clarity-smart-clip', config: {width: 520, height: 390}},
	  
	  {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: 'damon-system-comparison', config: {width:250, height:165, wmode:'opaque'}},
	  
	  {name: 'emergency-care',
	    config: {
	      flashvars: {
	        pokingWire: 'true',
	        bracket: 'true',
	        looseWire: 'true',
	        appliance: 'true',
	        headgear: 'true',
	        soreness: 'true'
	      }
	    }
	  },

	  {name: 'ibraces-logo', config: {width:200, height:135, wmode:'opaque'}},
	  
	  {name: 'know-your-teeth', config: {width:500, height:400}},
	  
	  {name: 'office-tour',
	    config: {width:500, height:375, wmode:'opaque',
		  flashvars: { 
			caption01: '',
			caption02: '',
			caption03: '',
			caption04: '',
			caption05: '',
			caption06: '',
			caption07: '',
			caption08: '',
			caption09: '',		  
			caption10: '',		  
			caption11: '',
			caption12: '',
			caption13: '',
			caption14: '',
			caption15: '',
			caption16: ''		  
	      }	  
	    }
	  },
	
	  {name: 'palatal-expander', config: {width: 200, height: 150}},
	  {name: 'patient-care', config: {height: 375}},

		{name: 'smile-gallery',
	    config: {
	      flashvars: {
	        bonding: "true",
	        bridges: "true",
	        crowns: "true",
	        fillings: "true",
	        implants: "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: 'true',
	        ceramic: 'true',
	        invisible: 'true',
	        lingual: 'true'
	      }
	    }
	  }

	]
	};
	
	// Loop through the defined modules 
	// and do flash replacement for any that are on the current page
	for (var j = flashModules.modules.length - 1; j >= 0; j--){
		var module = flashModules.modules[j];
		// combine default config settings with individual module config settings
		var modConfig = jQuery.extend({}, flashModules.defaults, module.config);
		// combine default flashvars with module flashvars
		modConfig.flashvars = jQuery.extend({}, flashModules.defaults.flashvars, module.config.flashvars);
		modConfig.src = 'flash/' + module.name + '.swf';
		jQuery('#flash-' + module.name).flash(modConfig, flashModules.defaults.pluginOptions);
	}

// Flash Video functions
//-------------------------------------------------------------------------------

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, // Must add 26px to height to accomodate for the UI controls
		  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 
		  	hiddenGui: "false"
			},
		  pluginOptions: {version: 9}
		},
	
		videos: [
			{name: 'the-damon-system',config:{width: 240, height: 206}},
			{name: 'the-damon-system-2',config:{width: 400, height: 330}},
			{name: 'in-ovation',config:{}},
			{name: 'invisalign',config:{height: 239}},
			{name: 'ibraces-1',config:{}},
			{name: 'ibraces-2', config: {width: 352}},
			{name: 'ibraces-3', config: {width: 352}},
			{name: 'opalescense', config: {width: 400, height: 251}},
			{name: 'suresmile', config: {height: 206}},
			{name: 'testimonial1', config: {width: 400, height: 300}},
			{name: 'testimonial2', config: {width: 400, height: 300}},
			{name: 'office', config: {width: 400, height: 300}},
			{name: 'product', config: {width: 400, height: 300}}
		]
	};
	for (var j=0; j < flashVideos.videos.length; j++) {
		var video = flashVideos.videos[j];
		// combine default config settings with module config settings
		var vidConfig = jQuery.extend({}, flashVideos.defaults, video.config);
		// combine default flashvars with module flashvars
		vidConfig.flashvars = jQuery.extend({}, flashVideos.defaults.flashvars, video.config.flashvars);
		vidConfig.flashvars.flvToPlay = video.name + '.flv';
		vidConfig.flashvars.startImage = 'video/' + video.name + '.jpg';
		jQuery('#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){
	jQuery("a." + game).click(function(){
	  jQuery('#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]);
	};

//Toggle functions
//---------------------------------------------------------------------------------
	
	// Show only when javascript is available
	jQuery('.toggle-link').css('display','block');

	//hide lists first!
	jQuery('#toggle-content li div').css('display','none');	

	//toggle
	function toggleInfoContent(id){
		if(jQuery('#' + id).css('display') != 'none'){
		  jQuery('#' + id).hide();
		}else{
		  jQuery("#toggle-content li div").hide();
		  jQuery('#' + id).show();
		}
	}
	jQuery(".toggle-anatomy").click(function(){
	    toggleInfoContent('anatomy-of-a-tooth');
	    return false;
	});
	
	jQuery(".toggle-teeth").click(function(){
	    toggleInfoContent('flash-know-your-teeth');
	    return false;
	});
	//------
	
	

//Basic HTML functions
//---------------------------------------------------------------------------------

	// 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 (jQuery('#content').height() > jQuery(window).height()) {
		jQuery('.back-to-top').removeClass('hide');
	}
	
	// Some effects rely on an element to be initially hidden,
	// but we only hide them if the user has javascript
	jQuery('.jshide').addClass('hide');
	
	
	//clear form fields
	jQuery('.clearme').one("focus", function() {
			jQuery(this).val("");
	});

	// Open external links in new windows
	jQuery('a[href^="http://"]').not('[href*="orthosesame.com"]').addClass('external').attr('target', '_blank');
	
	// Open pdf links in new windows
	jQuery('a[hrefjQuery=".pdf"]').addClass('pdf').attr('target', '_blank');

	// Anti-spam email obfuscator
	//-- requires <script type="text/javascript" src="http://10.scripts.sesamehost.com/scripts/jquery.jcAntiSpam.js"></script>
	//-- change the ('.my-email-address') to to the class of the container which holds your email
	jQuery('.trevor-email').jcAntiSpam({
	emailCommonName: 'E-mail Trevor',//Name displayed in link text, e.g., 'Email So-And-So'
	emailName: 'trevor',//First half of primary email address; before "@" symbol
	emailDomain: 'comellaortho.com',// Full Primary email domain name
	emailCcName: '',//First half of CC email address; before "@" symbol
	emailCcDomain: ''//CC email domain name
	}); 
	
	jQuery('.joan-email').jcAntiSpam({
	emailCommonName: 'E-mail Joan',//Name displayed in link text, e.g., 'Email So-And-So'
	emailName: 'joan',//First half of primary email address; before "@" symbol
	emailDomain: 'comellaortho.com',// Full Primary email domain name
	emailCcName: '',//First half of CC email address; before "@" symbol
	emailCcDomain: ''//CC email domain name
	}); 
	
	jQuery('.cindy-email').jcAntiSpam({
	emailCommonName: 'E-mail Cindy',//Name displayed in link text, e.g., 'Email So-And-So'
	emailName: 'cindy',//First half of primary email address; before "@" symbol
	emailDomain: 'comellaortho.com',// Full Primary email domain name
	emailCcName: '',//First half of CC email address; before "@" symbol
	emailCcDomain: ''//CC email domain name
	}); 
	
	jQuery('.kerri-email').jcAntiSpam({
	emailCommonName: 'E-mail Kerri',//Name displayed in link text, e.g., 'Email So-And-So'
	emailName: 'kerri',//First half of primary email address; before "@" symbol
	emailDomain: 'comellaortho.com',// Full Primary email domain name
	emailCcName: '',//First half of CC email address; before "@" symbol
	emailCcDomain: ''//CC email domain name
	}); 
	
	jQuery('.fran-email').jcAntiSpam({
	emailCommonName: 'E-mail Fran',//Name displayed in link text, e.g., 'Email So-And-So'
	emailName: 'fran',//First half of primary email address; before "@" symbol
	emailDomain: 'comellaortho.com',// Full Primary email domain name
	emailCcName: '',//First half of CC email address; before "@" symbol
	emailCcDomain: ''//CC email domain name
	}); 
	
	jQuery('.linda-email').jcAntiSpam({
	emailCommonName: 'E-mail Linda',//Name displayed in link text, e.g., 'Email So-And-So'
	emailName: 'linda',//First half of primary email address; before "@" symbol
	emailDomain: 'comellaortho.com',// Full Primary email domain name
	emailCcName: '',//First half of CC email address; before "@" symbol
	emailCcDomain: ''//CC email domain name
	}); 
	
	jQuery('.cathi-email').jcAntiSpam({
	emailCommonName: 'E-mail Cathi',//Name displayed in link text, e.g., 'Email So-And-So'
	emailName: 'cathi',//First half of primary email address; before "@" symbol
	emailDomain: 'comellaortho.com',// Full Primary email domain name
	emailCcName: '',//First half of CC email address; before "@" symbol
	emailCcDomain: ''//CC email domain name
	}); 
	
	jQuery('.jen-email').jcAntiSpam({
	emailCommonName: 'E-mail Jen',//Name displayed in link text, e.g., 'Email So-And-So'
	emailName: 'jen',//First half of primary email address; before "@" symbol
	emailDomain: 'comellaortho.com',// Full Primary email domain name
	emailCcName: '',//First half of CC email address; before "@" symbol
	emailCcDomain: ''//CC email domain name
	}); 


//remote avatar 
jQuery.getScript("http://www.elocallink.tv/zyte/zproc.php?x=Q1ap4x2");
  

//Form Functions
//---------------------------------------------------------------------------------
	
	//toggle hidden field on Appointment Request Form
	jQuery('#Found').change(function() {
		var selected = jQuery('#Found option:selected');
		if(selected.val() == 'Other') {
			jQuery('#found-other').toggle();
		} else {
			jQuery('#found-other').hide();
		}
	});  
	
	//clear form fields with "clearme" class when clicked
	jQuery('.clearme').one("focus", function() {
			jQuery(this).val("");
	});


//Form validation
//---------------------------------------------------------------------------------
	
	//--- requires: 
	//--- <script type="text/javascript" src="http://6.scripts.sesamehost.com/scripts/jquery.validate.js"></script>
	//--- <script type="text/javascript" src="http://7.scripts.sesamehost.com/scripts/jquery.maskedinput-1.2.2.min.js"></script>

	//masked input
	jQuery(".date-mask").mask("99/99/9999");
	jQuery(".phone-mask").mask("(999) 999-9999");

	//additional validation methods
	jQuery.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
	jQuery(".validate").each(function() {
		jQuery(this).validate({
			errorElement: "div",
				success: function(label) {
					label.text("ok!").addClass("success");
				},
			rules: {
				Name: {
					required:true,
					minlength: 5
				},
				Doctor_Name: {
					required:true,
					minlength: 5
				},
				Patient_Name: {
					required:true,
					minlength: 5
				},
				Patient_Email: {
					required: true,
					email:true
				},
				Patient_Patient_Referring: {
					required:true,
					minlength: 5
				},
				Doctor_Patient_Referring: {
					required:true,
					minlength: 5
				},
				Doctor_Email: {
					required: true,
					email:true
				},
				Appointment_Email: {
					required: true,
					email:true
				},
				Email: {
					email:true
				},
				Daytime_Phone: {
					required: true,
					phone: true	
				},
				Patient_Phone: {
					required: true,
					phone: true	
				},
				Message: {
					required:true,
					minlength: 12
				},
				Would_like_to: {
					required: true
				},
				User_Name: {
					required: true
				},
				Password: {
					required: true
				},
				txtNumber: {
					required:true,
					minlength: 5
				}
			}
		});
	});

//prettyPhoto
jQuery("a[rel^='prettyPhoto']").prettyPhoto({
	theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
});



});//end document.ready