$(document).ready(function(){
// CREATE TABS
  $("#tabs a").click(function () {
    $("#tabs li").removeClass("active");
    $(this).parent().addClass("active");
    if ($("#portfolio-entries").length > 0) {
      $("#portfolio-entries li").hide();
      if ($(this).attr("href").split('#')[1] == 'all') {
        $("#portfolio-entries li").show();
      } else {$(".port-"+$(this).attr("href").split('#')[1]).show();}
    } else if ($("#category-list").length > 0) {
      $("#category-list").hide();
      $("#popular-weblogs").hide();
      $("#"+$(this).attr("alt")).show();
      }
  });

// SET DEFAULT STATUS
  var active_port = document.location.toString().split('#')[1];
  if (active_port=="web" || active_port=="print") {
    if ($("#portfolio-entries").length > 0 ) {
      $("#tabs li").removeClass("active");
      $("#portfolio-entries li").hide();
      if (active_port=="web") {
        $("#tabs li").eq(1).addClass("active");
      } else {
        $("#tabs li").eq(2).addClass("active");
      }
    } else {$(".port-entry").hide();}
    $(".port-"+active_port).show();
  } else if (active_port=="categories" || active_port=="popular") {
    if ($("#category-list").length > 0) {
      $("#tabs li").removeClass("active");
      if (active_port=="categories") {
        $("#popular-weblogs").hide();
        $("#category-list").show();
        $("#tabs li").eq(0).addClass("active");
      } else {
        $("#category-list").hide();
        $("#popular-weblogs").show();
        $("#tabs li").eq(1).addClass("active");
      }
    }
  }

// TOGGLE CASE STUDY BAR
  $(".case-study").click(function () {
    $("#case-study-content").toggle("blind", {direction: "vertical"}, 300);
    $(".case-study-status").toggleClass("opened");
    if ($(".case-study-status-txt").html() == 'Show Case Study') {
      $(".case-study-status-txt").html("Hide Case Study");
     } else {
      $(".case-study-status-txt").html("Show Case Study");
    }
    return false;
  });
// CREATE SLIDEBAR
  $('#slidebar').slidebar({
    fx: 'easeInOutSine', 
    speed: 300
  });
// OTHER PROJECTS TOGGLE
  $("#other-project-toggle li a").click(function () {
    $(".port-option").css({backgroundColor:"#F6F3EA"});
    $(this).css({backgroundColor:"white"});
  });
// TOGGLE PORTFOLIO PIECES
  $("#slidebar a").click(function () {
    $(".port-entry").hide();
    if ($(this).attr("id").split('-')[0]=="all") {$(".port-entry").fadeIn("slow");} else {$(".port-"+$(this).attr("id").split('-')[0]).fadeIn("slow");}
  });

// FADE IMAGE ON HOVER
  $(".port-entry a img" || "#portfolio-preview a img").hover(function () {
    $(this).parent().css({backgroundColor:"#DEDBCA"});
    $(this).fadeTo(300, 0.5);
  }, function () {
    $(this).fadeTo(300, 1);
  });

 });
// SLIDEBAR CODE
(function($) {
$.fn.slidebar = function(o) {
	o = $.extend({ fx: 'linear', speed: 500, click: function(){return true}, linum: 'no' }, o || {});

	return this.each(function() {
		var path = location.pathname + location.search + location.hash;
		var $current = new Object;
		var $li = $('li', this);
		
		// check for complete path match, if so flag element into $current
		if ( o.linum == 'no' )
			$current = $('li a[href$="' + path + '"]', this).parent('li');
			
		// double check, this may be just an anchor match
		if ($current.length == 0 && o.linum == 'no')
			$current = $('li a[href$="' + location.hash + '"]', this).parent('li');

		// no default current element matches worked, or the user specified an index via linum
		if ($current.length == 0 || o.linum != 'no') {
			if (o.linum == 'no') o.linum = 0;
			$current = $($li[o.linum]);
		}

		var $back = $('<li class="back"><div class="left"></div><div class="bottom"></div><div class="corner"></div></li>').appendTo(this);
		var curr = $('li.current', this)[0] || $($current).addClass('current')[0];

		$li.not('.back').hover(function() {move(this);}, function(){});

		$(this).hover(function(){}, function() {move(curr);});

		$li.click(function(e) {
			setCurr(this);
			return o.click.apply(this, [e, this]);
		});

        setCurr(curr);

        function setCurr(el) {
            $back.css({ 'left': el.offsetLeft+'px', 
						'width': el.offsetWidth+'px', 
						'height': el.offsetHeight+'px', 
						'top': el.offsetTop+'px' });
            curr = el;
		};

		function move(el) { 
			$back.stop()
			.animate({
					width: el.offsetWidth,
					left: el.offsetLeft,
					height: el.offsetHeight,
					top: el.offsetTop
			}, o.speed, o.fx);
		};
	});
};
})(jQuery);

// EASING CODE
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
	def: 'easeOutSine',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	}
});