// JavaScript Document

   var $container = $('#content-wrapper');
   
      // sorting
      $('#sort a').click(function(){
	  	//Kill Switch
		if ($(this).hasClass("selected-button" && $(this).attr("id") != "button1")) {return false;}
		$('.selected-button').removeClass("selected-button");
		$(this).addClass('selected-button') ;
		
        // get href attribute, minus the #
        var $this = $(this),
            sortName = $this.attr('href').slice(1),
            asc = $this.parents('.sort').hasClass('asc');
        $container.isotope({ 
          		sortBy : sortName,
          		sortAscending : true
        });
		if (sortName == "homepage") {
		$('.side').each(function() {
			var w = Math.random()*200;
			$(this).animate({"width": w}, "slow");
			})
			}
		if (sortName == "about") {
		$('.side').each(function() {
			if ( $(this).hasClass('w_About') ) {
				$(this).animate({"width": "350px"}, "slow");
				}
			else if ( $(this).hasClass('w2_About') ) {
				$(this).animate({"width": "80px"}, "slow");
				}
			else {
				$(this).animate({"width": "0px"}, "slow");
				}
			})
		}
		if (sortName == "services") {
			$('.side:odd').each(function() {
				$(this).animate({"width":"10px"}, "slow");
				})
			$('.side:even').each(function() {
				$(this).animate({"width":"0px"}, "slow");
				})
		}
		if (sortName == "contact") {
			$('.side').each(function() {
				$(this).animate({"width":"120px"}, "slow");
				})
		}
		if (sortName == "work") {
			$('.side').each(function() {
				$(this).animate({"width":"0px"}, "slow");
				})
		}	
		
        return false;
		
      });
    
    
      // switches selected class on buttons
      $('#options').find('.option-set a').click(function(){
        var $this = $(this);

        // don't proceed if already selected
        if ( !$this.hasClass('selected') ) {
          $this.parents('.option-set').find('.selected').removeClass('selected');
          $this.addClass('selected');
        }

      });

// animating divs 1
	$('#ani').click(function (){
		$('.side').animate({"width": "0px"}, "slow");
		})
	$('#ani2').click(function (){
		$('.side').each(function() {
			var w = Math.random()*200;
			$(this).animate({"width": w}, "slow");
			})
		})

   
   $container.isotope({
  // options
  itemSelector : '.brick',
  layoutMode : 'masonry',
 
  resizesContainer : false,
 // animationEngine : 'jquery',
  getSortData : {
           homepage : function ( $elem ) {
   				 return $elem.attr('homepage');
  					},
			about : function ( $elem ) {
   				 return $elem.attr('about');
  					},
			services : function ( $elem ) {
   				 return $elem.attr('services');
  					},
			contact : function ( $elem ) {
   				 return $elem.attr('contact');
  					},
			work : function ( $elem ) {
   				 return $elem.attr('work');
  					},
				}

});

$('.brick').css("display","block") ; //Wait for the Isotope to Load before visibility


      // hacky way of adding random size classes
      $('.side').each(function(){
        var w = Math.random()*200;
			var gray = (Math.floor(Math.random() * 7 + 25))
		 	var col = 'rgb(' + gray + ',' + gray + ',' + gray + ')';
			$(this).css("background-color", col);
			$(this).animate({"width": w}, "slow");
			});
       
//Just For Fun
	function color() {
		$('.background').css("background-image", "none");
		 var col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
		$('.background').css("background-color", col);
	
	return false; }
	
	function color2() {
		$('.background').each(function() {
		$(this).css("background-image", "none");
		 var col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
		$(this).css("background-color", col);
		})
	return false; }
	
	function color3() {
		$('.background').each(function() {
		$(this).css("background-image", "none");
		var gray = (Math.floor(Math.random() * 256))
		 var col = 'rgb(' + gray + ',' + gray + ',' + gray + ')';
		$(this).css("background-color", col);
		})
	return false; }
	
		function color4() {
		$('.background').each(function() {
			var bgImage = Math.floor(Math.random()*11)
			var image = "url(images/random/turtles/" + bgImage + ".jpg)"
			$(this).css("background-image", image);
			})
		}

