
$(document).ready( function()
{
	$('input[name=subscribe_text]').inputFieldText(' Insert your email, and hit send'); 	 	
	$('input[name=search_text]').inputFieldText('Search Typefaces'); 	 	
	
	 PEPS.rollover.init();
	 
	//LOADING POPUP
	//Click the button event!
	$("#shareButton").click(function()
	{
		centerPopup();
		loadPopup();
	});
	
	//CLOSING POPUP
	//Click the x event!
	$("#share_close").click(function()
	{
		disablePopup();
	});
	//Click out event!
	$("#share_background").click(function()
	{
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e)
	{
		if(e.keyCode==27 && popupStatus==1)
		{
		disablePopup();
		}
	});
	 
});


PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();
     
      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/_o\./, '.');
   }
};


jQuery.fn.inputFieldText = function(string) 
{          
    this.each(function() { 
        $(this).val(string); 
        $(this).focus(function(){ 
            if ($(this).val() == string){ 
                $(this).val(''); 
            } 
        }); 
        $(this).blur(function(){ 
            if ($(this).val() == '' ){ 
                $(this).val(string); 
            } 
        });     
    }); 
} 


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

function loadPopup()
{
	//loads popup only if it is disabled
	if(popupStatus==0)
	{
		$("#share_background").css({"opacity": "0.7"});
		$("#share_background").fadeIn("fast");
		$("#share_page_display").fadeIn("fast");
		popupStatus = 1;
	}
}

function disablePopup()
{
//disables popup only if it is enabled
	if(popupStatus==1)
	{
		$("#share_background").fadeOut("slow");
		$("#share_page_display").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup()
{
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#share_page_display").height();
	var popupWidth = $("#share_page_display").width();

	$("#share_page_display").css({"position": "absolute","top": windowHeight/2-popupHeight/2,"left": windowWidth/2-popupWidth/2});
	//only need force for IE6
	$("#share_background").css({"height": windowHeight});
}






