var $j = jQuery.noConflict();


// Current Field and Button Highlighting

$j(document).ready(function(){
	$j("#submit").mouseover(function() {
		$j(this).addClass("buttonHover")
	});
	$j("#submit").focus(function() {
		$j(this).addClass("buttonHover")
	});
	$j("#submit").mouseout(function() {
		$j(this).removeClass("buttonHover")
	});
	$j("#submit").blur(function() {
		$j(this).removeClass("buttonHover")
	});
	$j("#reset").focus(function() {
		$j(this).addClass("buttonHover")
	});
	$j("#reset").mouseover(function() {
		$j(this).addClass("buttonHover")
	});
	$j("#reset").mouseout(function() {
		$j(this).removeClass("buttonHover")
	});
	$j("#reset").blur(function() {
		$j(this).removeClass("buttonHover")
	});
});

//PORTFOLIO GALLERY
$j(document).ready(function() {
	
	//Set up links to toggle display of portfolio sections
	$j("#portfolioNav a").click(function() {
		$j("#portfolioNav a").css({'color': '#a00e11'});
		var title = $j(this).attr("title");
		$j(this).css({'color' : '#666'});
		$j(".portfolioBox").each(function() {
			var display = $j(this).css("display");
			var id = $j(this).attr("id");
			if (display == "block") $j(this).hide();
			if (id == title) $j(this).show("normal");
		});
		
		$j("div.portfolioBox * a").each(function() {
			var isFirst = $j(this).parent("li").get(0).className;
			if (isFirst != 'first') {
				$j(this).css({
					'background-color' : '#fff',
					'border' : '1px solid #bac2b4',
					'color' : '#a00e11'
				});
			}
			else {
				$j(this).css({
					'background-color' : '#a00e11',
					'border' 		   : '1px solid #a00e11',
					'color'			   : '#fff'
				});
			}
		});
		
		var counter = 1;
		$j(".portfolioBox").each(function() {
			$j(this).find("div").each(function() {
				if (counter == 1) $j(this).css({'display': 'block'});
				else $j(this).css({'display': 'none'});
				
				counter += 1;
			});
			
			counter = 1;
		});
		
		return false;
	});
	
	//Create links inside each portfolio section to toggle display of images
	$j(".portfolioBox").each(function() {
			
		var output = '<ul class="portfolioButtons">';
		var counter = 1;
		$j(this).find("div").each(function() {
			
			// If there are mult. images, hide all but first
			if (counter > 1) $j(this).css("display", "none");
			
			var divId = $j(this).attr("id");
			
			if (counter == 1) output += '<li class="first"><a href="" class="'+divId+' changeImage">'+counter+'</a></li>';
			else output += '<li><a href="" class="'+divId+' changeImage">'+counter+'</a></li>';
			
			counter += 1;
		
		});
		output += '</ul>';
		
		if (counter > 2) $j(this).find("ul").before(output);
		
		//Set links up to change toggle images on click
		$j(this).find("a.changeImage").click(function() {
			
			// Unselect all a tags in portfolio buttons
			var what = $j(this).parent().parent().parent().parent("div").find("div * a").each(function() {
				$j(this).css({
					'background-color' : '#fff',
					'border' : '1px solid #bac2b4',
					'color' : '#a00e11'
				});		
			});
			
			// Get ID class of link, matches ID of corresponding image
			var linkClass = $j(this).attr("class");
			linkClass = linkClass.replace(/ changeImage/, "");
			
			// Select this link
			$j(".portfolioBox div a").each(function() {
				var thisClass = $j(this).attr("class");
				thisClass = thisClass.replace(/ changeImage/, "");
				if (thisClass == linkClass) $j(this).css({'background-color' : '#a00e11', 'color' : '#fff', 'border' : '1px solid #a00e11'});
			});
			
			var tag = $j(this).parent().parent().parent().parent().find("div").each(function() {
				var imgId = $j(this).attr("id");
				if (imgId == linkClass) $j(this).show();
				else $j(this).hide();
			});
			
			return false;
		
		});
	});
	
});



