function beforeSlide(currSlideElement, nextSlideElement, options, forwardFlag)
{
$(".box.active").removeClass("active");
}
function afterSlide(currSlideElement, nextSlideElement, options, forwardFlag)
{

$("#c_"+nextSlideElement.id).addClass("active");
}

	$(function() {
		
		// show/hide 'Search' text in search box on focus
		$('#search input')
			.focus(function() { if($(this).val() == 'Search') $(this).val(''); })
			.blur(function() { if($(this).val() == '') $(this).val('Search'); });
			
		// prevent search box from submitting if it's empty (or 'Search')
		$('#search')
			.submit(function() { if($(this).find('input').val() == 'Search') return false; });

		// show/hide 'Search the Blog' text in search_the_blog box on focus
		$('#search_the_blog input')
			.focus(function() { if($(this).val() == 'Search the Blog') $(this).val(''); })
			.blur(function() { if($(this).val() == '') $(this).val('Search the Blog'); });
			
			$('#pivot_signup .email_address')
			.focus(function() { if($(this).val() == 'E-mail Address') $(this).val(''); })
			.blur(function() { if($(this).val() == '') $(this).val('E-mail Address'); });
			
		// prevent search_the_blog box from submitting if it's empty (or 'Search the Blog')
		$('#search_the_blog')
			.submit(function() { if($(this).find('input').val() == 'Search the Blog') return false; });
	
		// add striped background to each h2
		$('#content h2').each(function() {
			var w = $(this).width() - $(this).find('strong').width() - 15;
			$(this).append('<em></em>').find('em').width(w);
		});
		
		// add transparent line to all headers except homepage
		$('#hline').css('opacity','.3');
		
		// cycle images (my little cycle plugin, at the bottom of this file :)
		$('#content .top .cycle').myCycle();
		
		
		
		
		// on plog post page - alternate background color for comments
		$('.be_comments .be_comment:even').addClass('even');
		
		if((function x(){})[-6]=='x') { $('.blog #main .main a.more').css({'display':'-moz-inline-box'}); }
		
		$(".case_stories #caseheader").cycle({before: beforeSlide,
		after:afterSlide,
		 delay:7000}); 
		 
		 
		 $("#content.case_stories .box").hover(function(){$(this).addClass("active");},function(){$(this).removeClass("active");}).click(function(){document.location.href = $(this).find('a').attr('href');});
		 
		// stylish select
		$('.view select').sSelect();
					
		$('.portfolio_thumb').colorbox({innerWidth:"922px", innerHeight:"610px"},function(){
		$('#portfolio_viewer .cycle').myCycle();
		});
		
		
		if($('.portfolio_images').size() > 1)
		{
			$('.portfolio_images:gt(0)').hide();
			$('#portfolio_nav').html('<span class="left">Click to see larger images</span><a href="#" class="next">Next</a><a href="#" class="prev">Prev</a><span>View More</span>');
			$('#portfolio_nav .next').click(function(){
							var cur = $('.portfolio_images:visible');

				if(cur.next('.portfolio_images').size() > 0)
				{
					cur.hide();
					cur.next('.portfolio_images').show();
				}
				return false;
			});
			$('#portfolio_nav .prev').click(function(){
				var cur = $('.portfolio_images:visible');
				if(cur.prev('.portfolio_images').size() > 0)
				{
					cur.hide();
					cur.prev('.portfolio_images').show();
				}
				return false;
			});
			
			
		}
		else
		{
		$("#portfolio_nav").hide();
		}
		
		$(".paginate a").each(function(){
		if($(this).html().indexOf("First") >= 0 ||	$(this).html().indexOf("Last") >= 0)
		{
		$(this).css("width","60px");
		}
		});
		
		
					
	});
	
	$.fn.myCycle = function() {
		$(this).each(function() {
			var cdiv = $(this);
			var cimg = cdiv.find('img');
			var cnum = cimg.length;
			var cpgs = '';
			if(cnum==1) return;
			
			for(x = 0; x < cnum; x++) { cpgs += '<li><a href="#" rel="' + (x + 1) + '">' + (x + 1) + '</a></li>'; }
			cimg.hide().eq(0).show();
			cdiv.css('width',cimg.eq(0).width()).css('height',cimg.eq(0).height()).after('<ul class="cyclelinks"><li class="cprev"><a href="#">◄&lt;</a></li>' + cpgs + '<li class="cnext"><a href="#">&gt;</a></li></ul><span id="caption"></span>');
							$("#caption").html(cdiv.find("img:visible").attr('alt'));

			
			var clnx = cdiv.next('ul.cyclelinks');
			var title = "";
			clnx.find('li').eq(1).addClass('active');
			clnx.find('a').click(function() {
				var cdiv = $(this).parents('ul').prev('div');
				var cims = cdiv.find('img');
				
				if($(this).parent('li').hasClass('cprev')) {
					var ccur = cims.index(cdiv.find('img:visible'));
					var cnum = cims.length - 1;
					if(ccur == 0) { cnew = cnum; } else { cnew = ccur - 1; }
					cdiv.find('img:visible').fadeOut(300);
					cims.eq(cnew).fadeIn(300);

					$(this).parents('ul').find('li').removeClass('active').eq(cnew + 1).addClass('active');

	title =cims.eq(cnew).attr('alt');
				$("#caption").html(title);
					return false;
				}
				if($(this).parent('li').hasClass('cnext')) {
					var ccur = cims.index(cdiv.find('img:visible'));
					var cnum = cims.length - 1;
					if(ccur == cnum) { cnew = 0; } else { cnew = ccur + 1; }
					cdiv.find('img:visible').fadeOut(300);
					cims.eq(cnew).fadeIn(300);
					$(this).parents('ul').find('li').removeClass('active').eq(cnew + 1).addClass('active');
					title =cims.eq(cnew).attr('alt');
				$("#caption").html(title);

					return false;
				}
				

				
				cdiv.find('img:visible').fadeOut(300);
				cims.eq($(this).attr('rel') - 1).fadeIn(300);

	title = cims.eq($(this).attr('rel') - 1).attr('alt');
				$("#caption").html(title);

				
				$(this).parents('ul').find('li').removeClass('active');
				
				$(this).parent('li').addClass('active');
				return false;
			});
							$('.cyclelinks .cprev a').html('&lt;');
							
							
							

		});
		return $(this);
	}