jQuery(document).ready(function($) {
    $('#gallery').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed: 4000,
		before: function(){
			val = $(this).children("img").attr("src") ;
			getCurrentSlide(val);
		}
	});
	
	
	function getCurrentSlide(curr) {
		smallSelect = curr.replace(".jpg", "");
		i=0;		
		$(".filmstrip li img").each(function() { 			
			firstImg = $(this).attr("src");
			newfirst = firstImg.replace("-small.jpg", "");
			newfirst = firstImg.replace("-small-dark.jpg", "");
			
			if(smallSelect == newfirst){
				//alert("found the match at " + i);
				//alert($(this).attr("src"));
				
				chgImg = $(this).attr("src");
				newThumb = chgImg.replace("-small-dark.jpg", "-small.jpg");
				
				$(this).attr("src", newThumb);
				$(this).addClass("current");
				
				//alert($(this).attr("src"));			
				
			}else{
				i++;
				//$(this).removeClass("current");
				
				chgImg = $(this).attr("src");
				newThumb = chgImg.replace("-small.jpg", "-small-dark.jpg");
				
				$(this).attr("src", newThumb);
				$(this).removeClass("current");
			}
		});
	}
	
	var opened = false;
	
	$("#about_tab").mouseover(function(){
		if(opened){
			$(".texticon").attr("src", "images/down-hover.png");	
		}else{
			$(".texticon").attr("src", "images/up-hover.png");				
			
		}
	});

	
	$("#about_tab").mouseout(function(){
		if(opened){
			$(".texticon").attr("src", "images/down.png");	
		}else{
			$(".texticon").attr("src", "images/up.png");				
			
		}
	});

	$("#about_tab").click(function(){
		if(opened){
			$("#about_me").animate({"top": "+=132px"}, "slow");
			$(".text").html("Select a Project");
			$(".texticon").attr("src", "images/up.png");	
		}else{
			$("#about_me").animate({"top": "-=132px"}, "slow");
			$(".text").html("Hide");
			$(".texticon").attr("src", "images/down.png");				
			
		}
		$("#about_content").slideToggle("slow");
		opened = opened ? false : true;

	 });
	
	
	 
	 $(".img_wrap img").click( function(){		
	
		newImage = $(this).attr("src");
		i=0;	
		//-- change class here
		$(".filmstrip li img").each(function() {  
			if($(this).attr("src") == newImage){				
				$('#gallery').cycle(i);  
			}else{
				i++;
			}
			
		}); 												  
		
	});
	
});