//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) {
		// hover fix
		$('#nav li').bind('mouseenter mouseleave', function(){
			$(this).toggleClass('sfhover');
		});
		// Add other IE6 only code here
	}
	
	
	// 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://"]').not('[href*="orthodonticassociates.com"]').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 ($('#content').height() > $(window).height()) {
		$('#content').append('<p><a href="#hd">Back to top</a> &uarr;</p>');
	}
	
	$.sifr(
	{
	  font: 'flash/caliban.swf', 
	  color: '#c49446',
	  textAlign: 'left',
	  before: function()
	  {
      $(this).css({
      	'font-size':'30px',
      	'font-weight':'normal',
      	'font-family':'Arial, Helvetica, sans-serif', 
      	'margin-bottom':'20px'
    	});
    }
  });
	$('#content h1').sifr();
	
	// accordion navigation
	$('#nav').accordion({ 
    active: false, 
    header: '.head', 
    navigation: true, 
    fillSpace: false, 
    animated: 'easeslide'
  });
	
	// jQuery Cycle Plugin
	$('.slideshow').cycle({
	pause: true,
	wmode: 'transparent'
	});
	
	// Duplicate the following block of code to add extra office tours
	$('#cycle-office-tour') // Give this ID a unique name if more than one office tour is needed on a page
	.before('<div class="office-tour-nav" id="office-1">') // Ditto for this ID
	.cycle({
	cleartype: true, // true if clearType corrections should be applied (for IE)
	cleartypeNoBg: true, // Set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
	speed: 500, // This controls speed of transition
	timeout: 5000, // This controls delay between slides. Set to 0 if more than one office tour on a page, so they don't auto-play
	pager: '#office-1',
	before: function() {
	$('#caption span').fadeOut(); // Give this ID a unique name if more than one office tour is needed on a page
	},
	after: function(curr, next, opts) {
	var alt = $(next).find('img').attr('alt'); // This grabs the image alt text
	$('#caption span').html(alt).fadeIn(); // This puts alt text into the caption span
	}
	}); 
  
  // homepage testimonials
  $('#testimonials ul').listcycle(3, 5000);
	
	// wrap img.caption in a div and use the title attr as a caption  
	$("#content img.caption").each(function(i) {
		var $img = $(this);
		var caption = $img.attr('title');
		var width = $img.attr('width') + 10;
		$img.wrap('<div class="inset" style="width:'+width+'px;"></div>').after("<p>" + caption + "</p>");
	});



	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' + '006595' // 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: 'homepage', config: {width:570, height:439}},
			{name: 'braces-diagram', config: {height: 375}},
			{name: 'brace-painter', config: {height: 430}},
			
			{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: '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: 'false',
						ceramic: 'true',
						invisible: 'true',
						lingual: 'true'
					}
				}
			},
			
			{name: 'office-tour',
				config: {
					width: 500,
					height: 375
				}
			},

			{name: 'palatal-expander', config: {width: 200, height: 150}},
			{name: 'patient-care-videos', config: {height: 375}}
		]
	};

	for (var j = flashModules.modules.length - 1; j >= 0; 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);
	}
	



	// 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 = games.length - 1; j >= 0; j--){
		setGameClick(games[j]);
	};



// embeded flash video clips

	// 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/flv-player.swf',
			width: 320,
			height: 285,
			wmode: 'transparent',
			menu: false,
			flashvars: {
				SkinPath: "video/SteelExternalAll.swf",
				FLVPath: clip + ".flv" //link is relative to SkinPath, not site root
				}
			},
			{ version: 8 }
		);
	};
	
	// enable each video clip
	for (var j = clips.length - 1; j >= 0; j--){
		var video = clips[j];
		embedFlashVideo(video, 'div#content div#video-'+ video);
	};


});//end document.ready


