$(document).ready(function(){
	//alert($('#navigationSecondary ul').children().length);
	if('0'==$('#navigationSecondary ul').children().length){
		$('#navigationSecondary').remove();
	}
	$("#contactForm").validate();	
	
	$("blockquote p:last-child").append('<span class="stop">&nbsp;</span>');
	
	$('.accordionTitle').each(function(){
		$(this).nextUntil(':not(.accordionContent)').andSelf().wrapAll('<div' + ' ' + 'class="accordion">');
	})
	
	$('.accordionTitle').toggle(function(){
		if($.browser.msie&&(parseInt(jQuery.browser.version)==8)){
			$(this).siblings('.accordionBody').show();	
		}else{
			$(this).siblings('.accordionBody').slideDown(600);
		}
		$(this).css('background-image','url(/images/icon_toggle_down.png)')
		return false;
	},function(){
		if($.browser.msie&&(parseInt(jQuery.browser.version)==8)){
			$(this).siblings('.accordionBody').hide();
		}else{
			$(this).siblings('.accordionBody').slideUp(600);
		}
		$(this).css('background-image','url(/images/icon_toggle_up.png)')
		return false;
	});
	
	$('.accordion').each(function(){
		$(this).children('.accordionContent').wrapAll('<div' + ' ' + 'class="accordionBody">');
	});
	$('.accordionBody').slideUp(1);
	
	//alert($('.t-home #headerImage ul li').length);
	if($('.t-home #headerImage ul li').length>0){
		$('.t-home #headerImage li').fadeOut(1);
		frame = 0;
		$('.t-home #headerImage li:eq(0)').fadeIn(200);
		loop = $('.t-home #headerImage ul li').length
		function animation(){
			$('.t-home #headerImage li:eq('+frame+')').fadeIn(1000,function(){
				frame++;
				if(frame==loop){
					frame=0;
				}
			}).siblings('li').fadeOut(1000);
		}
		
		var animationSet = setInterval(function() {
			animation();
		}, 4000);
	}else{
		$('#headerImage li').fadeOut(1);
		$('#headerImage li:eq('+ (Math.floor(Math.random()*$('#headerImage li').length+1)-1)+')').fadeIn(200);
	}
	
	
	/*$('.t-home #headerImage li').mouseenter(function(){
		clearInterval(animationSet);
	}).mouseleave(function(){
		animation();
		animationSet = setInterval(function() {
			animation();
		}, 3000);
	});*/
});
