//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');
	});	
	//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

	
	//png fix
	//must reference jquery.pngFix1.2.js in order to work
	//$(document).pngFix();

// 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: 475,
			height: 272,
			wmode: 'transparent',
			flashvars: {
				autoPlay: 'false', // change value to 'true' to play on start
				thisColor: '0x' + '858600' // 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:591, height:268}},
	  {name: 'logopage', config: {width:800, height:156}},
	  {name: 'braces-diagram', config: {height: 375,thisColor: 858600}},
	  {name: 'brace-painter', config: {height: 410, wmode:'opaque'}},
	  
	  {name: 'logopage',
	    config: {width:142, height:173,
	      flashvars: {
	        linklogo: 'index.php'
	      }
	    }
	  },
	
	  {name: 'brushing-and-flossing-ortho',
	    config: {
	      flashvars: {
	        brushing: 'true',
	        flossing: 'true'
	      }
	    }
	  },

		{name: 'brushing-dental',
	    config: {
	      flashvars: {
	        brushing: 'true',
	        flossing: 'true'
	      }
	    }
	  },
	  
	  {name: 'flossing-dental',
	    config: {
	      flashvars: {
	        brushing: 'false',
	        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: 'false',
	        soreness: 'true'
	      }
	    }
	  },

	  {name: 'ibraces-logo', config: {width:200, height:135, wmode:'opaque'}},
	  
	  {name: 'know-your-teeth', config: {width:500, height:400}},
	  
	  {name: 'office-tour-belmont',
	    config: {width:500, height:375, wmode:'transparent',
		  flashvars: { 
			caption01: '',
			caption02: '',
			caption03: '',
			caption04: '',
			caption05: '',
			caption06: '',
			caption07: ''
	      }	  
	    }
	  },
	  {name: 'office-tour-gastonia',
	    config: {width:500, height:375, wmode:'transparent',
		  flashvars: { 
			caption01: '',
			caption02: '',
			caption03: '',
			caption04: '',
			caption05: '',
			caption06: '',
			caption07: ''
	      }	  
	    }
	  },
	
	  {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: "false",
	        veneers: "true",
	        whitening: "true"
	      }
	    }
	  },

		{name: 'types-of-appliances',
	    config: {
	      flashvars: {
	        elastics: 'true',
	        headgear: 'false',
	        herbst: 'true',
	        palatal: 'true',
	        positioners: 'true',
	        separators: 'true'
	      }
	    }
	  },

	  {name: 'types-of-braces',
	    config: {
	      flashvars: {
	        metal: 'true',
			gold: 'false',
	        ceramic: 'true',
	        invisible: 'false',
			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 = 'flash/' + 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: 'video/flvPlayer.swf',
		  width: 320,
		  height: 266, // Must add 26px to height to accomodate for the UI controls
		  wmode: '',
		  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: 'swat', config: {}},
			{name: 'smart-clip', config: {}},
			{name: 'ibraces-3', config: {width: 352}},
			{name: 'opalescense', config: {width: 400, height: 251}},
			{name: 'suresmile', config: {height: 206}}
		]
	};
	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.name + '.flv';
		vidConfig.flashvars.startImage = 'video/' + video.name + '.jpg';
		$('#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){
	$("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]);
	};

//Toggle functions
//---------------------------------------------------------------------------------
	
	// Show only when javascript is available
	$('.toggle-link').css('display','block');

	//hide lists first!
	$('#toggle-content li div').css('display','none');	

	//toggle
	function toggleInfoContent(id){
		if($('#' + id).css('display') != 'none'){
		  $('#' + id).hide();
		}else{
		  $("#toggle-content li div").hide();
		  $('#' + id).show();
		}
	}
	$(".toggle-anatomy").click(function(){
	    toggleInfoContent('anatomy-of-a-tooth');
	    return false;
	});
	
	$(".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 ($('#container').height() > $(window).height()) {
		$('.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
	$('.jshide').addClass('hide');
	
	
	//clear form fields
	$('.clearme').one("focus", function() {
			$(this).val("");
	});

	// Open external links in new windows
	$('a[href^="http://"]').not('[href*="orthosesame.com"]').addClass('external').attr('target', '_blank');
	
	// Open pdf links in new windows
	$('a[href$=".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 ('#ID OF CONTAINER') to to the id of the container which holds your email
	/*
	$('#ID OF CONTAINER').jcAntiSpam({
		emailCommonName: '',//Name displayed in link text, e.g., 'Email So-And-So'
		emailName:       '',//First half of primary email address; before "@" symbol
		emailDomain: 	 '',// Full Primary email domain name
		emailCcName: 	 '',//First half of CC email address; before "@" symbol
		emailCcDomain:   ''//CC email domain name
	});
*/
//Form Functions
//---------------------------------------------------------------------------------
	
	//toggle hidden field on Appointment Request Form
	$('#Found').change(function() {
		var selected = $('#Found option:selected');
		if(selected.val() == 'Other') {
			$('#found-other').toggle();
		} else {
			$('#found-other').hide();
		}
	});  
	
	//clear form fields with "clearme" class when clicked
	$('.clearme').one("focus", function() {
			$(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
	$(".date-mask").mask("99/99/9999");
	$(".phone-mask").mask("(999) 999-9999");

	//additional validation methods
	$.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
	$(".validate").each(function() {
		$(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_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
				},
				Patient_Email: {
					required: true,
					email:true
				},
				Contact_Email: {
					required: true,
					email:true
				},
				 Comments_Email: {
					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
				}
			}
		});
	});

});//end document.ready
<!--//--><![CDATA[//><!--
sfHover = function() {
	var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// Hide/Show Div
function ReverseContentDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}



<!--//--><![CDATA[//><!--
sfHover = function() {
	var sfEls = document.getElementById("top-navigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//--><!]]>


//--><!]]>
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // NOTE Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
