;(function($) {

$.fn.extend({
	slideShow : function(settings) {
		defaults = {
			'speed' : 400,
			'delay' : 4000,
			'random' : false
			};
		if(!settings) settings = defaults;
		$.extend(defaults, settings);
		return this.each(function() {
			var it = $(this);
			var list = $('a > img', this);
			if(list.length <= 1) {return;}
			list.hide();
			$(this).data('slideShowSettings', defaults);
			$(this).data('slideShowElements', list);
			var first = Math.floor(Math.random() * list.length);
			$(this).data('slideShowIndex', first);
			$(list[first]).show();
			setTimeout(function() {
				it.slideShowSwitch();
			}, defaults['delay']);
		});
	},
	slideShowSwitch : function() {
		var switchto = this.data('slideShowIndex');
		var list = this.data('slideShowElements');
		if(this.data('slideShowSettings')['random']) {
			while(switchto == this.data('slideShowIndex')) {
				switchto = Math.floor(Math.random() * list.length);
			}
		} else {
			switchto = (switchto + 1) % list.length;
		}
		$(list[this.data('slideShowIndex')]).fadeOut();
		$(list[switchto]).fadeIn();
		this.data('slideShowIndex', switchto);
		var it = this;
		setTimeout(function() {
			it.slideShowSwitch();
		}, it.data('slideShowSettings')['delay']);
	}
});


$(function() {
	var uri = document.location.href.replace(/[^\/]+\/+[^\/]+/, "").replace(/\?.*/, "").replace(/\#.*/, "");
	$('a[href$='+uri+']').each(function() {
		if($(this).hasClass('hoverimg')) {
			$('img', this).each(function() {
				var src2 = $(this).attr('src');
				if(!/\-hover/.test(src2)) {
					$(this).attr('src', src2.replace(/[.]jpg$/, "-hover.jpg").replace(/[.]png$/, "-hover.png"));
				}			
			});
			$(this).removeClass('hoverimg');
		}
	});
	$('a.hoverimg').hover(
		function() {
			$('img', this).each(function() {
				var src = $(this).attr('src');
				if(!/\-hover/.test(src)) {
					$(this).attr('src', src.replace(/[.]jpg$/, "-hover.jpg").replace(/[.]png$/, "-hover.png"));
				}
			});
		},
		function(){
			$('img', this).each(function() {
				var src = $(this).attr('src');
				$(this).attr('src', src.replace(/\-hover[.]jpg$/, ".jpg").replace(/\-hover[.]png$/, ".png"));
			});			
		}
	);
	$('#slides').slideShow();
	$(".service .title a[href=#]").click(function() {
		$('.more').not($('.more', $(this).closest('.service'))).hide();
		$('.more', $(this).closest('.service')).toggle();
		event.preventDefault();
	});
	$("#faq h3").click(function() {
		$(this).siblings('div').not($(this).next()).slideUp();
		$(this).next().slideToggle();
	}).css('cursor', 'pointer').hover(function() {
		$(this).css('text-decoration', 'underline');
	},
	function() {
		$(this).css('text-decoration', 'none');
	});
	$("#faq div").hide();
	if(document.location.hash && document.location.hash.length > 0) {
		$(".title a[href=#]", $('a[name=' + document.location.hash.replace(/#/, "") + ']').closest('table')).click();
	}
	if($('a.iframe').length > 0) {
		$('a.iframe').fancybox({'width' : 640, 'height' : 480});
	}
});


})(jQuery);
