 $(document).ready(function(){
   
/* Cycle functions */
	$('#feature_control_play_holder').hide();

	$('#preview').cycle({
		fx: 'scrollHorz',
		speed: 1000,
		prev: '#preview,#feature_control_previous_holder a',
		next: '#feature_control_next_holder a',
		timeout: 5000
	});

	$('#feature_control_pause_holder a').click(function (){
		$('#preview').cycle('pause');
		$('#feature_control_pause_holder').hide();
		$('#feature_control_play_holder').show();
		return false;
	});

	$('#feature_control_play_holder a').click(function (){
		$('#preview').cycle('resume');
		$('#feature_control_pause_holder').show();
		$('#feature_control_play_holder').hide();
		return false;
	});


/* end of cycle function */

var z = 0; //for setting the initial z-index's
  var inAnimation = false; //flag for testing if we are in a animation

  $('#pictures img').each(function() { //set the initial z-index's
    z++; //at the end we have the highest z-index value stored in the z variable
    $(this).css('z-index', z); //apply increased z-index to <img>
  });

  function swapFirstLast(isFirst) {
    if(inAnimation) return false; //if already swapping pictures just return
    else inAnimation = true; //set the flag that we process a image

    var processZindex, direction, newZindex, inDeCrease; //change for previous or next image

    if(isFirst) { processZindex = z; direction = '-'; newZindex = 1; inDeCrease = 1; } //set variables for "next" action
    else { processZindex = 1; direction = ''; newZindex = z; inDeCrease = -1; } //set variables for "previous" action
    $('#pictures img').each(function() { //process each image
      if($(this).css('z-index') == processZindex) { //if its the image we need to process
        $(this).animate({ 'top' : direction + $(this).height() + 'px' }, 'slow', function() { //animate the img above/under the gallery (assuming all pictures are equal height)
          $(this).css('z-index', newZindex) //set new z-index
            .animate({ 'top' : '0' }, 'slow', function() { //animate the image back to its original position
              inAnimation = false; //reset the flag
            });
        });
      } else { //not the image we need to process, only in/de-crease z-index
        $(this).animate({ 'top' : '0' }, 'slow', function() { //make sure to wait swapping the z-index when image is above/under the gallery
          $(this).css('z-index', parseInt($(this).css('z-index')) + inDeCrease); //in/de-crease the z-index by one
        });
      }
    });

    return false; //don't follow the clicked link
  }

  $('#next_btn_holder a').click(function() {
    return swapFirstLast(true); //swap first image to last position
  });

  $('#prev_btn_holder a').click(function() {
    return swapFirstLast(false); //swap last image to first position
  });

/* scrolling */
$.localScroll.hash()
$('#what_we_do_holder').localScroll();
$("#rates_holder").localScroll();

/* tooltips */

$('.quote_tooltip').bt({showTip: function(box){$(box).fadeIn(500);},hideTip: function(box,callback){$(box).animate({opacity: 0}, 500, callback);},shrinkToFit: true,hoverIntentOpts: {interval: 0,timeout: 0}, fill: 'rgb(232, 221, 191)', strokeWidth: 3, strokeStyle: '#B8A491', backgroundImage: '/img/quote_paper.gif', cssStyles: {fontFamily: 'Georgia, "Times New Roman", Times,serif', lineHeight: '30px', textAlign: 'center', backgroundImage: 'url(/img/paper_bg.gif)', color: '#684F3E', fontSize: '16px'}});

/* portfolio filter */

  $('#web_link').click(function() {
	filter_class(".web");
	return false;
  });

  $('#print_link').click(function() {
	filter_class(".print");
	return false;
  });

  $('#brand_link').click(function() {
	filter_class(".brand");
	return false;
  });

  $('#squirrels_link').click(function() {
	$("#projects_row_list li").fadeIn("fast");
	return false;
  });


function filter_class(class_name) {
	$("#projects_row_list li").hide();
	$("#projects_row_list li").filter(class_name).fadeIn("fast")
}

/* portfolio fancy box */

if ((screen.width<=1024) && (screen.height<=768)) {
$(".project_info_btn_holder a.screen").fancybox(); 
}
else {
$(".project_info_btn_holder a.screen").fancybox({'imageScale':false}); 
}





 });

