


$.fn.replaceAndFadeIn = function(newContentElements) { 
    return this.each(function() { 
        // for each matching element, remove the current contents, hide the element, 
        // append the new contents and then fadeIn the element 
        $(this).empty().hide().append(newContentElements).fadeIn('slow'); 
    }); 
};
   
   



// clear out plugin default styling 
$.blockUI.defaults.css = { width: 200,
	left: '40%',
	top: '40%',
	padding: '4px',
	margin: 0,
	'text-align': 'center',
	backgroundColor: '#394151',
	color: '#fff',
	'font-size': '14px',
	'-webkit-box-shadow': '2px 2px 5px rgba(0, 0, 0, 0.8)',
	'-moz-border-radius': '10px',
	'-webkit-border-radius': '10px',
	'filter': 'alpha(opacity=90)',
	'-moz-opacity': '.90',
	'opacity': '.90'
	};
$.blockUI.defaults.overlayCSS = { backgroundColor: '#FFF', opacity: .5 };


$(function() {



var timeout = 15000;
var blockBackground = '#fff';
var blockOpacity = '0.5';


// home link
$('#logo').livequery('click', function() {
	location.href='/index.php';
});
      
        $('a.load-it').livequery('click', function() {
   			$('#home-page').hide(); 
            var $this = $(this);
			var url = $this.attr('href');
			var page = $this.attr('title');
			url = url +'?a=load&p=' + page;
			//alert(url);
             $('#content').block({ message: '<strong><img src="images/ajax-loader.gif" style="width:16px;height:16px;vertical-align:middle;" alt="Loading" /><br />Loading</strong>',
             			 centerX: false,
             			 centerY: false,
             			 css: { top: '20px', left: '35%' } });
             $.ajax({
                    url:     url,
                    cache:   false,
                    error:   onError,
                    timeout: timeout
             });
            
            return false;
        });
        
        
        $('#home-link').livequery('click', function(){
        	$('#content').hide().empty();
        	$('#home-page').show('slow'); 

        });
        
        
   function onError(xhr, status, e) {
        $.blockUI({ message: '<div id="errorMessage"><h1>'+ errorTitle +'</h1>'+ errorMessage 
            +'<p><button>OK</button></div>' });
        $('button', '#errorMessage').click(function() {
            $.unblockUI({ fadeOut: 0 });
        });
        
    };
     
// Add zoomy

function loadPage(p){
var url = 'loader.php?a=load&p=' + p;
$('#content').block({ message: '<strong><img src="images/ajax-loader.gif" style="width:16px;height:16px;vertical-align:middle;" alt="Loading" /><br />Loading</strong>',
             			 centerX: false,
             			 centerY: false,
             			 css: { top: '20px', left: '35%' } });
             $.ajax({
                    url:     url,
                    cache:   false,
                    error:   onError,
                    timeout: timeout
             });


}

var page = new RegExp('#([a-zA-Z0-9]+)');
var p = (window.location.href.match(page)||[])[1];

if(p)
loadPage(p);



$('div.scrsht a.zoom').livequery(function() {
	$(this).fancybox({'overlayShow': true });
});



var suboptions = {
        target: '#subscribe-results',
		type: 'post',
		clearForm: true
    };
    
     // bind form2 using ajaxSubmit
    $('#subscribe-form').submit(function() {
        // submit the form via ajax
        $(this).ajaxSubmit(suboptions);
        return false;
    });



});


