$(function () {
	
	$.ajaxSetup({
		async:false,
		cache:false
	});
	
	$('a').click(function(){
		$(this).blur();
	})
	
	//Image slideshow
	if ( $("#slides-outer").length > 0 ) {
		var slideLink = "";
		$('#slides-outer').cycle({ 
			fx: 'scrollUp',
			timeout: 6000,
			pause: true,
			pager: '#slide-nav',
			pauseOnPagerHover: true,
			before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
				$('#slides-frame').unbind().bind('click', function(){
					window.location = nextSlideElement.href;
				});
			}
		});
		/*$('a.slide-pause').toggle(function(e) {
			e.preventDefault();
			$('#slides-outer').cycle('pause');
			$(this).addClass('slide-pause-on');
		}, function(e) {
			e.preventDefault(e);
			$('#slides-outer').cycle('resume', true);
			$(this).removeClass('slide-pause-on');
		})*/
	}
	
	//Text Cycle
	if ($("#cycle-outer").length > 0) {	
		$('#cycle-outer').cycle({ 
			fx: 'fade',
			timeout: 6000
		});
	}
	
	//Image slideshow
	if ( $("#gallery-outer").length > 0 ) {
		$('#gallery-outer').cycle({ 
			fx: 'fade',
			next: '#gallery-next', 
			prev: '#gallery-prev',
			timeout: 6000
		});
	}

	$('.ellipsis span').ellipsis();
	
});


(function($) {
	$.fn.ellipsis = function(enableUpdating){
		var s = document.documentElement.style;
		if (!('textOverflow' in s || 'OTextOverflow' in s)) {
			return this.each(function(){
				var el = $(this);
				if(el.css("overflow") == "hidden"){
					var originalText = el.html();
					var w = el.width();
					
					var t = $(this.cloneNode(true)).hide().css({
                        'position': 'absolute',
                        'width': 'auto',
                        'overflow': 'visible',
                        'max-width': 'inherit'
                    });
					el.after(t);
					
					var text = originalText;
					while(text.length > 0 && t.width() > el.width()){
						text = text.substr(0, text.length - 1);
						t.html(text + "...");
					}
					el.html(t.html());
					
					t.remove();
					
					if(enableUpdating == true){
						var oldW = el.width();
						setInterval(function(){
							if(el.width() != oldW){
								oldW = el.width();
								el.html(originalText);
								el.ellipsis();
							}
						}, 200);
					}
				}
			});
		} else return this;
	};
})(jQuery);
