//JQuery Setup
$(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, #logins 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');
	

//jquery accordion nav

	$('#beforeafter').accordion({
			active: true,
			header: '.head',
			navigation: false,
			fillSpace: false,
			animated: 'easeslide'
		});

	//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');
	

	
//jcIR
 //check if images are enabled then run replacement
 $('<img src="images/welcome.gif'+ '#' + Math.random() + '"/>').load(function() {
  $('.jcir').jcIR({
   image_dir: 'titles',//no slashes
   image_ext: '.gif',//file extention of replacement image
   elem_width: '478',//width of element being replaced
   elem_height: '44'//height of el;ement being replaces
  });
 });
 
	//PNG FIX
	$(document).pngFix(); 

	//hide lists first!
	$('#toggle-content li div').css('display','none');	
	
	//toggle smile gallery
	function toggleInfoContent(id){
	if($('#' + id).css('display') != 'none'){
	 $('#' + id).hide();
	}else{
	 $("#toggle-content li div").hide();
	 $('#' + id).show();
	}
	}
	$(".toggle-bridges").click(function(){
		 toggleInfoContent('flash-bridges');
		 return false;
	});
	
	$(".toggle-crowns").click(function(){
		 toggleInfoContent('flash-crowns');
		 return false;
	});
	
		$(".toggle-crowns-and-bridges").click(function(){
		 toggleInfoContent('flash-crowns-and-bridges');
		 return false;
	});
		
		$(".toggle-crowns-and-veneers").click(function(){
		 toggleInfoContent('flash-crowns-and-veneers');
		 return false;
	});
				
		$(".toggle-implants").click(function(){
		 toggleInfoContent('flash-implants');
		 return false;
	});
								
		$(".toggle-veneers").click(function(){
		 toggleInfoContent('flash-veneers');
		 return false;
	});
	//------
	
	//Teeth for life
	$('.anatomy-of-a-tooth-link').click(function() {
		$('#anatomy-of-a-tooth').slideToggle("slow");
	});
	$('.flash-know-your-teeth-link').click(function() {
		$('#flash-know-your-teeth').slideToggle("slow");
	});
	$('.flash-brushing-and-flossing-link').click(function() {
		$('#flash-brushing-and-flossing').slideToggle("slow");
	});

	//Ortho Dictionary
	$('.parts-of-braces-link').click(function() {
		$('#parts-of-braces').slideToggle("slow");
	});
	$('.ortho-procedures-link').click(function() {
		$('#ortho-procedures').slideToggle("slow");
	});
	

 	//toggle hidden form elements
	$("#Found").change(onSelectChange);
	
	//Hide div w/id extra
    $("#found-other").css("display","none");

	function onSelectChange(){  
		var selected = $("#Found option:selected");       
		if(selected.val() == 'Other'){  
            //show the hidden field
            $("#found-other").show("slow");
		} else {
			//otherwise, hide it 
            $("#found-other").hide("fast");		
		} 
	}  
 
	// wrap img.caption in a div and use the title attr as a caption  
	$("#content img.caption").each(function (i) {
		var $this = $(this);
		var caption = $this.attr('title');
		var width = $this.attr('width') + 10;
		$this.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: 460,
	  height: 276,
	  wmode: 'transparent',
	  flashvars: {
	    autoPlay: 'false', // change value to true to play on start
	    thisColor: '0x' + '2d5f74' // 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:571, height:249}},
	  {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: 'the-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:400, height:320}},
	  
	  {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: 'false'
	      }
	    }
	  },
	  
	  {name: 'office-tour',
	    config: {width:500, height:375,	 
		  flashvars: { 
			caption01: '',
			caption02: '',
			caption03: '',
			caption04: '',
			caption05: '',
			caption06: '',		  
			caption07: '',		  
			caption08: '',		  
			caption09: '',		  
			caption10: ''		  
	      }	  
	    }
	  },
	  
	  	  {name: 'bridges',
	    config: {width:500, height:375,	 
		  flashvars: { 
			caption01: '3 unit bridge to improve color, shape and replace missing front tooth.',
			caption02: 'Worn teeth and lower space corrected with bonded ceramic Maryland bridge.'		  
	      }	  
	    }
	  },
	  
	  	  	  {name: 'crowns',
	    config: {width:500, height:375,	 
		  flashvars: { 
			caption01: 'Badly worn front two teeth corrected with porcelain crowns.',
			caption02: 'Four ceramic crowns correct poor coloration and dark line at the gum.',
			caption03: 'Five ceramic crowns correct poor shape and color, and cover exposed roots.',
			caption04: 'Ceramic crowns repair worn fillings and close space between teeth.',
			caption05: 'Ceramic crowns fix discolored teeth and old fillings.'
	      }	  
	    }
	  },
	  
	  	  	  	  {name: 'crowns-and-bridges',
	    config: {width:500, height:375,	 
		  flashvars: { 
			caption01: 'New ceramic crown and 3 unit bridge improve greatly on color and shape, and replaces missing tooth.',
			caption02: 'New ceramic crown and 3 unit ceramic veneer bridge repair upper front teeth and replace missing tooth.',
			caption03: 'Three unit bridge to improve color, shape and replace missing front tooth.',
			caption04: 'Worn teeth and lower space corrected with bonded ceramic Maryland bridge.',
			caption05: 'Veneers and bridge correct discoloration of teeth and fillings.',
			caption06: 'Discolored front teeth, and missing tooth, corrected with veneers and a bridge.'
	      }	  
	    }
	  },
	  
	  	  	  	  	  {name: 'crowns-and-veneers',
	    config: {width:500, height:375,	 
		  flashvars: { 
			caption01: 'Veneers and crowns on front six teeth correct discolored fillings and teeth.',
			caption02: 'Veneers and crowns correct discolored teeth and fillings.',
			caption03: 'Front teeth, top and bottom, rebuilt with veneers and crowns to repair fillings and discoloration.'			
	      }	  
	    }
	  },
	  
	  	  	  	  	  	  {name: 'implants',
	    config: {width:500, height:375,	 
		  flashvars: { 
			caption01: 'Implant and crown replacing  missing upper right front tooth( lateral incisor).',
			caption02: 'Implants and crown replacing upper front two teeth that were removed.'
	      }	  
	    }
	  },
	  
	  	  	  	  	  	  {name: 'veneers',
	    config: {width:500, height:375,	 
		  flashvars: { 
			caption01: 'Improved shape and color with veneers on the four front teeth. Great aesthetics 8  years later.',
			caption02: 'Veneers reshape and realign worn and tilted edges of bottom three teeth.',
			caption03: 'Veneers correct color and gap of front six teeth. Great aesthetics after 8 years.',
			caption04: 'Veneers fix worn edges of front 4 teeth. Great looking after 8  years.',
			caption05: 'Four veneers correct color, shape and gap.',
			caption06: 'Veneers restore worn edges with natural color and shape',
			caption07: 'Teeth reshaped and lengthened with four veneers.',
			caption08: 'Front six teeth have color and shape improved with 6 veneers.',
			caption09: 'Two veneers correct discoloration and worn edges.',
			caption10: 'Six new veneers show great color and shape.',
			caption11: 'Front six teeth repaired and reshaped with veneers; great look even after 11 years.',
			caption12: 'Top eight teeth had discoloration and space corrected with veneers.',
			caption13: 'Veneers placed to create natural color and close gap on top ten teeth.',
			caption14: 'Five veneers to correct discoloration and gap; looking great 11 years later.'
	      }	  
	    }
	  },
	
	  {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: "video/video-" +  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);
	};
});

// BLOCK
function reverseContentDisplay(div) {
	if(document.getElementById(div).style.display=="none") {
		document.getElementById(div).style.display="block";
	} else {
		document.getElementById(div).style.display="none";}
}

function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
} 