/**
 * Sesame Global JavaScript
 * Updated 02/01/2011
 * 
 * All plugin/jquery function additions should be added to the bottom in the below format, within the 'scLocal' var
 *
 * ,COMMON_NAME_OF_LIBRARY_ITEM_TO_BE_INITIALIZED: function() {
 *         YOUR CODE HERE
 *     }
 * } // Add comma here only if you add more rules; the last rule should not have a comma here
 */

var scLocal = (function($) {return {

// Google Analytics
// ---------------------------------------------------------------------------------
    analytics: function() {
        // load dependancies
        $LAB.script('/sesame_scripts/scripts/jquery.geekga-1.2.min.js')
            .wait(function() {
                var gaCode = $('body').attr('data-ga_code'),
                    siteDomain = window.location.hostname;
                $.geekGaTrackPage(gaCode, siteDomain);
        });
    },

// Form Validation
// ---------------------------------------------------------------------------------
    formValidation: function() {
        
        if ($('form.validate').length < 1) {return;}
        
        // Cookie
        $LAB.script('/sesame_scripts/scripts/jquery.cookies.2.2.0.min.js')
            .wait(function() {
                var antiSpamCookie = $.cookies.get('sesamehubsite'),
                    hiddenField = '<input type="hidden" name="sc_form[antispam]" value="'+ antiSpamCookie +'"/>';
                $('form').append(hiddenField);
            });
        
        // Star Rating
        $LAB.script('/sesame_scripts/scripts/jquery-ui-1.8.4.core_widget.js')
            .script('/sesame_scripts/scripts/jquery.ui.stars.min.js')
            .wait(function() {
                var ratingContainer = $('#rating');
                //prepend Rating caption
                $(ratingContainer).prepend('<p class="width1">Your Rating: <span id="rating-label"/>').addClass('js-rate');
                
                $('#rating').stars({
                    captionEl: $("#rating-label")
                });
            });
        
        // Add hidden field to each form for anti-spam
        // Hide all items with class of "hidden-content"
        $('.hidden-option').css('display', 'none');
        
        // Sequential numbering of comment form li's
        $(".sequential-list li").each( function(i) {
            i = i+1;
            $(this).prepend('<span class="comment-number">' + i + '. </span>');
        });
        
        // Toggle hidden fields on Appointment Request Form
        // New Patient Toggle...
        $("input[name^='sc_form[Current_Patient]']").live('click', function() {
            if ($("input[name^='sc_form[Current_Patient]']:checked").val() == 'No') {
                //not current patient, ask where they found us
                $('.hidden-content').fadeIn('slow');
            } else {
                //current patient, hide content
                $('.hidden-content').fadeOut();
                if ($('#found-other').css('display') != 'none') {
                    $('#found-other').fadeOut();
                }
            }
        });
        
        // Date Input
        $(":date").dateinput({
            offset: [-180,108]
        });
        

        // Post Appointment Survey form "May We Contact You" toggle
        $("#Contact_Patient").change(function() {
            
            if ($(this).val() == 'Yes') {
                // not current patient, ask where they found us
                $('#survey_participant').fadeIn('slow', function() {
                    $(this).find('input').removeAttr('disabled').attr('required','required');
                });
            } else { 
                // current patient, hide content
                $('#survey_participant').fadeOut('fast',function() {
                    $(this).find('input').attr('disabled','disabled').removeAttr('required');
                });
            }
        });
    
        // Appointment Request form "Referred by patient" toggle
        $("#Referred_By_Current_Patient").change(function() {
            
            if ($(this).val() == 'Yes') {
                // not current patient, ask where they found us
                $('#referred_by_patient').fadeIn('slow', function() {
                    $(this).find('input').removeAttr('disabled').attr('required','required');
                });
            } else {
                // current patient, hide content
                $('#referred_by_patient').fadeOut('fast',function() {
                    $(this).find('input').attr('disabled','disabled').removeAttr('required');
                });
            }
        });
    
        // Referral form "Radiographs Sent" toggle
        $("input[name^='sc_form[Radiographs_Sent[]]']").live('click', function() {
             if ($("input[name^='sc_form[Radiographs_Sent[]]']:checked").val() == 'Yes') {
                // not current patient, ask where they found us
                $('.hidden-option').fadeIn('slow', function() {
                    $(this).find('input').removeAttr('disabled').attr('required','required');
                });
            } else {
                // current patient, hide content
                $('.hidden-option').fadeOut('fast',function() {
                    $(this).find('input').attr('disabled','disabled').removeAttr('required');
                });
            }
        });
        
        // Form validation
        // ---------------------------------------------------------------------------------
        $('form.validate').validator({ 
            speed: 'fast',
            position: 'bottom left', 
            offset: [7, 18],
            message: '<div class="error box-round box-shadow-large singlepx-shadow-dark"><em/></div>' // em element is the arrow            
        }); 
            
        //extra validation params
        $.tools.validator.fn("[data-equals]", "Value not equal with the $1 field", function(input) {
            var name = input.attr("data-equals"),
                field = this.getInputs().filter("[name=" + name + "]"); 
            return input.val() == field.val() ? true : [name]; 
        });             
        $.tools.validator.fn("[data-minlength]", function(input, value) {
            var min = input.attr("data-minlength");
            
            return value.length >= min ? true : {     
                en: "Please provide at least " +min+ " character" + (min > 1 ? "s" : "")
            };
        });
    },

// PrettyPhoto modal windows
// ---------------------------------------------------------------------------------
    modalWindows: function() {
        
        var $modalLinks = $('a[rel^=prettyPhoto]');
        
        if ($modalLinks.length < 1) {return;}
        
        /*gets plugin then runs function*/
        $LAB.script('/sesame_scripts/scripts/jquery.prettyPhoto.2.5.6.js')
            .wait(function() {
                $modalLinks.prettyPhoto({
                    animationSpeed: 'normal',     // fast/slow/normal
                    default_width: 900,           
                    default_height: 700,          
                    opacity: 0.65,                // Value betwee 0 and 1
                    showTitle: false,             // true/false
                    allowresize: true,            // true/false
                    counter_separator_label: '/', // The separator for the gallery counter 1 "of" 2
                    theme: 'light_rounded',       // light_rounded / dark_rounded / light_square / dark_square / facebook
                    hideflash: false,             // Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto
                    wmode: 'opaque',              // Set the flash wmode attribute
                    autoplay: true,               // Automatically start videos: True/False
                    modal: false                  // If set to true, only the close button will close the window
                });    
            });
    },
    
// Slideshows
// -------------------------------------------------------------------------------
    galleryViewTour: function() {
        
        var $gallery = $('ul#gallery');
        
        if ($gallery.length < 1) {return;}
        
        // jQuery GalleryView Office Tour ----------------------------------------------
        $LAB.script('/sesame_scripts/scripts/jquery.galleryview-2.0.js')
            .script('/sesame_scripts/scripts/jquery.easing.1.3.js')
            .script('/sesame_scripts/scripts/jquery.timers-1.1.2.js')
            .wait(function() {
                //customize me
                $gallery.galleryView({
                    panel_width: 460,
                    panel_height: 350,
                    frame_width: 80,
                    frame_height: 60,
                    transition_speed: 600,
                    easing: 'easeInOutBack',
                    transition_interval: 0,
                    nav_theme: 'dark'
                });
        });
    },
    
// jQuery Cycle Office Tour ----------------------------------------------------
    cycleTour: function() {
        
        var $slideshowContainer = $('#cycle-office-tour');
        
        if ($slideshowContainer.length < 1) {return;} // skip this function if no objects found
        
        // jQuery cycle slideshow
        $LAB.script('/sesame_scripts/scripts/jquery.cycle.2.73.all.min.js')
            .wait(function() {
                // jQuery Cycle Plugin
                $('ul.slideshow').cycle({
                    pause: true,
                    wmode: 'transparent'
                });
            
                // Duplicate the following block of code to add extra office tours
                $slideshowContainer // 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
                        }
                    });
        });
    },

// jQuery Cycle Slideshow (homepage) ----------------------------------------------------
    cycleSlideshow: function() {
        
        var $slideshowContainer = $('#slideshow-home');
        
        if ($slideshowContainer.length < 1) {return;} // skip this function if no objects found
        
        // jQuery cycle slideshow
        $LAB.script('/sesame_scripts/scripts/jquery.cycle.2.73.all.min.js')
            .wait(function() {

                var $firstSlide = $slideshowContainer.find('img'),
                    width = $firstSlide.attr('width'),
                    height = $firstSlide.attr('height'),
                    slideItems = '';

                // add slides to slideshow (images 2-6)
                for (var i = 1; i <= 6; i++) {
                    slideItems += '<img src="/assets/images/slideshow/slide'+i+'.jpg" alt="slide" width="'+width+'" height="'+height+'" />';
                }
                
                $slideshowContainer.append(slideItems);
                     
                // start the slideshow 
                $('.slideshow img:first').fadeIn(1000, function() {
                    $slideshowContainer.cycle({
                        fx:    'fade',
                        pause: false,
                        wmode: 'transparent',
                        height: height,
                        cleartype: false, // 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: 1000, // This controls speed of transition
                        timeout: 0 // This controls delay between slides. Set to 0 if more than one office tour on a page, so they don't auto-play
                    });
                });
        });
    },
    
// jQuery Cycle Before and After -------------------------------------------------
    cycleBeforeAfter: function() {
        
        var $slideshowContainer = $('#before-after-cycle'); // Give this ID a unique name if more than one office tour is needed on a page
        
        if ($slideshowContainer.length < 1) {return;} // skip this function if no objects found
        
        $LAB.script('/sesame_scripts/scripts/jquery.cycle.2.73.all.min.js')
            .wait(function() {
                //customize me
                $slideshowContainer
                    .before('<div class="before-after-nav">') // 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: 0, // This controls delay between slides. Set to 0 if more than one office tour on a page, so they don't auto-play
                        pager:  '.before-after-nav',
                        before: function() {
                            $('.cycle-detail 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 cycle_alt = $(next).find('img').attr('alt'); // This grabs the image alt text
                            $('.cycle-detail span').html(cycle_alt).fadeIn(); // This puts alt text into the caption span
                        }
                    });
        });
    },
    
// jQuery Before After Slider -------------------------------------------------------
    sliderBeforeAfter: function() {
        
        var $sliderContainer = $('#slider-cycle');
        
        if ($sliderContainer.length < 1) {return;}  // skip this function if no objects found
        
        $LAB.script('/sesame_scripts/scripts/jquery.cycle.2.73.all.min.js')
            .script('/sesame_scripts/scripts/jquery.beforeafter.js')
            .script('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js')
            .wait(function() {
                //customize me
                $('.before-after-slider').beforeAfter({
                    animateIntro : false,
                    showFullLinks : false
                });

                // Cycle plugin added to above Slider
                $('#slider-cycle')
                    .before('<div class="slider-nav">')
                    .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: 0, // This controls delay between slides. Set to 0 if more than one office tour on a page, so they don't auto-play
                        pager:  '.slider-nav',
                        before: function() {
                            $('.slider-detail span').fadeOut(); // Give this ID a unique name if more than one office tour is needed on a page
                        },
                        after: function(curr, next, opt) {
                            var slider_alt = $(next).children('.before-after-slider').children('.ui-draggable').siblings().find('img').attr('alt'); // This grabs the image alt text
                            $('.slider-detail span').html(slider_alt).fadeIn(); // This puts alt text into the caption span
                        }
                });
        });
    },
        
// Basic HTML and utility functions
// ---------------------------------------------------------------------------------
    htmlFunctions: function() {
        // Some effects rely on an element to be initially hidden,
        // but we only hide them if the user has javascript
        $('.jshide').addClass('hide');

        // Force #content height to match #sidebar height
        //$("#content").css({'min-height': $("#sidebar").innerHeight()});
        
        // Open external links in new windows
        $('a[href^=http://], a[href^=https://]')
            .not('[href*=login.sesamecommunications.com], a[href$=.doc], a[href$=.pdf]')
            .addClass('external').attr('target', '_blank');
        
        // Open pdf links in new windows + add icon
        $('a[href$=.pdf]').attr('target', '_blank').not('[class*=noicon]').append('<span/>').addClass('pdf');
        
        // Open M$ doc links in new windows + add icon
        $('a[href$=.doc]').attr('target', '_blank').not('[class*=noicon]').append('<span/>').addClass('doc');
        
        // Add icons to links which open in prettyPhoto
        $("a[rel^='prettyPhoto[flash]']").parent('li').append('<span/>').addClass('video-link');

        // Ordered List Style
        $('ol.alpha, ol.numeric').addClass('js');
        $("ol li").each(function (i) {
            $(this).wrapInner('<span/>');
        });
        
        // Toggle functions
        // ---------------------------------------------------------------------------------
        
        // Show only when javascript is available
        $('#toggle-links').css('display', 'block');
        
        // Hide lists first!
        $('#toggle-content dl').hide();
        
        // Toggle
        function toggleInfoContent(id) {
            var $target = $(id);
            if ($target.css('display') != 'none') {
              $target.fadeOut('fast');
              $('.back-to-top').addClass('hide');
            } else {
              $('#toggle-content dl').fadeOut('fast');
              $target.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);
            }
            
            return false;
        });
        
        // Emergency Care toggle ----------------------------------
        // Hide items first
        $('#toggle-emergency div p').hide();
        // Toggle
        function toggleEmergency(id) {
            if ($(id).css('display') != 'none'){
                $(id).animate({opacity: 'toggle'}).parent().animate({width: '80px' ,height: '60px'});
            } else {
                $(id).animate({opacity: 'toggle'}).parent().animate({width: '200px', height: '150px'});
            }
        }
        
        $("a.toggle-div").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') {
                toggleEmergency(id);
            }
            
            return false;
        });
        // end toggle functions
        
        
        // Back to top
        if ($('#bd').height() > $(window).height()) {
            $('.back-to-top').removeClass('hide');
        }
        
        // pt/dr login tooltip functions
        // $('#pt-login-form a, #dr-login-form a').bind('mouseover', function(e){
        //     var target = e.target, // e.target grabs the node that triggered the event.
        //         $target = $(target);  // wraps the node in a jQuery object
        //         $target.animate({opacity: '.65'}, 400).bind('mouseout', function() {
        //             $target.animate({opacity: '1'}, 400);
        //         });
        // });
        
        // iFrame embed for Google Local
        // just create an <a data-js="iframe"> tag with the href to the google local map and this will do the rest
        $('a[data-js=iframe]').each( function(i) {
            //grabs the src of the google map from the href of <a> tag
            var iframeSrc = $(this).attr('href');
            $(this).replaceWith('<iframe src="' + iframeSrc + '" class="map box_shadow box_round"></iframe>');
        });

        
        // Wraps blockquotes in fancy double quotes
        // $('blockquote p').prepend('<span>&ldquo;</span>').append('<span>&rdquo;</span>');
        
        // add fancy tag graphic to this h3
        $('h3.key').each( function() {
            $(this).append('<span class="info"/>');
        });
        
        // fade footer logo IMG
        // $('#logo-invisalign, #logo-ada, #logo-aao').bind({
        //     mouseenter: function() {
        //         $(this).animate({backgroundColor: '#ffffff'},240).children().fadeIn(400);
        //     },
        //     mouseleave: function() {
        //         $(this).animate({backgroundColor: '#e6e6e6'},320).children().fadeOut(160);
        //     }
        // });
    }, //end HTML functions

// Standard Flash and video Modules
//-------------------------------------------------------------------------------
    flashReplacement: function() {
        
        if ($("*[id^=flash-], *[id^=video]").length < 1) {return;} // skip this function if no objects found
        
        /* setup dynamic loading */ 
        $LAB.script('/sesame_scripts/scripts/jquery.flash_1.3.js')
            .wait(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,
                        'src': '/sesame_media/flash/',//default location of all Sesame flash mods
                        'wmode': 'transparent',
                        'flashvars': {
                            'autoPlay': 'false', // change value to 'true'to play on start
                            'thisColor': '0x' + '794B6F' // change global hex color (default=639CCE)
                        },
                        'express': '/sesame_media/flash/playerProductInstall.swf',
                        '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: {
                                'src': 'flash/',//uses local location; default is media.sesamehost.com
                                'width': 540, 
                                'height': 227
                            }
                        },
                        {name: 'braces-diagram', config: {'height': 375}},
                        {name: 'brace-painter', config: {'height': 430, 'wmode':'opaque'}},
                        {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,'flashvars': {'autoPlay': 'true'}}},
                        {name: 'damon-system-comparison', config: {'width':250, 'height':165, 'wmode':'opaque'}},
                        
                        //old emergency care module
                        {name: 'emergency-care',
                            config: {
                                'flashvars': {
                                    'pokingWire': 'true',
                                    'bracket': 'true',
                                    'looseWire': 'true',
                                    'appliance': 'true',
                                    'headgear': 'true',
                                    'soreness': 'true'
                                }
                            }
                        },
                        
                        // Individual Emergency Care Animations -----------------------------------------------
                        {name: 'general-soreness', config: {'width': 200, 'height': 150}},
                        {name: 'headgear', config: {'width': 200, 'height': 150}},
                        {name: 'loose-appliance', config: {'width': 200, 'height': 150}},
                        {name: 'loose-bracket', config: {'width': 200, 'height': 150}},
                        {name: 'loose-wire', config: {'width': 200, 'height': 150}},
                        {name: 'poking-wire', config: {'width': 200, 'height': 150}},
                        
                        {name: 'ibraces-logo', config: {'width': 200, 'height': 135, 'wmode': 'opaque'}},
                        
                        {name: 'know-your-teeth', config: {'width': 500, 'height': 400}},
                        
                        {name: 'office-tour',
                            config: {'width': 500, 'height': 375, 'wmode': 'opaque',
                                'flashvars': { 
                                    'caption01': '',
                                    'caption02': 'Entry way',
                                    'caption03': 'Reception area',
                                    'caption04': 'Coffee tables and chairs',
                                    'caption05': 'Coffee bar',
                                    'caption06': 'Family waiting room',
                                    'caption07': 'Adult waiting room',
                                    'caption08': 'Game room',
                                    'caption09': 'Exam and consultation room',        
                                    'caption10': 'Records room',
                                    'caption11': 'X-ray room',
                                    'caption12': 'Sterilization area',
                                    'caption13': 'Brushing area',
                                    'caption14': 'Open treatment bay'
                                }
                            }
                        },
                        
                        {name: 'palatal-expander', config: {'width': 200, 'height': 150}},
                        {name: 'patient-care',
                            config: {
                                'src': '/sesame_media/flash/',//uses local location; default is /sesame_scripts
                                'height': 375,
                                'flashvars': {
                                    'autoPlay': 'false',
                                    'xmlFile': '/assets/video/videos.xml'//location and name of xml file (e.g., /assets/video/videos.xml) 
                                }
                            }
                        }
                    ]
                };
                
                // 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);
                }
                
                // Flash Video functions
                //-------------------------------------------------------------------------------
                
                var flashVideos = {
                
                    defaults: {
                        // Define the configuation values applied to each module.
                        // Each module in flashModules can override these values.
                        
                        'src': '/sesame_media/video/flvPlayer.swf',
                        'dir': '/sesame_media/video/',//location of video files
                        'img_dir': '/sesame_media/video/',//location of image files
                        'width': 320,
                        'height': 266,
                        '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 
                        }
                    },
                
                    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: 'opalescence', config: {'width': 400, 'height': 251}},
                        {name: 'invisalign', 
                            config: {
                                //dir: '',//leave blank to override location of video
                                //img_dir: 'video/',//override location of image file
                                'width': 360
                            }
                        },
                        {name: 'suresmile', config: {'height': 206}},
                        {name: 'suresmile-robot', 
                            config: {
                                'height': 242, 
                                flashvars: {
                                    startImage: 'none', 
                                    autoStart: 'true'
                                }
                            }
                        },
                        //Invisalign ProPack
                        {name: 'invisalign', config: {'width': 360, 'height': 266}},
                        {name: 'invisalign-best-friends', config: {}},
                        {name: 'invisalign-news-travels-fast', config: {}},
                        {name: 'invisalign-lobby', config:{'width': 320, 'height': 266}}
                    ]
                };
                
                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 = vidConfig.dir + video.name + '.flv';
                    vidConfig.flashvars.startImage = vidConfig.img_dir + video.name + '.jpg';
                    $('#video-' + video.name).flash(vidConfig, flashVideos.defaults.pluginOptions);
                };
        });
    }, //end flashReplacement

// Cufon & FontAvailable Image Replacement Headings
// -------------------------------------------------------------------------------
    // cufon: function() {
    //     // uses @font-face CSS rules first
    //     // only loads if browser doesn't support @font-face
    //     if (Modernizr.fontface) {return;}
    //     
    //     // Cufon + jQuery
    //     // load the cufon library
    //     $LAB.script('/sesame_scripts/scripts/cufon-yui.js').wait()
    //         .script('/assets/js/Humanst521BTRoman_400.font.js')
    //         .wait(function() {
    //             Cufon.replace('h1.headline', {
    //                 fontFamily:'Humanst521BTBold'
    //             });
    //     });
    // },

// Navigation
// -------------------------------------------------------------------------------
    navigation: function() {
        //superfish menus
        $LAB.script('/sesame_scripts/scripts/superfish.js')
            .wait(function() {
                $('#nav>ul, #utility-nav>ul, #logins>ul').superfish({ 
                    hoverClass: 'sfhover',                          //class used by IE for hover effects
                    delay:      240,                                //one second delay on mouseout 
                    animation:  {opacity:'show',height:'show'},     //fade-in and slide-down animation 
                    autoArrows: false,                              //disable generation of arrow mark-up 
                    disableHI:  true                                // set to true to disable hoverIntent detection
                });
        });
    },

// Anti-spam email obfuscator
// -------------------------------------------------------------------------------
    antiSpam: function() {
        
        var $emailLinks = $('a.email');
        
        if ($emailLinks.length < 1) {return;} // skip this function if no objects found
        
        $LAB.script('/sesame_scripts/scripts/jquery.emailProt.js')
            .wait(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                 
                $emailLinks.addClass('addicon').emailProt();
        });
    }

// CUSTOM FUNCTIONS START HERE

    // ,yourFunction: function() {
    //     // Do stuff
    // }

// AND END HERE

};})(jQuery); // end scLocal


// jQuery setup
jQuery(document).ready(function() {
    
    // Automatically calls all functions in scLocal
    for (var i in scLocal) {
        scLocal[i]();
    }
    
    //debug container labels
    if ($('body.debug').length > 0) {
        $('#hd, #bd, #sidebar, #content, #ft').each(function() {
            var elementId = $(this).attr('id');
            $(this).prepend('<code class="element_label">#' + elementId + '</code>');
        });
    }
});
