jQuery.noConflict();
jQuery(function($){
	
	var frontend = 
	{
		init:function()
		{
			this.slideShow();
			this.FAQs();
			this.contactAware();
			this.blogNav();
		},
		
		slideShow:function()
		{
			if($('#slides').length)
			{
				var values = $('#slides').attr("class").split(" ");
				timeout = values[0].split("-");
				timeout = timeout[1];
				if (isNaN(timeout)) timeout = 3000;
				
				
				speed = values[1].split("-");
				speed = speed[1];
				if (isNaN(speed)) speed = 1000;
				
				$('#slides').cycle(
				{
					timeout:parseInt(timeout),
					speed:parseInt(speed),
					pause:1,
					pager: '#slideNav',
					next: $('body.HomePage').length ? '#next' : null,
					prev: $('body.HomePage').length ? '#prev' : null,
					pagerAnchorBuilder: function(idx, slide)
					{
                        // return selector string for existing anchor
                        return '#slideNav li:eq(' + idx + ') a';
                    }
				});
				
				if($('div.slide').length)
				{
					if($('div.noContent').length)
					{
						$('div.slide').hover(function(){$(this).css('cursor', 'pointer');}).click(function(){
							window.location = $(this).find('h2 a:eq(0)').attr('href');							
						});
						
						$('div.slide > div').css({display: 'none',visibility:'hidden'});
					}
					else
					{
						$('div.slide div').css('top', '150px');
						$('div.slide').hover(function(e)
						{
							$(this).children('div:eq(0)').hoverFlow(e.type, {top: '0'}, 500);
						}, function(e)
						{
							$(this).children('div:eq(0)').hoverFlow(e.type, {top: '150px'}, 500);
						});	
					}
				}
			}
		},
		
		FAQs:function()
		{
			if($('body.FAQPage').length && $('#FAQCatNav').length)
			{
				$('div.categoryBlock').hide();
				$('div.categoryBlock:eq(0)').show();
				
				$('#FAQCatNav a:eq(0)').addClass('active');
				
				$('#FAQCatNav a').click(function(){
					var id = this.href.split('#');
					$('div.categoryBlock').hide();
					$('#'+id[1]).show();
					$('#FAQCatNav a').removeClass('active');
					$(this).addClass('active');
					return false;
				});
			}
		},
		
		contactAware:function()
		{
			if($('body.ContactPage').length && $('div.formWidget select').length)
			{
				var opts = new Array();
				var title = $('h1').text().toLowerCase();
				$('div.formWidget select option').each( function()
				{
					if($(this).text().toLowerCase().indexOf(title) != -1)
					{
						this.selected = "selected";
						return false;
					}
				});
			}
		},
		
		blogNav:function()
		{
			if($('#blogNav').length)
			{
				$('#blogNav span').each(function(){ $(this).replaceWith('<a href="#" class="trigger">'+$(this).text()+'</a>')});
				this.showSection();
				$('a.trigger').click(function(){
					$('#blogNav ul:not('+this+')').slideUp();
					$('#blogNav li > a').removeClass('current');
					$(this).addClass('current').next().slideToggle();
					return false;
				});
			}
		},
		
		showSection:function()
		{
			$('#blogNav ul').hide();
			$('#blogNav ul a').each(function(){
				if(this.href == window.location.href)
				{
					$(this).parent().parent().show().prev().addClass('current');
					return false;	
				}		
			});		
		}
	}
	
	frontend.init();

});

Cufon.replace('h1', { fontFamily: 'FS Albert Pro Thin' });
Cufon.replace('#mainNav a', { fontFamily: 'FS Albert Pro'})
