var postedProject="";

$(document).ready(function($) {

	

$('#carousel-casing') 
.after('<div id="carousel-nav">') 
.cycle({ 
   fx: 'fade',
				speed: 2000,
				timeout: 8000,

    pager:  '#carousel-nav' 
});


function setRollOvers()
{

$("#projects li").mouseover(function()
{
	var target = $(this).find("div.project-info");
	target.stop().animate({ 
         opacity: 0.8,
        marginTop: "-125px"
      }, 800 );
	
});

$("#projects li").mouseout(function()
{
	var target = $(this).find("div.project-info");
	target.stop().animate({ 
         opacity: 0,
        marginTop: "0px"
      }, 800 );
    
});
}

setRollOvers();


// Custom sorting plugin
(function($) {
  $.fn.sorted = function(customOptions) {
    var options = {
      reversed: false,
      by: function(a) { return a.text(); }
    };
    $.extend(options, customOptions);
    $data = $(this);
    arr = $data.get();
    arr.sort(function(a, b) {
      var valA = options.by($(a));
      var valB = options.by($(b));
      if (options.reversed) {
        return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;				
      } else {		
        return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;	
      }
    });
    return $(arr);
  };
})(jQuery);


$(function() {
	
	 var $filterType = $('.projects-all a');
	 $filterType.click(function(e) 
	 {
	 	 	e.preventDefault();
	 	 	 var targetClass = $(this).attr("class");
	 	 	 $("input#projecttype").val("all");
	 	 	$('#target').submit();

	 });
	 
});


$(function() {
	
	 var $filterType = $('#side-menu-projects ul li a');
	 $filterType.click(function(e) 
	 {
	 	 	e.preventDefault();
	 	 	 var targetClass = $(this).attr("class");
	 	 	 $("input#projecttype").val(targetClass);
	 	 	$('#target').submit();

	 });
	 
});


// DOMContentLoaded
$(function() {

  // bind radiobuttons in the form
  var $filterType = $('.projects-all a');
  
  // get the first collection
  var $projectlist = $('#projects');

  // clone applications to get a second collection
  var $data = $projectlist.clone();

  // attempt to call Quicksand on every form change
  $filterType.click(function(e) {
  	e.preventDefault();
$('#side-menu ul li').removeClass("active");
    var $filteredData = $data.find('li').removeClass('no-show').addClass('show');
   
    // finally, call quicksand
    $projectlist.quicksand($filteredData, {
      duration: 800,
      easing: 'easeInOutQuad'
    }, function() 
    {
		setRollOvers();
    });
  });
});

	
// DOMContentLoaded
$(function() {

  // bind radiobuttons in the form
  var $filterType = $('#side-menu ul li a');
  
  // get the first collection
  var $projectlist = $('#projects');

  // clone applications to get a second collection
  var $data = $projectlist.clone();

  // attempt to call Quicksand on every form change
  $filterType.click(function(e) {
  	e.preventDefault();
	
	$('#side-menu ul li').removeClass("active");
	$(this).parent().addClass("active");
    var targetClass = $(this).attr("class");

   if (targetClass == 'all') 
   {
      var $filteredData = $data.find('li');
   } 
   else 
   {
         var $filteredData = $data.find('li.'+targetClass).removeClass('no-show').addClass('show');
   }
    // finally, call quicksand
    $projectlist.quicksand($filteredData, {
      duration: 800,
      easing: 'easeInOutQuad'
    }, function() 
    {
		setRollOvers();
    });
  });
});

function manualSort(manualClass)
{
  var $projectlist = $('#projects');

  // clone applications to get a second collection
  var $data = $projectlist.clone();
  	if(manualClass == "all")
  	{
  		var $filteredDataManual = $data.find('li').removeClass('no-show').addClass('show');
  	}
  	else
  	{
		var $filteredDataManual = $data.find('li.'+manualClass);
	}
	 $projectlist.quicksand($filteredDataManual, {
      duration: 800,
      easing: 'easeInOutQuad'
    }, function() 
    {
		setRollOvers();
    });
   }

if(postedProject)
{
	manualSort(postedProject);
}
});

