jQuery(function( $ ){
	
	//borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery.easing.php
	 $.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};
	
	
	$('a.nav').click(function(){
		$.scrollTo( this.hash, 600, {easing:'easeOutQuart'} );
		return false;
	});
	
	// collapseable subnav
	initMenu();
	

	//jquery.cycle - 
	
	$('#sec').cycle({ 
	    fx:     'fade', 
	    speed:  'fast', 
	    timeout: 0,  //don't cycle - wait for trigger
	    next:   '#next', 
    	    prev:   '#prev' ,
	    cleartype:  1, // enable cleartype corrections
	    pager:  '#sub' ,
	    
	    
	    // callback fn that creates a thumbnail to use as pager anchor 
    	    pagerAnchorBuilder: function(idx, slide) { 
		return '#sub li:eq(' + idx + ') a'; 
    	    }
	});

         $('#testimonials').cycle({
             fx:     'fade', 
	    speed:  'slow',
            timeout: 8000,
            cleartype:  1 // enable cleartype corrections
         });
	
});


// LazyLoader - http://www.appelsiini.net/projects/lazyload

$("img").lazyload({ 
     placeholder : "img/grey.gif",
     effect : "fadeIn" 
 });


function initMenu() {
	$('#menu ul').hide();
	$('#menu a:not(.submenu)').click(
		function() {

			var checkElement = $(this).next();
			
			if(checkElement.is(':visible')) {
				return false;
			}
			if(!checkElement.is('ul')) {
				$('#menu ul:visible').slideUp('normal');
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#menu ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}