var Site = {
	
	fixIE6: function()
	{
		$.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, adds .sfhover class on rollover
			$('#nav li, #util li').bind('mouseenter mouseleave', function(){
				$(this).toggleClass('sfhover');
			});

			// //IE6 Upgrade Alert
			// //set cookie handler
			// var displayAlertBox = $.cookie('sc_ie_alert');
			// //if cookie val "noshow" then hide message - user has already seen this message!
			// if(displayAlertBox == 'false')
			// {
			// 	$('#ie_alert').css('display', 'none');
			// }
			// else
			// {
			// 	$('#ie_alert').css('display', 'block');
			// }
			// //click to close behavior
			// $('.ie-alert-link').click(function(){
			// 	$('#ie_alert').slideToggle("slow");
			// 	$.cookie('sc_ie_alert', 'false', { expires: 14 });
			// });

			// Add other IE6 only code here
		}
	},
	
	
	utilities: function()
	{
		// 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 (remove '@' for jquery v.1.3 and up)
		$('a[href^="http://"]').addClass('external').attr('target', '_blank');

		// Open pdf links in new windows (remove '@' for jquery v.1.3 and up)
		$('a[href$=".pdf"]').addClass('pdf').attr('target', '_blank');

		// Add 'back to top' link when the content is taller than the window
		if ($('#bd .content').height() > $(window).height()) {
			$('#bd .content').append('<p><a href="#hd">Back to top</a> &uarr;</p>');
		}

		// 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>");
		});
	},


	flashText: function()
	{
		$('.content h1').each(function(){
			var $this = $(this);
			var isLong = $this.hasClass('long');
			var swfFile = isLong ? '-twoline.swf' : '.swf';
			var swfHeight = isLong ? 65 : 30;
			$this.flashtxt(
				{
					src: 'flash/headlines' + swfFile,
					width: 500,
					height: swfHeight
				}
			);
		});
	},


	imageCycle: function()
	{
		$('.slideshow').cycle({
			fx: 'fade'
		});
	},


	flashReplacement: function()
	{
		// 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 trueto play on start
					thisColor: '0x' + '680001' // change global hex color (default=639CCE)
				},
				pluginOptions: {version: 9}
			},

			modules: [
				// Change item values in any 'flashvars' section to false to omit,
				// Add any value to override the default.
				
				{name: 'home', config: {width:594, height:385}},
				{name: 'home-ortho', config: {width:594, height:385}},
				{name: 'home-dental', config: {width:594, height:385}},
				{name: 'braces-diagram', config: {height: 375}},
				{name: 'brace-painter', config: {height: 430}},

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

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

				{name: 'color-your-retainer', config: {width: 300, height: 300}},
				{name: 'clarity', config: {width: 520, height: 390}},
				{name: 'clarity-smart-clip', config: {width: 520, height: 390}},

				{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-ortho',
					config: {
						width: 500,
						height: 375,
						flashvars: {
							caption01: 'Allison Park Office - Reception',
							caption02: 'Allison Park Office - Reception',
							caption03: 'Allison Park Office - Reception',
							caption04: 'Allison Park Office - Wing Chairs',
							caption05: 'Allison Park Office - Play Area',
							caption06: 'Allison Park Office - Clinic Area',
							caption07: 'Allison Park Office - Toothbrushing Station',
							caption08: 'Bridgeville Office - Reception',
							caption09: 'Bridgeville Office - Clinic Area'
						}
					}
				},

				{name: 'office-tour-dental',
					config: {
						width: 500,
						height: 375,
						flashvars: {
							caption01: '',
							caption02: '',
							caption03: '',
							caption04: '',
							caption05: '',
							caption06: '',
							caption07: '',
							caption08: ''
						}
					}
				},

				{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: false,
							ceramic: true,
							invisible: true,
							lingual: false
						}
					}
				}
			]
		};


		// 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 = 'flash/' + module.name + '.swf';
			$('#flash-' + module.name).flash(modConfig, flashModules.defaults.pluginOptions);
		}
		
	},
	
	
	flashVideos: function()
	{
		var flashVideos = {

				defaults: {
				  // Define the configuation values applied to each movie.
				  // 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}}
				]
			};
		// Enable flash video on any div whose id starts with "video-"
		// Infer the name of the video clip from the rest of the id
		// e.g. <div id="video-the-damon-system"> looks for the file "the-damon-system.flv"
		$("div[id^='video-']").flash(null, { version: 8 }, function(opts){
			var $this = $(this);	
			var videoClip = $this.attr('id').replace(/^video-/,'');
			opts.src = 'video/flvPlayer.swf';
			opts.width = 350;
			opts.height = 280;
			opts.wmode = 'transparent';
			opts.menu = false;
			opts.flashvars = {
				flvToPlay: videoClip + ".flv",
				smoothVideo: true,
				showScaleModes: false,
				autoStart: false,
				startImage: "video/" + videoClip + ".jpg",
				allowFullScreen: false
			};
			this.innerHTML = '<div class="alt">' +this.innerHTML+ '</div>';
			$this.addClass('flash-replaced').prepend($.fn.flash.transform(opts));
		});
	},
	
	
	init: function()
	{
		this.fixIE6();
		this.utilities();
		this.imageCycle();
		this.flashText();
		this.flashReplacement();
		this.flashVideos();
	}
	
};

//JQuery Setup
$(document).ready(function(){ Site.init(); });
