jQuery.noConflict();
jQuery(function($) 
{
	var frontend = 
	{
		init:function()
		{
			this.blogNav();
			this.slide();
			this.equalColumns();
			this.hoverBrands();
		},
		
		blogNav:function()
		{
			if($('#blogNavWidget').length)
			{
				$('#blogNavWidget ul').hide();
				$('#blogNavWidget h2').each(function(){ $(this).replaceWith('<h2><a href="#" class="trigger">'+$(this).text()+'</a></h2>')});
				this.showSection();
				$('a.trigger').click(function(){
					var nextUL = $(this).parent().next('ul');
					$('#blogNavWidget h2').removeClass('current');
					$(this).parent().addClass('current');
					$('#blogNavWidget ul').slideUp();
					nextUL.slideToggle();
					return false;
				});
			}
		},
		
		showSection:function()
		{
			var open = false;
			
			$("#blogNavWidget ul a").each(function()
			{
				if (this.href == "http://" +window.location.hostname + window.location.pathname) 
				{
					$(this).addClass('current');
					$(this).parent().parent().show();
					open = true;
				}
			})	
			
			if(!open)
			{
				$("#blogNavWidget ul:first").show();
			}			
			
		},
		
		slide:function()
		{
			if ($('.ss-articleholder').length && $('#slides').length) 
			{				
				var p = '#controls div';
			
				$('#slides').cycle({
					fx: 'scrollLeft',
					pager:p,
					pause:1,
					timeout:4000,
					pagerAnchorBuilder: function(idx, slide){
						return '<a href="#">' + (idx+1) + '</a>';}
				});
			}
			else if($('#slides').length)
			{
				if ($('#slides div').length > 1)
				{
					var p = '#controls';
					
					$('#slides').cycle({
						fx: 'scrollLeft',
						pager: p,
						pause: 1,
						timeout: 0,
						pagerAnchorBuilder: function(idx, slide){
							return '#controls li:eq(' + idx + ') a';
						}
					});
				}
			}
		},
		
		equalColumns:function()
		{
			if ($('#featureBoxes').length) 
			{
				var tallest = 0;
				var thisHeight;
				$("div.featureBox").each(function(){
					thisHeight = $(this).height();
					if (thisHeight > tallest) {
						tallest = thisHeight;
					}
				});
				$("div.featureBox").height(tallest);
			}
		},
		
		hoverBrands:function()
		{
			if($('#brands').length)
			{
				$('#brands a').hover(
				function()
				{
					$(this).css('opacity', .5);
				},
				function()
				{
					$(this).css('opacity', 1);
				});
				
				$('#brands a').focus(
				function()
				{
					$(this).css('opacity', .5);
				});
				
				$('#brands a').blur(
				function()
				{
					$(this).css('opacity', 1);
				});
			}
		}
	}
	frontend.init();
});