/*
** core.js - PFW Javascript Library
** Crimson Media Lab
**
*/

(function($){

var PFW = {
  
    ondomready: function() {
        PFW.links();
		//PFW.email_obfuscation();
		PFW.backtotop();
        $("hr").replaceWith('<div class="line">&nbsp;</div>');       
    },
	
    links: function() {
       $("#middle-col a,#right-col a,#footer a, #search a").each(function() {
          // comment add .popup class 
          $a = $(this);
          if (this.href && !/mailto/.test(this.href)) {
             if (! /provincetownforwomen.com/.test(this.href)) {$a.addClass("new_window");}
          }
          if (this.className.indexOf("new_window") > -1 ){
              $(this).click(function(){
                 PFW.new_window(this);
                 return false;
              }); 
           }  

       });
       return false;
    },
	
    new_window: function(link) {
        // prevent doubleclicking
        if ($(link).hasClass("clicking")) return;
        $(this).addClass("clicking");
        window.setTimeout(function(){$(this).removeClass("clicking")},500);

        var url = link.href || link;
        var nw = window.open(url, "newwin", 'width=800,height=550,directories=yes,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
        if (nw) {nw.focus();}
    },

    email_obfuscation: function() {
       function reverse(text) {
          return text.split("").reverse().join("");
       }
    
       $("a.to").each(function(i,a) {
          var email;
          if (a.href.indexOf("mailto:") > -1) { email = a.href.replace("mailto:",'') }
          else {email = a.innerHTML};
          email = reverse(email);
          email = email.replace(/\+/,"@");
          email = reverse(email);
          if (a.href.indexOf("mailto") == -1) { a.innerHTML = email };
          a.href = "mailto:"+email;
       });
    
    },
	
    backtotop: function() {
       //var h = document.body.clientHeight;
       //if (h < 1000) { $("#middle-col p a.topofpage").hide() }
       $("#middle-col p a.topofpage").click(function() {
            $('html,body').animate({scrollTop: 0}, 100);
            return false;
            }
       )
    }, 

   last:''
  
}

window.PFW = PFW;

$(document).ready(function(){PFW.ondomready();});

})(jQuery);

