// -------------- Tabs --------------
$(function () {
    var tabContainers = $('div.tabs > div');
    
    $('.tabNavigation a').click(function () {
        tabContainers.hide().filter(this.hash).fadeIn();

        $('.tabNavigation span').removeClass('selected');
        $('.tabNavigation a').removeClass('selected');
        $(this).addClass('selected');
		$(this).parent().addClass('selected');
        
        return false;
    }).filter(':first').click();
});
// -------------- Homepage Sliding Content --------------
if (document.getElementById("home")) {
	$(function() {
		$("#controller").jFlow({
			slides: "#slides",
			width: "605px",
			height: "308px",
			duration: 600
		});
	});
};

/* --- Portfolio image gallery --- */

	if (document.getElementById("sub")) {

		var $gallery = $("ul#gallery");

		// Create extra elements & navigation links
		$gallery
			.wrap('<div id="gallery-wrapper"></div>')
			.before('<a href="#" id="gallery-next"><img src="/images/arrow_right.png" alt="Next"></a><a href="#" id="gallery-previous"><img src="/images/arrow_left.png" alt="Previous"></a><p id="gallery-caption"></p>')
			.wrap('<div id="gallery-innerwrapper"></div>');

		// Remove IE's alt tooltip
		if ($.browser.msie) { $gallery.find("img").attr("title", ""); }

		// Settings
		var currentimage = 0;
		var imagecount = $gallery.children("li").size();

		// Image width
		var $firstimage = $gallery.find("img:first");
		var gallerywidth = $firstimage.width(); // $firstimage.width();  // IE miscalculates?
		var galleryheight = $firstimage.height(); // $firstimage.height();

		// Set the strip's actual width to be safe
		$gallery.width(gallerywidth * imagecount);

		// Set initial caption
		
/*
disabled due to lack of content for captions all occurances of any caption action have been commented out

		if ($firstimage.attr("alt")) {
			$("#gallery-caption").html($firstimage.attr("alt"));
			$("#gallery-caption").show();
		} else {
			$("#gallery-caption").hide();
		}
*/

		// Movement links
		$("#gallery-next").click(function(){

			galleryspeed = 1000;
			currentimage++;
			if (currentimage >= imagecount) { currentimage = 0; galleryspeed = 500; }

			
			// Update caption
			/*
			var caption = $gallery.find("img:eq(" + currentimage + ")").attr("alt");
			$("#gallery-caption").fadeOut("60", function(){
				$("#gallery-caption").html(caption);
			});
			*/
			// Slide image
			$gallery.animate({left: -gallerywidth*currentimage}, galleryspeed, "swing", function(){
				// Show next caption
				/*
				if (caption) { $("#gallery-caption:not(:empty)").fadeIn("900"); }
				*/
			});


			return false;
		});

		$("#gallery-previous").click(function(){

			galleryspeed = 1000;
			currentimage--;
			if (currentimage < 0) { currentimage = imagecount-1; galleryspeed = 500; }

			// Update caption
			/*
			var caption = $gallery.find("img:eq(" + currentimage + ")").attr("alt");
			$("#gallery-caption").fadeOut("60", function(){
				$("#gallery-caption").html(caption);
			});
			*/

			// Slide image
			$gallery.animate({left: -gallerywidth*currentimage}, galleryspeed, "swing", function(){
				// Show next caption
				/*
				if (caption) { $("#gallery-caption").fadeIn("900"); }
				*/
			});

			return false;
		});


		// Enlarged images
		$("#gallery.enlarge img").click(function(){

			// Show overlay
			return false;
			//alert("I'm working on it");


		});
		
		// Swiping on iOS
		$("#gallery li").touchwipe({
		 wipeLeft: function() {
			galleryspeed = 1000;
			currentimage++;
			if (currentimage >= imagecount) { currentimage = 0; galleryspeed = 500; }
			$gallery.animate({left: -gallerywidth*currentimage}, galleryspeed, "swing", function(){
			});
			return false;
		},
		 wipeRight: function() { 
			galleryspeed = 1000;
			currentimage--;
			if (currentimage < 0) { currentimage = imagecount-1; galleryspeed = 500; }
			$gallery.animate({left: -gallerywidth*currentimage}, galleryspeed, "swing", function(){
			});
			return false;
		 },
		 min_move_x: 20,
		 preventDefaultEvents: true
		});

	}