/*----------------------------------------------------------

* File Name: global.js

----------------------------------------------------------*/

// Start the functions for animating the search box
function search_reveal(_trigger /* HTML trigger link */, _node /* HTML element */){
	var _boo = false,	
		_height = $(_node).outerHeight();
	$(_node).css({
		'height': 0,
		'overflow': 'hidden'
	});
	$(_trigger).click(function(e) {
		if(_boo === false){
			$(_node).animate({
				'height': _height
			});
			_boo = true;
		} else if(_boo === true) {
			$(_node).animate({
				'height': 0
			});
			_boo = false;
		}
		e.preventDefault();
	});
};
// End the functions for animating the search box

// Start the functions for animating the case studies.
function slider_style(_node /* HTML element */) {
	$(_node).each(function() {
		$(this).css({
			'position': 'absolute'
		});
	});
};
function slider_nav_style(_node /* HTML element */) {
	var _children = $(_node).length,
		_width = $(_node).width(),
		_parent_width = _children * _width;
	$(_node).parents("ul").css({
		"position": "relative",
		"width": _parent_width,
		"left": "50%",
		"marginLeft": - (_parent_width / 2)
	});
};
function slider(_trigger /* HTML trigger link */, _node /* HTML element */) {
	var _max = $(_node).length,
		_parent = $(_node).parent();
		_heights = create_array(_node);
	$(_parent).css({
		'height': _heights[0]
	});
	$(_trigger).click(function(e) {
		var _id = $(this).attr("rel");
		if(!$(this).hasClass("active")){
			slider_animate(_id, _heights, _node, _parent);
			$(_trigger).removeClass("active");
			$(this).addClass("active");
		}
		e.preventDefault();
	});
};
function slider_animate(_id /* Identifier */, _heights /* Array */, _node /* HTML element */, _parent /* HTML element */) {
	$(_node).fadeOut(500);
	$(_parent).animate({
		'height': _heights[_id]
	}, {queue: false}, 500);
	$(_node).eq(_id).fadeIn(500);
};
function create_array(_node /* HTML element */) {
	var _arr = [];
	$(_node).each(function() {
		_arr.push($(this).height());
	});
	return _arr;
};
// End the functions for animating the case studies.

// Start the functions for animating the gallery.
function gallery_style(_node /* HTML element */) {
	$(_node).each(function() {
		$(this).css({
			'position': 'absolute'
		});
	});
};
function gallery_nav_style(_node /* HTML element */) {
	var _children = $(_node).length,
		_width = $(_node).width(),
		_parent_width = _children * _width;
	$(_node).parents("ul").css({
		"position": "relative",
		"width": _parent_width,
		"left": "50%",
		"marginLeft": - (_parent_width / 2)
	});
};
function gallery(_trigger /* HTML trigger link */, _node /* HTML element */) {
	var _max = $(_node).length,
		_parent = $(_node).parent();
	$(_trigger).click(function(e) {
		var _id = $(this).attr("rel");
		if(!$(this).hasClass("active")){
			gallery_animate(_id, _node, _parent);
			$(_trigger).removeClass("active");
			$(this).addClass("active");
		}
		e.preventDefault();
	});
};
function gallery_animate(_id /* Identifier */, _node /* HTML element */, _parent /* HTML element */) {
	$(_node).fadeOut(500);
	$(_node).eq(_id).fadeIn(500);
};
// End the functions for animating the gallery
