// JavaScript Document

// Superfish menu
$(document).ready(function(){
	
	// Clone applications to get a second collection
	var $data = $(".portfolio-content-1, .portfolio-content-3, .portfolio-content-4").clone();
	
	//NOTE: Only filter on the main portfolio page, not on the subcategory pages
	$('.portfolio-main-1 li, .portfolio-main-3 li, .portfolio-main-4 li').click(function(e) {
		$(".filter li").removeClass("active");	
		// Use the last category class as the category to filter by. This means that multiple categories are not supported (yet)
		var filterClass=$(this).attr('class').split(' ').slice(-1)[0];
		
		if (filterClass == 'all-projects') {
			var $filteredData = $data.find('.project');
		} else {
			var $filteredData = $data.find('.project[data-type=' + filterClass + ']');
		}
		$(".portfolio-content-1, .portfolio-content-3, .portfolio-content-4").quicksand($filteredData, {
			duration: 800,
			easing: 'swing',
		}, function() {
			$("#content a img").hover(function() {
   	 		$(this).stop().animate({ "opacity": 0.5 }, 400);
    		},function() {
			$(this).stop().animate({ "opacity": 1 }, 400);
			});
						
			$("a[rel='colorbox']").colorbox({transition:"elastic"});
			
		});
		$(this).addClass("active"); 			
		return false;
	});
	
    $('ul.sf-menu').superfish({ 
            delay:       800,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
			dropShadows:   true   						// turn on drop shadows
    }); 
	
	// Tweet
	$(".tweet").tweet({
            username: "GeneMaytak",
            join_text: null,
            avatar_size: null,
            count: 2,
            auto_join_text_default: "we said,", 
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out",
            loading_text: "loading tweets..."
    });
	
	// Tweet
	$(".sidebar-tweet").tweet({
            username: "GeneMaytak",
            join_text: null,
            avatar_size: null,
            count: 3,
            auto_join_text_default: "we said,", 
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out",
            loading_text: "loading tweets..."
    });
	
	// flickr feed with colorbox
	$('#flickr-feed').jflickrfeed({
		limit: 6,
		qstrings: {
			id: '52617155@N08'
		},
		itemTemplate: '<li>'+
						'<a rel="colorbox" href="{{image}}">' +
							'<img src="{{image_s}}" alt="{{title}}" />' +
						'</a>' +
					  '</li>'
	}, function(data) {
		$("a[rel='colorbox']").colorbox();
	});
	
	// sidebar flickr feed
	$('#sidebar-flickr').jflickrfeed({
		limit: 8,
		qstrings: {
			id: '52617155@N08'
		},
		itemTemplate: '<li>'+
						'<a rel="colorbox" href="{{image}}">' +
							'<img src="{{image_s}}" alt="{{title}}" />' +
						'</a>' +
					  '</li>'
	}, function(data) {
		$("a[rel='colorbox']").colorbox();
	});
	
	// tabs
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first, ul.sidebar-tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li, ul.sidebar-tabs li").click(function() {

		$("ul.tabs li, ul.sidebar-tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	// Back to top
	$('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
	
	// background hover
	$("#content a img").hover(function() {
   	 	$(this).stop().animate({ "opacity": 0.5 }, 400);
    	},function() {
		$(this).stop().animate({ "opacity": 1 }, 400);
	});
	
	$(".page-list li a").hover(function() {
   	 	$(this).stop().animate({ backgroundColor: "#62d1d2"}, 400);
    	},function() {
		$(this).stop().animate({ backgroundColor: "#f7f7f7" }, 400);
	});
	
	$("#icon-div-1").hover(function() {
   	 	$("#icon-hover-1").stop().animate({ backgroundColor: "#d11919"}, 400);
    	},function() {
		$("#icon-hover-1").stop().animate({ backgroundColor: "#5d5d5d" }, 400);
	});
	
	$("#icon-div-2").hover(function() {
   	 	$("#icon-hover-2").stop().animate({ backgroundColor: "#d11919"}, 400);
    	},function() {
		$("#icon-hover-2").stop().animate({ backgroundColor: "#5d5d5d" }, 400);
	});
	
	$("#icon-div-3").hover(function() {
   	 	$("#icon-hover-3").stop().animate({ backgroundColor: "#d11919"}, 400);
    	},function() {
		$("#icon-hover-3").stop().animate({ backgroundColor: "#5d5d5d" }, 400);
	});
		
});
