// JavaScript Document

$(function(){
	// Setup Top Navigation Effects
	$('#nav_hover').css({opacity:0});
	
	$('.menu_item').not('.drop_menu .menu_item').hover(
		function(){ 
			$dwidth = $(this).width();
			$dposition = $(this).position();
			$dwidth = $dwidth + 18;
			//alert($dwidth);
			$('#nav_hover').stop(true,false).animate({opacity:1,width:$dwidth+'px',left:$dposition.left+'px'},300); 
		}, function(){
			$('#nav_hover').animate({opacity:0},400); 
		}
	);
		   
	// Setup Articles
	$('.article').each(function(){
		$(this).append('<img class="article_bar_top" src="/images/article_bar_top.jpg" alt="Article Top" /><img class="article_bar_btm" src="/images/article_bar_btm.jpg" alt="Article Bottom" />')
		
		// eAlign or Elemental Aligner (11.12.09) - Blue Ridge Solutions, Inc.
		// Calculate number of elements and space accordingly 
		// Vertical alignment uses height and top/bottom
		// Horizontal alignment uses width and left/right
		element = 16;
		spacing = 100;
		total = element + spacing;
		ends = 30;
		
		container = $(this).height() - (ends * 2); // height or width
		leftover = container;
		while (leftover >= total) { leftover = leftover - total; }
		leftover = Math.round(leftover / 2);
		position = ends + leftover;
		
		while (container >= element) { // top/bottom or left/right
			$(this).append('<img class="article_bar_ornament" src="/images/article_bar_ornament.jpg" alt="Ornament" style="top:'+position+'px" />');
			container = container - total;
			position = position + total;
		}
	});
	
	// Setup Navigation "Stained Glass" Buttons
	$('.nav_btn')
		.each(function(){
			off = $(this).html();
			on = off.replace('.jpg','_on.jpg" class="btn_on"');
			$(this).append(on);
		})
		.hover(
			function(){ $('.btn_on',$(this)).css({opacity:0}).show().stop(true,true).animate({opacity:1},600); },
			function(){ $('.btn_on',$(this)).animate({opacity:0},400); }
		)
	;
	
	// Setup Listing Navigation
	$('#site_lft a, #site_lft div').not('#site_lft div a, #site_lft a.include_business')
		.css({cursor:'pointer'})
		.append('<img class="lft_nav_btm" src="/images/lft_nav_on_btm.png" alt="Navigation Bottom" />')
		.hover(
			function(){ $('.lft_nav_btm',$(this)).show(); $(this).addClass('hover'); },
			function(){ $('.lft_nav_btm',$(this)).hide(); $(this).removeClass('hover'); }
		)
	;
	
	// Animate Sub Listings
	$('#site_lft div:not(.alwaysshow) a').hide();
	$('#site_lft div.alwaysshow a').css({display:'block'});
	$('#site_lft div:not(.alwaysshow) span').toggle(
		function(){ $('a',$(this).parent()).slideDown(400).animate({opacity:1},200); $(this).parent().addClass('over'); },
		function(){ $('a',$(this).parent()).animate({opacity:0},200).slideUp(400); $(this).parent().removeClass('over'); }
	);
	
	
	// Set Hover State For Image Links
	$('.block_links img, a.copyright img').css({opacity:0.8});
	$('.block_links img, a.copyright img').parent().hover(
		function(){$(this).children('img').stop(true,true).animate({opacity:1},200)},
		function(){$(this).children('img').animate({opacity:0.8},200)}
	);
	
	// Alternate Comment BGs
	$('.comment:odd').css({background:'#F1EEDF'});
});

