jQuery(function( $ ){

	// Have to replace the links rather than just altering the href values because IE likes to kick puppies & make babies cry.
	$("#logo a, h3.cyberwoven a").each(function(){
		if($(this).attr("href") == "/") $(this).attr("href", "/");
		var newhref = $(this).attr("href").replace("/","http://www.cyberwoven.com");
		var newvalue = $(this).text();
		$(this).after('<a href="' + newhref + '">' + newvalue + '</a>');
		$(this).remove();
	});

	// Home page portfolio slider.
	$('#homeslider').after('<ul class="homesliderbuttons"><li><a class="prev" style="display:none;" href="#">Prev</a></li><li><a class="next" href="#">Next</a></li></ul>');
	$('#homeslider').serialScroll({items:'li', prev:'#home a.prev', next:'#home a.next', offset:-330, start:1, duration:1200, force:true, stop:true, lock:false, cycle:false, easing:'slider', jump: false,
	onBefore:function( e, elem, $pane, $items, pos ){
		var $prev = $('#home a.prev'), $next = $('#home a.next');
		$prev.add($next).show();
		if( pos <= 1 ) $prev.hide();
		else if( pos >= $items.length-2 ) $next.hide();
	}
	})

	// Client Tools Show & Tell
	$('#clients ul#tools a').click(function(){
		$('div#clientpages div').hide();
		linkclass = $(this).attr("class");
		$('div#'+linkclass).show();
		$('ul#tools').slideUp("slow", function(){$('div#clientpages').slideDown("slow");});
		return false;
	});
	$('#clients a.showtools').click(function(){
		$('div#clientpages').slideUp("slow", function(){$('ul#tools').slideDown("slow"); $('div#clientpages div').hide();});
		return false;
	});

    // Open links with rel="external" in new window - like ye ole' target="_blank"
	$('a[rel="external"]').click(function() {window.open( $(this).attr('href') ); return false;});
    
	// Open Homepage rel="popover" links in popover window if li has class of hasmore.
	// DISABLED - Uncomment next line to enable.
	//$('#homeslider li p.teaser').append(' <a rel="popover" href="/">More&nbsp;&raquo;</a>');
	$('a[rel="popover"]').click( function() {
		$('#popover').fadeIn('fast');
		var pophtml = $(this).parent('p').parent('li').html();
		$('#popovercontent').html(pophtml);
		$('#popovercontent a[rel="popover"]').remove();
		return false;
	});
	$('.closepopover').click( function(){$('#popover').fadeOut('fast');});
	
	// Initialize Lightbox (For Portfolio Gallery)
	$(".lightbox").lightbox();

	// Push away the static portfolio if the visitor has flash.
	if (swfobject.hasFlashPlayerVersion("9.0.0")) {
		$('#staticfolio').addClass('flyaway');
	}

});


// Function called by portfolio flash to launch jQuery Lightbox.
function enlargeImage(b){
	var bigImage = 'a[href=/' + b + ']';
	$(bigImage).click();
}




