/***********************************
*	Site Name IC Main Site
*	Developer: Rich Rudzinski
*	Created on: 9/09
***********************************/
$(document).ready(function() {
	/* Back to Top function so no # in url */
	$('#backTop').click(function() {
		$(document).scrollTop(0);
		return false;
	});
	feedAdjust();	
	$('#feedLinks a').click(function() {
		feedSwap($(this));
		return false;
	});
	// initialize js navigation if using IE6
	//if(navigator.appVersion.match('MSIE 6.0')) 
	navInit();
	// Initialize font replacement
});

/* Navigation JS for IE6 */
function navInit() {
	$('#nav li').hover(function() {
		$(this).toggleClass('hover');		
	}, function() {
		$(this).toggleClass('hover');
	});
	$('#nav .navOverlay li').hover = '';
	$('#nav .navOverlay').hover(function() {
	}, function() {
		$(this).parent().parent().find('a').css('color', '#fff');
	});
}

/* adjusts the height of the blog feed */
function feedAdjust() {
	/* Feed content height */
	var postArray = $('#feedCont .post .content');
	for(i=0; i<postArray.length; i++) {
		if(postArray[i].getElementsByTagName('img').length) {
			var height = $(postArray[i].getElementsByTagName('img')[0]).height();
			var blurbHeight = $($('#feedCont .post .blurbInner')[i]).outerHeight();
			var height = (height > blurbHeight) ? height : blurbHeight;
		} else {				
			var height = $($('#feedCont .post .blurbInner')[i]).outerHeight();
			var height = (height > 124) ? height : 124;
			$($('#feedCont .post .blurbInner')[i]).css('width', '608px');
		}
		$(postArray[i]).css('height', height + 'px');
	}
}

/* sets up the ajax handler for the blog feed on the ic homepage */
function feedSwap(obj) {
	$('#newsHead li').removeClass('active');
	obj.parent().addClass('active');
	$('#feedCont').animate({ opacity:0 }, 600, function() {
		$('#feedCont').html('');
		$.ajax({
			type: 'GET',
			url: 'includes/phpbin/feedHandler.php?'+obj.attr('href'),
			success: function(data) {
				$('#feedCont').html(data);
				feedAdjust();
				cufon();
				$('#feedCont').animate({ opacity:1 }, 600);
			}
		});
	});
}

/* Cufon font replacement */
function cufon() {
	// set Arial Narrow family and run replace
	Cufon.set('fontFamily', 'Arial Narrow');

	Cufon.replace('.mediumCond_links a', {
		hover: true
	});
	Cufon.replace('.mediumCond_link', {
		hover: true
	});
	Cufon.replace('.boldCond');
	Cufon.replace('.arrowBtn', {
		hover:true
	});
	Cufon.replace('.boldCond_links a', {
		hover: true
	});
	
	// set Helvetica Light family and run replace
	Cufon.set('fontFamily', 'Helvetica Light');
	
	Cufon.replace('.neueLight');
	Cufon.replace('.neueLightLink', {
		hover: true
	});
	Cufon.replace('.boldOblique_links a', {
		hover: true
	});		
}