//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
$(document).ready(function(){
	$("#mainnav").menumaker({
		menu_speed:	50,
		offset_mode:	"left"
	})
	
	$('.comment-list a[href^="http://"]').attr("target", "out");
	
	//---------------------------------------------------------------------------------------------
	//	Toggle
	//---------------------------------------------------------------------------------------------
	$('a.toggler').toggle(function(event) {
		event.preventDefault();
		var target = $(this).attr('rel');
		$(target).slideDown();
		$(this).closest('.inside').css('background-image','none');
	}, function(event) {
		event.preventDefault();
		var target = $(this).attr('rel');
		$(target).slideUp();
		$(this).closest('.inside').css('background-image',"url('/site/images/left_sidebar_bottom.gif')");
	});

	//---------------------------------------------------------------------------------------------
	//	Case Study Toggle
	//---------------------------------------------------------------------------------------------
	$('a.case-toggler').click(function(event) {
		event.preventDefault();
		$(this).parent().hide();
		var target = $(this).attr('rel');
		$(target).slideDown();
	});

	//---------------------------------------------------------------------------------------------
	//	Input labels
	//---------------------------------------------------------------------------------------------
	$('.fieldblock .textfield').focus(function(event){
		$(this).closest('.fieldblock').children('label').animate( { "opacity" : .5 }, 250 );
	});

	$('.fieldblock .textfield').keydown(function(event){
		$(this).closest('.fieldblock').children('label').fadeOut();
	});
	
	$('.fieldblock .textfield').blur(function(event){
		if (!$(this).val()) {
			$(this).closest('.fieldblock').children('label').animate( { "opacity" : 1 }, 250 );
		};
	});
	
	//---------------------------------------------------------------------------------------------
	//	Popup Window
	//---------------------------------------------------------------------------------------------
	$('.popup').click(function(event){
		event.preventDefault();

		var url = $(this).attr('href');
		var w = 400;
		var h = 430;
		var left = (screen.width/2)-(w/2);
		var top = (screen.height/2)-(h/2);
		
		window.open(url,'popup','height='+h+',width='+w+',scrollbars=1, top='+top+', left='+left);
	});
});

//---------------------------------------------------------------------------------------------
//	Slideshow
//---------------------------------------------------------------------------------------------
function changeSlide(newSlide,oldSlide,slideCount,index) {
	if (newSlide > slideCount) {
		newSlide = 1;
	} else if (newSlide < 1) {
		newSlide = slideCount;
	}
	
	if (oldSlide != newSlide) {
		$('#slide-'+index+'-'+ oldSlide).fadeOut();
		$('.slide-nav-dots a').removeClass('active');
		$('#slide-'+index+'-'+newSlide).fadeIn();
		$('#current-slide-'+index).html(newSlide);
		$('.slide-nav-dots a[rel='+newSlide+']').addClass('active');
	};
	return newSlide;
};

