
/* Font replacement */



/* Tabs */

$(function() {
	$( "#tabs" ).tabs();
});






$(document).ready(function() {

/* Radio buttons */




/* Client grid */





/* Cycle */

$('#casestudies').cycle({ 
    fx:    'scrollHorz', 
    timeout:	0,
    next:   '#cs-next', 
    prev:   '#cs-prev'
});

$('#featuredclients').cycle({ 
    fx:    'scrollHorz', 
    timeout:	0,
    next:   '#fc-next', 
    prev:   '#fc-prev'
});

$('#featuredevents').cycle({ 
    fx:    'scrollHorz', 
    timeout:	0,
    next:   '#fe-next', 
    prev:   '#fe-prev'
});

$('#latestnews').cycle({ 
    fx:    'scrollHorz', 
    timeout:	0,
    next:   '#ln-next', 
    prev:   '#ln-prev'
});



/* Leadership team */

$('.person').hover(function(){  
	$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:500});  
}, function() {  
	$(".cover", this).stop().animate({top:'-230px'},{queue:false,duration:500});  
});  

/* Our clients */

$('#client1link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client1link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client1").slideDown();
return false;
});

$('#client1close').click(function() {
$("#client1link img").css( { "top": "0"} );
$("#client1").slideUp();
return false;
});

$('#client2link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client2link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client2").slideDown();
return false;
});

$('#client2close').click(function() {
$("#client2link img").css( { "top": "0"} );
$("#client2").slideUp();
return false;
});

$('#client3link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client3link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client3").slideDown();
return false;
});

$('#client3close').click(function() {
$("#client3link img").css( { "top": "0"} );
$("#client3").slideUp();
return false;
});

$('#client4link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client4link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client4").slideDown();
return false;
});

$('#client4close').click(function() {
$("#client4link img").css( { "top": "0"} );
$("#client4").slideUp();
return false;
});

$('#client5link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client5link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client5").slideDown();
return false;
});

$('#client5close').click(function() {
$("#client5link img").css( { "top": "0"} );
$("#client5").slideUp();
return false;
});

$('#client6link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client6link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client6").slideDown();
return false;
});

$('#client6close').click(function() {
$("#client6link img").css( { "top": "0"} );
$("#client6").slideUp();
return false;
});

$('#client7link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client7link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client7").slideDown();
return false;
});

$('#client7close').click(function() {
$("#client7link img").css( { "top": "0"} );
$("#client7").slideUp();
return false;
});

$('#client8link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client8link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client8").slideDown();
return false;
});

$('#client8close').click(function() {
$("#client8link img").css( { "top": "0"} );
$("#client8").slideUp();
return false;
});

$('#client9link').click(function() {
$(".clientlink img").css( { "top": "0"} );
$("#client9link img").css( { "top": "-155px"} );
$(".client").hide();
$("#client9").slideDown();
return false;
});

$('#client9close').click(function() {
$("#client9link img").css( { "top": "0"} );
$("#client9").slideUp();
return false;
});


/* Show hide */

if (!$("#subnav1 ul li.current_page_item")[0]) {
   $('#subnav1').addClass('off');
   $("#subnav1 div").hide();

}

if (!$("#subnav2 ul li.current_page_item")[0]) {
   $('#subnav2').addClass('off');
   $("#subnav2 div").hide();
   
}

if (!$("#subnav3 ul li.current_page_item")[0]) {
   $('#subnav3').addClass('off');
   $("#subnav3 div").hide();
   
}


$('#subnav1 h3').click(function() {
	$('#subnav1').toggleClass('off');
  $('#subnav1 div').slideToggle('medium', function() {
  });
});

$('#subnav2 h3').click(function() {
$('#subnav2').toggleClass('off');
  $('#subnav2 div').slideToggle('medium', function() {
    
  });
});

$('#subnav3 h3').click(function() {
$('#subnav3').toggleClass('off');
  $('#subnav3 div').slideToggle('medium', function() {
    
  });
});


/* Inputs */

$("input[type=text][title]").each(function () {
	$(this).val($(this).attr("title"));
	if ($.trim($(this).val()) == "") $(this).val($(this).attr("title"));
	$(this).focus(function () {
	if ($(this).val() == $(this).attr("title")) $(this).val("");
	}).blur(function () {
	if ($.trim($(this).val()) == "") $(this).val($(this).attr("title"));
	});
});

$.fn.lavaLamp = function(o) {
    o = $.extend({ fx: "linear", speed: 500, click: function(){} }, o || {});

    return this.each(function() {
        var me = $(this), noop = function(){},
            $back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
            $li = $("li", this), curr = $("li.current_page_item", this)[0] || $("li.current-page-ancestor", this)[0];

        $li.not(".back").hover(function() {
            move(this);
        }, noop);

        $(this).hover(noop, 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" });
            curr = el;
        };

        function move(el) {
            $back.each(function() {
                $.dequeue(this, "fx"); }
            ).animate({
                width: el.offsetWidth,
                left: el.offsetLeft
            }, o.speed, o.fx);
        };

    });
};

$("#menu-main").lavaLamp({
	fx: "backout",
	speed: 700
});

$("#menu-main-russian").lavaLamp({
	fx: "backout",
	speed: 700
});

$("#menu-main-usa").lavaLamp({
	fx: "backout",
	speed: 700
});

/*$.fn.lavaLamp2 = function(o) {
    o = $.extend({ fx: "linear", speed: 500, click: function(){} }, o || {});

    return this.each(function() {
        var me = $(this), noop = function(){},
            $back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
            $li = $("a", this), curr = $("a", this)[0];

        $li.not(".back").hover(function() {
            move(this);
        }, noop);

        $(this).hover(noop, function() {
            move(curr);
        });
		
		$("li a").click(function(e) {
		$('#timelinescale').find('.thing').removeClass('thing');
			$(this).parent().addClass('thing');
		});

		$li.click(function(e) {
            setCurr(this);
            return o.click.apply(this, [e, this]);
        });
        


        setCurr(curr);

        function setCurr(el) {
$back.each(function() {
                $.dequeue(this, "fx"); }
            ).animate({
                width: el.offsetWidth,
                left: el.offsetLeft
            }, o.speed, o.fx);
            curr = el;
        }

        
    });
}; */

/*$.fn.lavaLamp2 = function(o) {
    o = $.extend({ fx: "linear", speed: 500, click: function(){} }, o || {});

    return this.each(function() {
        var me = $(this), noop = function(){},
            $back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
            $li = $("li", this), curr = $("li.currenti", this)[0];

        $li.not(".back").find('a').click(function() {
		$yoyo = this.parent();
            move($yoyo);
        }, noop);

        $(this).find('a').click(noop, 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" });
            curr = el;
        };

        function move(el) {
            $back.each(function() {
                $.dequeue(this, "fx"); }
            ).animate({
                width: el.offsetWidth,
                left: el.offsetLeft
            }, o.speed, o.fx);
        };

    });
};*/

/*$('#tl-next').click(function() {
$('#timelinescale .thing').next('li').find('.ohlink').click();
});

$('#tl-prev').click(function() {
$('#timelinescale .thing').prev('li').find('.ohlink').click();
});*/

/* Our history */

$('#timelinecycle').cycle({ 
    fx:    'scrollHorz', 
    timeout:	0,
    next:   '#tl-next', 
    prev:   '#tl-prev',
    nowrap: 1
});

$('#year2003').click(function() { 
    $('#timelinecycle').cycle(0);
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on');
    return false;
});

$('#year2004').click(function() { 
    $('#timelinecycle').cycle(1);
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on');
    return false; 
}); 

$('#year2005').click(function() { 
    $('#timelinecycle').cycle(2); 
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on');
    return false; 
});

$('#year2006').click(function() { 
    $('#timelinecycle').cycle(3); 
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on');
    return false; 
}); 

$('#year2007').click(function() { 
    $('#timelinecycle').cycle(4); 
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on');
    return false; 
}); 

$('#year2008').click(function() { 
    $('#timelinecycle').cycle(5); 
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on');
    return false; 
}); 

$('#year2009').click(function() { 
    $('#timelinecycle').cycle(6); 
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on');
    return false; 
}); 

$('#year2010').click(function() { 
    $('#timelinecycle').cycle(7); 
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on');
    return false; 
}); 

$('#year2011').click(function() { 
    $('#timelinecycle').cycle(8);
    $('#timelinescale').find('.on').removeClass('on');
	$(this).addClass('on'); 
    return false; 
}); 

$('#tl-next').click(function() {
$('#timelinescale .on').removeClass('on').parent().next().find('a').addClass('on');

});

$('#tl-prev').click(function() {
$('#timelinescale .on').removeClass('on').parent().prev().find('a').addClass('on');

});

/*$("#timelinescale").lavaLamp2({
	fx: "backout",
	speed: 700

});*/

$('.opportunity h4').click(function() {
  $(this).parent().find('div').toggle();
  $(this).parent().toggleClass('hidden');
});

});

$('.button').click(function(e) {
              $('.all').quicksand( $('.warm li'), {
                duration: 3000,
                attribute: 'id',
                easing: 'easeInOutQuad'
              });
              e.preventDefault();
            });


(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);
      
          // DOMContentLoaded
          $(function() {
          
            // bind radiobuttons in the form
          	var $filterType = $('#filter input[name="type"]');
          	var $filterSort = $('#filter input[name="sort"]');
        	
          	// get the first collection
          	var $applications = $('#applications');
        	
          	// clone applications to get a second collection
          	var $data = $applications.clone();

            // attempt to call Quicksand on every form change
          	$filterType.add($filterSort).change(function(e) {
          		if ($($filterType+':checked').val() == 'all') {
          			var $filteredData = $data.find('li');
          		} else {
          			var $filteredData = $data.find('li[data-type=' + $($filterType+":checked").val() + ']');
          		}
            
              // if sorted by size
          		if ($('#filter input[name="sort"]:checked').val() == "size") {
          			var $sortedData = $filteredData.sorted({
          				by: function(v) {
          					return parseFloat($(v).find('span[data-type=size]').text());
          				}
          			});
          		} else {
          		// if sorted by name
          			var $sortedData = $filteredData.sorted({
          				by: function(v) {
          					return $(v).find('strong').text().toLowerCase();
          				}
          			});
          		}   
        		
          		// finally, call quicksand
          	  $applications.quicksand($sortedData, {
          	    duration: 800,
          	    easing: 'easeInOutQuad'
          	  });

          	});
          
          });
