$(document).ready(function(){
	
	//replace all fck inserted movies with swfobject
	//needed for accessibility options
	
	//find all embed objects
	$('embed').each(function(){
			var cnt = 1;
			//if they are flash movies
			if($(this).attr('type') == 'application/x-shockwave-flash'){
				
				//get the source fo the flash movie
				if($(this).attr('src')){
					
					flash_src = $(this).attr('src');
					flash_div = 'flash-'+cnt;
					
					//test for a you tube link
					pattern = /youtube./i;			//basic regex patterm case insensitive
					result = pattern.test(flash_src);	//rung using test method
				
					if(result == true){
						if(jQuery.fn.youtubin){
							
							//replace the embed obect with a holding div
							$(this).replaceWith('<span id="'+flash_div+'"><a href="'+flash_src+'">View clip</a></span>');
							
							//use youtubin plugin to embded the flash movie
							$('#'+flash_div).children('a').youtubin({
								swfWidth : '375',
								swfHeight : '304'
							});
							
						}else{
							alert('You need to have the youtubin plugins installed.');
						}
					}else{
						
						//replace the embed obect with a holding div
						$(this).replaceWith('<span id="'+flash_div+'"></span>');
					
						$('#'+flash_div).flash({ 
							// test.swf is the flash document 
							swf: flash_src,
							width : 375,
							height : 304
						}); 
					}
				}
			}
	});
	
	//if the livequery plugin is detected
	if(jQuery.fn.ajaxify){
		if($('#content-loading').length > 0 ){ // check if element is on page
			
			$('#main #main-center-panel').css({'position':'relative'});
			$('#content-loading').css({
									  'position':'absolute',
									  'width':'100%',
									  'height':'100px',
									  'text-align':'right',
									  'position':'absolute',
									  'top':'0',
									  'left':'0'
									  });
			
			$('a.ajax').livequery(function(){
		  
				$(this).ajaxify({
					onStart:function(options){
						$('#content-loading').fadeIn('slow');
					},
					onError:function(options,data){			
						$('#content-loading').html("<p class='error'>Error: Couldn't open &quot;"+options.link+"&quot;.</p>");	
					},
					onSuccess:function(options,data){
						$('#content-loading').css('display','none');
					},
					onComplete:function(options){
						$('#content-loading').css('display','none');
					},
					target: '#article #main #main-center-panel #load-content',
					loadHash:'attr:href',
					loading_txt:'Page loading...',
					loading_img:'/img/jquery/ajax-loader.gif',
					loading_target:'#content-loading'			
				});
			
			});	
		}
	}
	
	if(jQuery.url){
		// get the file
		//alert(jQuery.url.attr("file")); // returns 'index.html'
		// get the path
		//alert(jQuery.url.attr("path")); // returns '/information/about/index.html'
		// get the first segment from the url path
		// get the second segment from the url path
		jQuery.url.segment(0) // returns 'information'
		
		$('#nav-wrapper ul li a').each(function(){
			if($(this).hasClass('selected')){
				$(this).removeClass('selected');
			}
			
			if($(this).attr('href') == jQuery.url.attr("path")){
				$(this).addClass('selected');
			}
			//caveat for home page section taking the first section of the URL
			if(jQuery.url.segment(0) == null){
				$('#nav-wrapper ul li a#a1').addClass('selected');
			}
		});
		
		$('a#xhtml').each(function(){
			//caveat for home page section taking the first section of the URL
			if(jQuery.url.segment(0) == 'city-of-bath-video'){
				$('a#xhtml').hide();
			}
		});
		
		//caveat for home page section taking the first section of the URL
		if(jQuery.url.segment(0) == null){
			$('#nav-wrapper ul li a#a1').addClass('selected');
		}
		
		$('#footer ul li a').each(function(){
			if($(this).hasClass('selected')){
				$(this).removeClass('selected');
			}
			
			if($(this).attr('href') == jQuery.url.attr("path")){
				$(this).addClass('selected');
			}
		});
	}
	
	//use jquery to place a description fo each link giving the full url relative to the site domaion after each link.
	// this replaces the CSS a:after method.
	$('#main-content p a, #main-content li a').each(function(i,e){if(this.href.length > 0){$(e).html($(e).html() + "<span class='hide'>["+this.href+"]</span>");}})


});