//center height
function animW() {
	if($(this).hasClass('hidden')){
	$(this).animate({opacity : 'toggle'}, 300);
	$(this).removeClass('hidden');
	}else{
		
	}
}
function animWC() {
	if($(this).hasClass('hidden')){return false;
	}else{
	$(this).animate({opacity : 'toggle'}, 300);
	$(this).addClass('hidden');
	}
}


function centerHeight() {
	contH = $('#layGlobalWrapper').height();
	winHeight = $(window).height();
	newMargin = (winHeight-contH)/2;
	if (newMargin > 0){
	$(this).css({'margin-top': newMargin+'px','margin-bottom': newMargin+'px'});
	}
}

$(document).ready(function(){
   contH = $('#layGlobalWrapper').height();
	winHeight = $(window).height();
	newMargin = (winHeight-contH)/2;
	if (newMargin > 0){
	$(this).css({'margin-top': newMargin+'px','margin-bottom': newMargin+'px'});
	}
});

$(window).resize(function(event){
   contH = $('#layGlobalWrapper').height();
	winHeight = $(window).height();
	newMargin = (winHeight-contH)/2;
	if (newMargin > 0){
	$(this).css({'margin-top': newMargin+'px','margin-bottom': newMargin+'px'});
	}
});

//gallery
$(document).ready(function() {
	$('#media-gallery').cycle({
				  fx: 'fade',
				  speed:  500,
				  timeout: 0,
				  containerResize: 0,
				  pager: '#media-pager',
				  pagerEvent: 'click',
				  next: '#media-gallery img',
				  after: onAfter,
				  // callback fn that creates a thumbnail to use as pager anchor 
					pagerAnchorBuilder: function(idx, slide) {
						isrc = $(slide).find('img.single-thumb').attr('src');
						return '<a href="javascript:void(0)"><img src="' + isrc + '" /></a>';
						
					}
        });
	function onAfter(){
			var descr = $(this).find('img').attr('title');
			var parent = $(this).parents('div.content-con');
			$(parent).find('.post-content').text(descr);
	}
	$("div.scrollable").scrollable({size: 8});
});

//content overflow handler

$.fn.initializeScroll = function() {
	$(this).jScrollPane({scrollbarOnLeft:false, scrollbarWidth: 11, wheelSpeed: 50, showArrows: true });
}

$(document).ready(function(){
	$('.post-content').initializeScroll();
});

//go home / hide window
function close_window(closer){
	 	par = $(closer).parent();
	 	$(par).animate({opacity : 'toggle'}, 300);
		$(par).addClass('hidden');
}

function close_open_window(){
		$( ".content-con" ).each(
		function(i){
				if ($(this).hasClass('hidden')){return false;}
					else{
						$(this).animate({opacity : 'toggle'}, 300);
						$(this).addClass('hidden');
					}
			   }
		);
}


//dropdowns
$(document).ready(function() {
	submenu = $('li.page_item > div.sub-cont');
	subparent = $(submenu).parent();
	$(submenu).hide();
	$(subparent).hover(function() {
		  $(submenu).show();
	});
	$(subparent).mouseleave(function() {
		  $(submenu).hide();
	});
});

//misc
$(document).ready(function(){
	$('.wpcf7-form-control-wrap').hover(function(){
		 $(this).find('span.wpcf7-not-valid-tip-no-ajax').animate({opacity: 0},400,function(){$(this).css('display','none');});
	 });
});


//Anchor Slider by Cedric Dugas http://www.position-absolute.com
$(document).ready(function() {
	$("a.anchor-link, .anchor-link a").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;
		})
	})
}
