//JQuery Setup
$(function(){
 
//Important functions to fire first!
//-------------------------------------------------------------------------------
  	
	//IE6 duct tape
	$('#nav ul li, #utility-nav ul li').bind('mouseenter mouseleave', function(){
		$(this).toggleClass('sfhover');
	});	
	
	//png fix
	$(document).pngFix();
	
	//disable right clicking of images
	$("img").noContext();
	
	//enable smooth scrolling of local links
	$.localScroll();
	
	//hide sub nav items
	$("div#nav li.our-services").hide();
	
	//IE6 Upgrade Warning
	//set cookie handler
	var alertBox = $.cookie('ie_alert');
	//if cookie val "noshow" then hide message - user has already seen this message!
	if(alertBox == 'noshow') {
		$('#alert').css('display', 'none');
		}else{
		$('#alert').css('display', 'block');
	}
	//click to close behavior
	$('.ie-alert-link').click(function() {
		$('#alert').slideToggle("slow");
		$.cookie('ie_alert', 'noshow', { expires: 14 });
	});
	//-- /end ie6 warning

// Anti-spam email obfuscator
//-------------------------------------------------------------------------------
$('a.email').emailProt(); 

// 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: 462,
			height: 277,
			wmode: 'transparent',
			flashvars: {
				autoPlay: 'false', // change value to 'true'to play on start
				thisColor: '0x' + '172F8E' // 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: 'home', config: {width: 502, height: 299}},
	  {name: 'braces-diagram', config: {height: 375}},
	  {name: 'brace-painter', config: {height: 430, wmode:'opaque'}},
	  
	  	
	  {name: 'brushing-and-flossing',
	    config: {
	      flashvars: {
	        brushing: 'true',
	        flossing: 'true'
	      }
	    }
	  },
	  
	  {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:462, height:347, wmode:'transparent',
		  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-videos', 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 = $.extend({}, flashModules.defaults, module.config);
		// combine default flashvars with module flashvars
		modConfig.flashvars = $.extend({}, flashModules.defaults.flashvars, module.config.flashvars);
		modConfig.src = 'swf/' + module.name + '.swf';
		$('#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: 'swf/flv-player.swf',
		  width: 360,
		  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: 'in-ovation',config:{}},
			{name: 'ibraces-1',config:{}},
			{name: 'ibraces-2', config:{}},
			{name: 'ibraces-3', config:{}},
			{name: 'invisalign', config:{}},
			{name: 'suresmile', config: {}},
			{name: 'the-damon-system',config:{}}
		]
	};
	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/' + video.name + '.flv';
		vidConfig.flashvars.startImage = 'video/' + video.name + '.jpg';
		$('#video-' + video.name).flash(vidConfig, flashVideos.defaults.pluginOptions);
	};

//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 ($('body #content').height() > $(window).height()) {
	$('#content').append('<p class="top-link"><a href="#">Back to top &uarr;</a></p>');
	}

	// 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');

});//end document.ready