//center height

$.fn.centerHeight = function() {
	contH = 540;
	winHeight = $(window).height();
	newMargin = (winHeight-540)/2;
	if (newMargin > 0){
	$(this).css({'margin-top': newMargin+'px'});
	}
}
$(document).ready(function(){
   $('#container').centerHeight();
});
$(window).resize(function(event){
   $('#container').centerHeight();
});

//inline form titles
$(document).ready(function() {
	$('input[name]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('name'));
		}

		$(this).focus(function() {
			if($(this).val() === $(this).attr('name')) {
				$(this).val('').addClass('focused');
			}
		});

		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('name')).removeClass('focused');
			}
		});
	});
});

//content overflow handler

$(document).ready(function(){
			$('.main-content').jScrollPane({scrollbarOnLeft:false, scrollbarWidth: 8, wheelSpeed: 50});
		/*$( ".main-content" ).each(
		// For each hottie, run this code. The "indIndex" is the
		function( intIndex ){
				   var $bodyH = $(this).height();
			   if ($bodyH > 480){
				   $(this).css({'padding-top': 10+'px', 'min-height': 530+'px'});
			   }
			}
		);*/
});



//single attachment gallery
$.fn.zoomShow = function() { 
	$(this).animate({width: 'toggle', opacity: 'toggle'},300, function(){$(this).toggleClass('visible');});
}
$(document).ready(function(){
	$(".gal-zoom").hide();
	$(".aux-content img").mouseover(function(event){
	  	$(this).parents('.single-project').find('.gal-zoom').zoomShow();
	  });
	$(".gal-zoom").mouseleave(function(event){
		if($(this).hasClass('visible')){
	  	$(this).zoomShow();
		}
	  });
	$(".close-zoom").click(function(event){
	  	$(this).parent().zoomShow();
	  });
});
$('#projects-gallery').cycle({ 
          fx: 'fade', 
          speed:  500, 
          timeout: 0, 
		  containerResize: 0,
		  pager: '#gallery-pager',
		  pagerEvent: 'mouseover',
		  // callback fn that creates a thumbnail to use as pager anchor 
			pagerAnchorBuilder: function(idx, slide) { 
				isrc = $(slide).find('img.single-thumb').attr('src');
				subPageLink = $(slide).find('a.dummy').attr('href');
				if(subPageLink != null) {thumbLink = subPageLink;}else{thumbLink = '#';}
				return '<li><a target="_blank" href="' + thumbLink + '"><img src="' + isrc + '" /></a></li>'; 
			} 
        });
$(document).ready(function() { 
        $("#gallery-pager li").click(function () { 
                var url = $(this).find("a").attr('href'); 
                window.location = url; 
        }); 
});
$('#main-gallery').cycle({ 
          fx: 'fade', 
          speed:  1000, 
          timeout: 3000, 
          next: '#main-gallery img',
		  pager: '#gal-pager',
		  containerResize: 0,
		  before: onBefore,
		  after: onAfter,
		  pager: '#gallery-pager',
		  // callback fn that creates a thumbnail to use as pager anchor 
			pagerAnchorBuilder: function(idx, slide) { 
				return '<li><a href="#"><img src="' + slide.src + '" /></a></li>'; 
			} 
        });
function onBefore(){
	heightG = $(this).height();
	widthG = $(this).width();
	$("#main-gallery").animate({height: heightG+8+'px', width: widthG+8+'px'}, 300);
	$(this).parent().find('img.current-slide').removeClass('current-slide');
}
function onAfter(){
		$(this).addClass('current-slide');
}

//Anchor Slider by Cedric Dugas http://www.position-absolute.com
$(document).ready(function() {
	$("a.anchor-link").anchorAnimate()
});

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 400
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}