//-- Sesame Design Global JavaScript --// 
//-- Created January 25th 2010 --//
//-- Updated 02/17/2010 --/
//----------------------------------------//
//-- All plugin/jquery function additions should be added in the below format, within the 'globalLib' var, then initialized after the jQuery $(function(){
//
//			COMMON_NAME_OF_LIBRARY_ITEM_TO_BE_INITIALIZED :
//			{
//				init : function()
//				{
//					YOUR CODE HERE
//				}
//			} -----Add comma here only if you add more rules; the last rule should not have a comma here	 

var globalLib =
{
//Google Analytics
//---------------------------------------------------------------------------------
	analytics :
	{
		init : function()
		{
			$.xLazyLoader({
				js: 'http://2.scripts.sesamehost.com/scripts/jGoogleAnalytics.min.js',
				name: 'jGoogleAnalytics',
				success: function() {
					//Google Analytics 
					$.jGoogleAnalytics(
						'UA-21827499-1', // Your GA tracker code
						{
							anchorClick: true, // adds click tracking to *all* anchors
							domainName: 'goldcoastsmiles.com', // e.g. 'domain.com'
							pageViewsEnabled: true // can be disabled e.g. if only tracking e.g. click events
						}
					);
				}
			});
		}//end init
	},//end analytics

//preload css images
//---------------------------------------------------------------------------------
	cssImage_preload :
	{
		init : function()
		{
			$.xLazyLoader({
			    js: 'http://15.scripts.sesamehost.com/scripts/jquery.preloadCssImages.min.js',
			    name: 'preloadCssImages',
			    success: function(){
			        $.preloadCssImages();
			    }
			});
		
		}//end init
	},//end image preloader

// Flash Modules
//-------------------------------------------------------------------------------
	flash_functions :
	{
		init : function()
		{
			/* setup dynamic loading */	
			$.xLazyLoader({
			    js: 'http://8.scripts.sesamehost.com/scripts/jquery.flash_1.3.js',
			    name: 'flash',
			    success: function(){
					// Define the default configuation values
					// followed by individual module configuration.
					// Values for individual modules will override the defaults
					
					var flashModules = {
						
						defaults: {
							'src':'flash/',
							'wmode': 'transparent',
							'express': 'http://media.sesamehost.com/flash/playerProductInstall.swf',
							'version': '10',
							'availparams': ['src', 'bgcolor', 'quality', 'allowscriptaccess', 'allowfullscreen', 'flashvars', 'wmode']
						},
					
					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: 'slideshow', 
					  	config: {
					  		'width':630, 
					  		'height':200
					  	}
					  }
					]
					};
					
					// 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 = modConfig.src + module.name + '.swf';
						$('#flash-' + module.name).flash(modConfig);
					}
			    }
			});
		
		}//end flash init
	},//end flash functions

//Basic HTML and utility functions
//---------------------------------------------------------------------------------
	html_functions :
	{
		init : function() 
		{
			// Some effects rely on an element to be initially hidden,
			// but we only hide them if the user has javascript
			$('.jshide').addClass('hide');
			
			// Open external links in new windows
			$('a[href^="http://"], a[href^="https://"]')
				.not('[href*="orthosesame.com"],[href*="sesameinteractive.com"],[href*="goldcoastorthodontics.com"], a[href$=".doc"], a[href$=".pdf"]')
				.addClass('external').attr('target', '_blank');

			//Toggle functions
			//---------------------------------------------------------------------------------
			// Show only when javascript is available
			$('#toggle-links').css('display','block');
			
			//hide lists first!
			$('#toggle-content dl').hide();
			
			//toggle
			function toggleInfoContent(id){
				if($(id).css('display') != 'none'){
				  $(id).fadeOut('fast');
				  $('.back-to-top').addClass('hide');
				}else{
				  $('#toggle-content dl').fadeOut('fast');
				  $(id).fadeIn('slow');
				  $('.back-to-top').removeClass('hide');
				}
			}
			$("#toggle-links").bind('click', function(e) {
				var target = e.target, // e.target grabs the node that triggered the event.
				$target = $(target);  // wraps the node in a jQuery object
				var id = $target.attr('href');
			    if (target.nodeName === 'A') {
					toggleInfoContent(id);
				}
				//commented because links to resources  not accessible
			    //return false;
			});

			//Back to top
			if ($('#content').height() > $(window).height()) {
				$('.back-to-top').removeClass('hide');
			}

		}//end HTML init
	},//end HTML functions

// IE6 Duct Tape	
//-------------------------------------------------------------------------------
	ie_functions :
	{
		init : function()
		{
			//detects if browser is IE by checking leadingWhitespace property. 
			//See: http://docs.jquery.com/Utilities/jQuery.support
			var fancyHover = $.support.leadingWhitespace;
			if(fancyHover === false) 
			{//browser is IE, use script
				$('#nav ul li, #utility-nav ul li').bind('mouseenter mouseleave', function(){
					$(this).toggleClass('sfhover');
				});
				
				//click to close behavior
				if($('.ie-alert-link').length > 0) {
					$.xLazyLoader({
						js: 'http://5.scripts.sesamehost.com/scripts/jquery.cookie.js',
						name: 'cookie',
						success: function() {
							var COOKIE_NAME = 'ie_alert';
							var options = { path: '', expires: 14 };
 
							$('.ie-alert-link').click(function() {
								$('#ie_alert').slideToggle("slow");
								$.cookie(COOKIE_NAME, 'noshow', options);
							});
							//set cookie handler
							var alertBox = $.cookie(COOKIE_NAME);
							//if cookie val "noshow" then hide message - user has already seen this message!
							if(alertBox) {
								$('#ie_alert').css('display', 'none');
							}else{
								$('#ie_alert').css('display', 'block');
							}
						}
					});
				}
				//-- /end ie6 warning
			}//end if/else
		}//end ie init		
	},//end ie_functions

// Navigation
//-------------------------------------------------------------------------------
	navigation :
	{
		init : function()
		{
			//superfish menus
			$.xLazyLoader({
				js: 'http://21.scripts.sesamehost.com/scripts/superfish.js',
				name: 'superfish',
				success: function() {
					$('#nav>ul, #utility-nav>ul, #logins>ul').superfish({ 
						hoverClass:		'sfhover',							//class used by IE for hover effects
						delay:			100,								//one second delay on mouseout 
						speed:			200,								//speed of animation 
						animation:		{opacity:'show'},					//fade-in and slide-down animation 
						autoArrows:		false,								//disable generation of arrow mark-up 
						disableHI:		true								// set to true to disable hoverIntent detection
				    });
				}
			});
		}//end init
	},//end navigation	

// Anti-spam email obfuscator
//-------------------------------------------------------------------------------
	anti_spam :
	{
		init : function()
		{
			$.xLazyLoader({
				js: 'http://12.scripts.sesamehost.com/scripts/jquery.emailProt.js',
				name: 'anti_spam',
				success: function() {
					//Insert empty <a> tag with the following attributes:
					// * class="email"
					// * rel="example|domain.com" where pipe char '|' replaces '@'
					// * title="Email Us", this is the text shown after the email link is created by js					
					$('a.email').emailProt();
				}
			});
		}//end init
	}//end anti-spam

	//YOUR CUSTOM FUNCTIONS START HERE

	//AND END HERE
	
};//end globalLib

//JQuery Setup
$(function(){

//--initialize all required library items
	// LINE: 14
	globalLib.analytics.init(); 
	
	// LINE: 40
	// globalLib.cssImage_preload.init();
	
	// LINE: 500
	globalLib.html_functions.init();

	// LINE: 727
	globalLib.ie_functions.init();

	// LINE: 885
	globalLib.navigation.init(); 

//--YOUR CUSTOM INITIALIZERS GO HERE
//--Add them like this:
//--globalLib.YOURFUNCTIONNAME.init();

//--initialize on-demand library items

	// Flash
	if($("div[id^='flash-']")){//load flash functions
		globalLib.flash_functions.init();
	}
	// Anti-Spam
	if($('a.email').length > 0) {//load Anti-Spam Obfusicator
		globalLib.anti_spam.init();
	}

});//end document.ready
