/************************************************************************
*   
*   G L O B A L  J A V A S C R I P T  F U N C T I O N S
*   
*   Author:  Damien Wright
*   Date:     January 1, 2009
*   Web:     http://www.mydesignbytes.com
*   Email:   contact@mydesignbytes.com
* 
*************************************************************************/

/*-----------------------------------------------------------------------
Facebox Functions
------------------------------------------------------------------------*/

jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox({
        loading_image: 'http://vac-services.com/images/loading.gif'
      }) 
})

/*-----------------------------------------------------------------------
Preload CSS Background Images
------------------------------------------------------------------------*/

$(function() {
 //$.preloadCssImages(); 
});

/*-----------------------------------------------------------------
Contact Form
------------------------------------------------------------------*/

// apply inline-box only for mozilla
if( jQuery.browser.mozilla ) {
// do when DOM is ready
$( function() {
// search form, hide it, search labels to modify, filter classes nocmx and error
$( 'form.cmxform' ).hide().find( 'p>label:not(.nocmx):not(.error)' ).each( function() {
var $this = $(this);
var labelContent = $this.html();
var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
// create block element with width of label
var labelSpan = $("<span>")
.css("display", "block")
.width(labelWidth)
.html(labelContent);
// change display to mozilla specific inline-box
$this.css("display", "-moz-inline-box")
// remove children
.empty()
// add span element
.append(labelSpan);
// show form again
}).end().show();
});
};

$(document).ready(function() {
$("#contactForm").validate();
});

/*-----------------------------------------------------------------
Spam Protection
------------------------------------------------------------------*/

jQuery.fn.nospam = function(settings) {
settings = jQuery.extend({
replaceText: false, 	// optional, accepts true or false
filterLevel: 'normal' 	// optional, accepts 'low' or 'normal'
}, settings);
	
return this.each(function(){
e = null;
if(settings.filterLevel == 'low') { // Can be a switch() if more levels added
if($(this).is('a[rel]')) {
e = $(this).attr('rel').replace('/', '@').replace('/', '.');
} else {
e = $(this).text().replace('/', '@').replace('/', '.');
}
} else { // 'normal'
if($(this).is('a[rel]')) {
e = $(this).attr('rel').split('').reverse().join('').replace('/', '@').replace('/', '.');
} else {
e = $(this).text().split('').reverse().join('').replace('/', '@').replace('/', '.');
}
}
if(e) {
if($(this).is('a[rel]')) {
$(this).attr('href', 'mailto:' + e);
if(settings.replaceText) {
$(this).text(e);
}
} else {
$(this).text(e);
}
}
});
};

$(function() {$('a.email').nospam();});
