/************************************************************************
*   
*   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:  Trevor Saint
*   Date:    9 October 2008
*   Web:     http://www.trevorsaint.com
*   Email:   contact@trevorsaint.com
* 
*************************************************************************/

/*-----------------------------------------------------------------------
Preload CSS Background Images
------------------------------------------------------------------------*/

$(function() {
 //$.preloadCssImages(); 
});

/*-----------------------------------------------------------------------
Form Default Values
------------------------------------------------------------------------*/

$(function() {	   
 $('input[title!=""], select[title!=""], textarea[title!=""]').hint('focus'); 
});

/*-----------------------------------------------------------------------
Featured Clients
------------------------------------------------------------------------*/

$(function() {
	
	$('#feature-clients').cycle({ 
		fx: 'scrollUp',
        timeout: 5000,
		pause: true,
		next: '#fn-next a',
		prev: '#fn-prev a',
        speed:   1100,
        startingSlide: 0
    });
	
});

/*-----------------------------------------------------------------------
Showcase Clients
------------------------------------------------------------------------*/

$(function() {		   
						   
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
     
	$(pager).find('a').removeClass('active') 
        .filter('a:eq('+currSlideIndex+')').addClass('active'); 
    }; 
	
	$('#showcase-clients').cycle({ 
		fx: 'scrollUp',
        timeout: 0,
		pause: true,
		next: '#pn-next a',
		prev: '#pn-prev a',
		height: '367px',
		pager: '#pager-numbers',
        speed:   1100,
        startingSlide: 0
    });
	
    $('#pn-one a').click(function() {$('#showcase-clients').cycle(0); return false;});	
    $('#pn-two a').click(function() {$('#showcase-clients').cycle(1); return false;});
	$('#pn-three a').click(function() {$('#showcase-clients').cycle(2); return false;});
	$('#pn-four a').click(function() {$('#showcase-clients').cycle(3); return false;});
	$('#pn-five a').click(function() {$('#showcase-clients').cycle(4); return false;});
	$('#pn-six a').click(function() {$('#showcase-clients').cycle(5); return false;});
	$('#pn-seven a').click(function() {$('#showcase-clients').cycle(6); return false;});
	$('#pn-eight a').click(function() {$('#showcase-clients').cycle(7); return false;});	
    $('#pn-nine a').click(function() {$('#showcase-clients').cycle(8); return false;});
    $('#pn-ten a').click(function() {$('#showcase-clients').cycle(9); return false;});
	
});

/*-----------------------------------------------------------------------
Selected Client
------------------------------------------------------------------------*/

$(function() {		   
						   
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
     
	$(pager).find('a').removeClass('active') 
        .filter('a:eq('+currSlideIndex+')').addClass('active'); 
    }; 
	
	$('#featured-client').cycle({ 
		fx: 'scrollUp',
        timeout: 0,
		pause: true,
		next: '#pn-next a',
		prev: '#pn-prev a',
		height: '468px',
		pager: '#pager-numbers',
        speed:   1100,
        startingSlide: 0
    });
	
    $('#pn-one a').click(function() {$('#featured-client').cycle(0); return false;});	
    $('#pn-two a').click(function() {$('#featured-client').cycle(1); return false;});
    $('#pn-three a').click(function() {$('#featured-client').cycle(2); return false;});	
    $('#pn-four a').click(function() {$('#featured-client').cycle(3); return false;});
    $('#pn-five a').click(function() {$('#featured-client').cycle(4); return false;});	
    $('#pn-six a').click(function() {$('#featured-client').cycle(5); return false;});
    $('#pn-seven a').click(function() {$('#featured-client').cycle(6); return false;});	
    $('#pn-eight a').click(function() {$('#featured-client').cycle(7); return false;});
    $('#pn-nine a').click(function() {$('#featured-client').cycle(8); return false;});	
    $('#pn-ten a').click(function() {$('#featured-client').cycle(9); return false;});
	
});

/*-----------------------------------------------------------------------
Flash Embed
------------------------------------------------------------------------*/

$(function() {
						   
    $('#frog').flash(
        { src: 'swf/freddy.swf',
          width: 352,
          height: 146,
		  wmode: 'transparent'},
        { version: 8 }
    );
	
});

/*-----------------------------------------------------------------------
Tabbing System
------------------------------------------------------------------------*/

$(function() {

	$(".tab li a").click(function () {
	 
	 $(".tab li a.active").removeClass("active");
	 $(this).addClass("active");
	 
	 $("#content-wrapper div").hide();
	 
	 var content_show = $(this).attr("rel");
	 $("#"+content_show).show();
	 
	 return false;
	 	 	  
	});	

});

/*-----------------------------------------------------------------------
External Website
------------------------------------------------------------------------*/

$(function() {
	$('a.external').click(function() {
		window.open(this.href);
		return false;
	});
});

/*-----------------------------------------------------------------
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();});