
// Hover Intent
(function(a){a.fn.hoverIntent=function(k,j){var l={sensitivity:7,interval:100,timeout:0};l=a.extend(l,j?{over:k,out:j}:k);var n,m,h,d;var e=function(f){n=f.pageX;m=f.pageY};var c=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);if((Math.abs(h-n)+Math.abs(d-m))<l.sensitivity){a(f).unbind("mousemove",e);f.hoverIntent_s=1;return l.over.apply(f,[g])}else{h=n;d=m;f.hoverIntent_t=setTimeout(function(){c(g,f)},l.interval)}};var i=function(g,f){f.hoverIntent_t=clearTimeout(f.hoverIntent_t);f.hoverIntent_s=0;return l.out.apply(f,[g])};var b=function(q){var o=(q.type=="mouseover"?q.fromElement:q.toElement)||q.relatedTarget;while(o&&o!=this){try{o=o.parentNode}catch(q){o=this}}if(o==this){return false}var g=jQuery.extend({},q);var f=this;if(f.hoverIntent_t){f.hoverIntent_t=clearTimeout(f.hoverIntent_t)}if(q.type=="mouseover"){h=g.pageX;d=g.pageY;a(f).bind("mousemove",e);if(f.hoverIntent_s!=1){f.hoverIntent_t=setTimeout(function(){c(g,f)},l.interval)}}else{a(f).unbind("mousemove",e);if(f.hoverIntent_s==1){f.hoverIntent_t=setTimeout(function(){i(g,f)},l.timeout)}}};return this.mouseover(b).mouseout(b)}})(jQuery);

// Superfish
(function(a){a.fn.superfish=function(c){var b=a.fn.superfish,h=b.c,n=a(['<span class="',h.arrowClass,'"> &#187;</span>'].join("")),i=function(){var d=a(this),e=j(d);clearTimeout(e.sfTimer);d.showSuperfishUl().siblings().hideSuperfishUl()},k=function(){var d=a(this),e=j(d),g=b.op;clearTimeout(e.sfTimer);e.sfTimer=setTimeout(function(){g.retainPath=a.inArray(d[0],g.$path)>-1;d.hideSuperfishUl();g.$path.length&&d.parents(["li.",g.hoverClass].join("")).length<1&&i.call(g.$path)},g.delay)},j=function(d){d= d.parents(["ul.",h.menuClass,":first"].join(""))[0];b.op=b.o[d.serial];return d};return this.each(function(){var d=this.serial=b.o.length,e=a.extend({},b.defaults,c);e.$path=a("li."+e.pathClass,this).slice(0,e.pathLevels).each(function(){a(this).addClass([e.hoverClass,h.bcClass].join(" ")).filter("li:has(ul)").removeClass(e.pathClass)});b.o[d]=b.op=e;a("li:has(ul)",this)[a.fn.hoverIntent&&!e.disableHI?"hoverIntent":"hover"](i,k).each(function(){e.autoArrows&&a(">a:first-child",this).addClass(h.anchorClass).append(n.clone())}).not("."+ h.bcClass).hideSuperfishUl();var g=a("a",this);g.each(function(l){var m=g.eq(l).parents("li");g.eq(l).focus(function(){i.call(m)}).blur(function(){k.call(m)})});e.onInit.call(this)}).each(function(){var d=[h.menuClass];b.op.dropShadows&&!(a.browser.msie&&a.browser.version<7)&&d.push(h.shadowClass);a(this).addClass(d.join(" "))})};var f=a.fn.superfish;f.o=[];f.op={};f.IE7fix=function(){var c=f.op;a.browser.msie&&a.browser.version>6&&c.dropShadows&&c.animation.opacity!=undefined&&this.toggleClass(f.c.shadowClass+ "-off")};f.c={bcClass:"sf-breadcrumb",menuClass:"sf-js-enabled",anchorClass:"sf-with-ul",arrowClass:"sf-sub-indicator",shadowClass:"sf-shadow"};f.defaults={hoverClass:"sfHover",pathClass:"overideThisToUse",pathLevels:1,delay:800,animation:{opacity:"show"},speed:"normal",autoArrows:true,dropShadows:true,disableHI:false,onInit:function(){},onBeforeShow:function(){},onShow:function(){},onHide:function(){}};a.fn.extend({hideSuperfishUl:function(){var c=f.op,b=c.retainPath===true?c.$path:"";c.retainPath= false;b=a(["li.",c.hoverClass].join(""),this).add(this).not(b).removeClass(c.hoverClass).find(">ul").hide().css("visibility","hidden");c.onHide.call(b);return this},showSuperfishUl:function(){var c=f.op,b=this.addClass(c.hoverClass).find(">ul:hidden").css("visibility","visible");f.IE7fix.call(b);c.onBeforeShow.call(b);b.animate(c.animation,c.speed,function(){f.IE7fix.call(b);c.onShow.call(b)});return this}})})(jQuery);

// Clear Default
(function($){$.fn.clearDefault = function(){return this.each(function(){var default_value = $(this).val();$(this).focus(function(){if ($(this).val() == default_value) $(this).val("");}); $(this).blur(function(){if ($(this).val() == "") $(this).val(default_value);});});};})(jQuery);


jQuery(document).ready(function(){
    current_url = location.href;
    jQuery('#fb-like').html('<iframe src="http://www.facebook.com/plugins/like.php?href='+current_url+'&amp;layout=button_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px; height:21px;" allowTransparency="true"></iframe>');

    jQuery("#q").clearDefault();
    jQuery('#main-nav ul').superfish({
        delay: 1000,
        speed: 'fast',
        autoArrows: false,
        dropShadows: false
    });
    function cb(){
        jQuery.colorbox({
            height: "90%",
            width: "870px",
            href: 'http://www.surveygizmo.com/s/376281/aps-web-survey',
            iframe: true,
            opacity: .6,
            onOpen:function(){ },
            onLoad:function(){ },
            onComplete:function(){ },
            onCleanup:function(){ },
            onClosed:function(){ }
        });
    }
    jQuery('.colorbox').click(function(){
        cb();
        return false;
    });
    jQuery("a[href*='.pdf'], a[rel='external'], a[href^='http']").click(function(){
        if(this.href.indexOf("persweb.connect2amc.com") == -1 && this.href.indexOf("addthis.com") == -1){
            window.open(this.href);
            return false;
        }
    });
    jQuery('#banner').click(function(event){
        event.preventDefault();
        _gaq.push(['_trackEvent', 'APS Meeting Banner', 'Clicked', location.href]);
        setTimeout(function() { self.location=$('#banner')[0].href; }, 500);
    });
    jQuery('#interior-side ul ul a[href="' + location.pathname + '"]').addClass('active');

    // Print Script
    if(location.search.indexOf("print=t") !== -1 || location.hash.indexOf("print=t") !== -1){
        $('body').prepend('<a id="pop-print" href="#" onClick="window.print();return false">Print this Page</a>');
        $('link[media="print"]').attr('media', 'screen, print');
    }
    $('#print').show();
    $('#print a').click(function(){
        var loc = window.location + ( window.location.href.indexOf('?') >= 0 ? '&' : '?') + 'print=t';
        $printwin = window.open(loc, 'printFriendly', 'top=49,left=50,height=400,width=600,location=1,menubar=1,scrollbars=1,resizable=1');
        return false;
    });
});

