

// various stuff to do when the page is ready
$(document).ready(function(){
	
	
	
	//general stuff
	$('a').click(function(){
        this.blur();
    });
    $('a img').focus(function(){
        this.parent.blur();
    });
	

	//
	//place context nav pointer img (the little teardrop dollop thing)
	function setPointer(contentNav){
		if(contentNav == 'all'){
			var pointerWidth = 0;
			$('.contentNav .pointer ').each(function(){
				pointerWidth = 0;
				$(this).parent('div').find('ul li').each(function(i){
					if($(this).hasClass('selected')){
						if(i > 0) pointerWidth = $(this).width()*.25 + pointerWidth;
						$(this).parent('ul').parent('div').find('.pointer').css('background-position',pointerWidth+'px bottom');		
					}else{
						pointerWidth = $(this).width() + pointerWidth;
					}
				});
			});
		}else if(contentNav != ''){
			//this is the stuff to run on a nav item click
			pointerWidth = 0;
			$(contentNav).find('ul li').each(function(i){
					if($(this).hasClass('selected')){
						if(i > 0) pointerWidth = $(this).width()*.25 + pointerWidth;
						$(this).parent('ul').parent('div').find('.pointer').css('background-position',pointerWidth+'px bottom');		
					}else{
						pointerWidth = $(this).width() + pointerWidth;
					}
			});
		}else{
			return false;
		}
	}
	//if theres a pointer on the page, set up its location
	if($('.pointer').length)setPointer('all');
	
	$('.contentNav ul li a').click(function(){
		if ($(this).parent('li').parent('ul').parent('div').attr('id')) {
			var thisId = $(this).parent('li').parent('ul').parent('div').attr('id');
			var thisNav = '#' + thisId;
		}
		if ($(thisNav + ' .pointer').length) {
			$(this).parent('li').parent('ul').find('li').each(function(){
				$(this).removeClass('selected');
			});
			$(this).parent('li').addClass('selected');
			
			setPointer(thisNav);
		}
		
		contentToLoad = $(this).attr('href')+' #'+$(this).attr('rel');
		//alert(contentToLoad);
		$('div .'+ thisId +' .holder').load(contentToLoad);
		return false;
	});
	//end content nav pointer
	
	//alert(find('div').class('swf'));
	
	//flash insert
	//only do the flash stuff if there is an element with the .swf class
	if($('.swf').length){
		
		//MGC flash
		$('.millionGirlChoir.swf').flash(
			{
			    src: '/Flash/MilllionGirlChoir/million_girl_choir.swf',
		        wmode: 'transparent', 
				width: '920',
		        height: '512',
				menu: false
		     }, 
			{
				expressInstall: true, 
				version: 9 
			}
		);
		
		//home flash full screen navigation
		$('.homeSplash.swf').flash(
			{
		        src: '/swf/portal.swf',
		        width: '100%',
		        height: '100%',
		        wmode: 'transparent'
				//,flashvars: {user: 'swellBella' }
		     }, 
			{
				expressInstall: true, 
				version: 8 
			}
		);
			
	}
	// end flash inserts	

		
	//rounded corners
	if($('.round').length ){
		
		var roundContent ='';
		var preRound = '<div class="ul"><div class="ur"></div><div class="ll"></div><div class="lr"><div class="content">';
		var postRound = '</div></div></div>';
		$('div.round').each(function(){
			roundContent = $(this).html();
			$(this).addClass("rounded");
			$(this).html(preRound+roundContent+postRound);
		});
	}
	
	
	
	
	//centered links on content nav
	if($('.contentNav.centered').length){
		$('.contentNav.centered').each(function(){
			var liWidth = 0;
			var contentNavWidth = $(this).width();
			//add up the li's to get their total width
			$(this).find('ul li').each(function(){
				liWidth = liWidth + $(this).width();
			});
			var contentNavLiMargin = contentNavWidth/2 - liWidth/2 +"px";
			$(this).find('li:first').css({
				"margin-left":contentNavLiMargin
			});
		});
	}




	//coming soon tooltip for dummy content
	var $toolTipItems = $("img.dummy, a.dummy, area.dummy");
	if ($toolTipItems.length) {
		$toolTipItems.tooltip({
			bodyHandler: function(){
				return 'coming soon';
			},
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			fade: 250,
			extraClass: 'comingSoon'
		});
	}
	
	//cant be floating something thats full width.. can i? this is temp!
	$('.contentBox.grid_12.right').removeClass('right');
	
	//ie specific tweaks (its late)
	if($.browser.msie){
		$('.contentNav.centered ul').css({
			'padding-bottom':'20px'
			}
		);
	}
	
	//mini-top tab nav
	$('.mininav span.read').hover(function(){
		$('.mininav span.read').animate({'top': '0px'},600);
	},function(){
		$('.mininav span.read').animate({'top':'-192px'},600);
	});
	

});


