(function($) {
	var animation_duration = 8000;
	function cycle_testimonials(){
		var container = $('#testimonials');
		container.animate({'opacity':0},500,'swing',function(){
			container.load('/wp-content/themes/twentyeleven/ajax_sidebar.php #testimonials',function(a,b,c){
				container.animate({'opacity':1},1000,'swing',function(){
					setTimeout(cycle_testimonials,animation_duration);				
				});
			
			});
			
		});		
		
	}
	
	$(document).ready( function() {
	    $("#access3 ul li a[title]").tooltip();
		
		//Highlight current sidebar menu link
		var path = window.location.href;
		$('#secondary li a').each(function(){
			if($(this).attr('href')==path){
				$(this).parent().addClass('current-menu-item current_page_item');
			}
		});
		
		//Show sidebar sub menus when parents or sub-menu pages are viewed.
		$('#secondary li.parent-menu').each(function(){
			if($(this).hasClass('current-menu-item') || $(this).hasClass('current-menu-parent')){
				$(this).find('.sub-menu').show();
				$(this).find('div.reveal').addClass('revealed');
			}
		});
		
		//Highlight header menu 2 entries when on sub pages.
		$('#menu-header-menu-2 li a').each(function(){
			if((path==$(this).attr('href')) || ($(this).text()!='Home' && path.match($(this).attr('href')))){
				$(this).parent().addClass('current-menu-item current_page_item');
			}
		});
		
		$('#stay_connected,#stay_connected-sidebar').click(function(){
			
			if($('input[type=text]',this).val().length>0){
				$('form',this).submit();
			}
			
			return false;
		});
		
		
		
		if($('.widget.testimonials').length>0){
			setTimeout(cycle_testimonials,animation_duration);
		}
		
		var old_domain='intercad.co.nz';
		var new_domain='intercad.com.au';
		if(window.location.host=='intercad.co.nz'){
			new_domain='intercad.co.nz';
			old_domain='intercad.com.au';			
		}else if(window.location.host=='intercad.com.au'){		
			old_domain='intercad.co.nz';
			new_domain='intercad.com.au';
		}
		$('a').each(function(){
			var href = $(this).attr('href');
			if(href && href.charAt(0)=='h'  && !$(this).hasClass('skip_override')){//only do replace for full paths - not relative /... paths
				href = href.replace(old_domain,new_domain);
				$(this).attr('href',href);
			}
		});
		
	});
})(jQuery);



