// Webfocus Design
// Common scripts

$(document).ready(function(){
	
	// Set the state of current page nav button on page load to show down state
	// The class="current" attribute is set by ColdFusion on the server (see nav include)
	if ($("a[class=current]").children("img").attr("src")) {
		currimgdefaultsrc = $("a[class=current]").children("img").attr("src");	
		currimgsrc = currimgdefaultsrc.replace('.gif', '_down.gif');
		$("a[class=current]").children("img").attr("src", currimgsrc);
	}
	
	// Main navigation image rollovers
	$("#nav a").mouseover(function() {
		imgsrc = $(this).children("img").attr("src");
		// Fail if no image found or if user is mousing over the current page button
		if (typeof(imgsrc) != 'undefined' && $(this).attr("class") != "current") {
			// Replace .gif with _over.gif
			imgsrcON = imgsrc.replace('.gif', '_over.gif');
			// Now change the src to the 'ON' value
			$(this).children("img").attr("src", imgsrcON);
		}
	});
	
	$("#nav a").mouseout(function(){
	  // trap for 'undefined' errors again
	  if (typeof(imgsrc) != 'undefined') {
		  $(this).children("img").attr("src", imgsrc);
	  }
	});	
	
	// Action bar animation
	$(".kwicks").kwicks({  
        min : 15,  
        spacing : 0,
				duration: 700,  
        easing: "easeOutBack"//"easeOutBounce" "easeOutBack" 
    });	
	
	// Portfolio scroller
	$("div.scrollable").scrollable({
		size: 1,
		loop: true,
		items: "#items",
		prev: ".prev",
		next: ".next"								
	});
	
	// Portfolio details popups
	$(".scrollable #items a[rel=portfolio]").fancybox({
		"hideOnContentClick": true,
		"zoomSpeedIn":	750, 
		"zoomSpeedOut":	0,	
		"overlayShow": true,
		"overlayOpacity": 0.4
	});	
	
	// Open all external links in new Window
	$('a[href^="http://"]').attr({
    target: "_blank"    
  }).append(' [^]');
	
});