$(document).ready(function() {

	$('#searchTrigger').animPanel({
		target: '#search',
		topStart: '0',
		topEnd: '-70px',
		imgOpen: 'search_trigger.png',
		imgClose: 'search_trigger_close.png'
	});

	//----------- CSS	
	( !$('#contentArea a.ditto_page').length ) ? $('span.ditto_currentpage').css('display','none') : '';
	$('.homeNewsItem:last, #homeServices ul li:last').css('border-bottom','none');

	
	//----------- Slideshow
	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:   1500, 
		timeout: 5000,
		next:   '#next',
		prev:   '#prev',
		before:  onBefore, 
		after:   onAfter
	 });
	
	function onBefore() { 
		$('#slideshow_captions').animate({  
			height: "0"
		}, 500 );
		$('#slideshow_captions').html(""); 	
	} 
	
	function onAfter(curr,next,opts) { 
		if (this.alt != '') {
			$('#slideshow_captions').animate({ 
				height: "30px"
			}, 500 );
			//console.log(opts.slideCount);
			$('#slideshow_captions').append('<span class="slideshow_caption"><strong>' + this.title + '</strong> - <i>' + this.alt + '</i></span>'); 
		}
		if (opts.slideCount==1) {
			$('#slideshow').cycle('stop');
			return false;
		}		
	}

	 
});

$(window).resize(function() {
	
});

$(window).bind("load", function() {						
	$('.loading').hide();
	$('#slideshowWrapper').show();	
});

/*------ Easing animations -----------------------------------------------------*/
(function($) {
	$.easing.custom = function (x, t, b, c, d) { 
		var s = 1.70158;  
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}
	$.easing.easeOutExpo = function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	};
	$.easing.easeOutBounce = function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	};
})(jQuery);
/*------ Animated panel -------------------------------------------------------------*/
(function($) {
	$.fn.animPanel = function(options) {
		var opts = $.extend({}, $.fn.animPanel.defaults, options);
		return this.each(function() {
			$this = $(this);
			var o = $.meta ? $.extend({}, opts, $this.data()) : opts;				
			$this.toggle(function() {
				$(o.target).animate({ top: o.topStart }, 300, "easeOutBounce", function() { 
					$(o.target).find('#searchTrigger img').attr('src','assets/templates/default_tpl/images/'+o.imgClose);	
				});						   
			},function() {
				$(o.target).animate({ top: o.topEnd }, 300, "easeOutBounce", function() { 
					$(o.target).find('#searchTrigger img').attr('src','assets/templates/default_tpl/images/'+o.imgOpen);
				});						   	
			})	
			
		});
	};
})(jQuery);
jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
