$(document).ready(function(){
	
	/* set the starting bigestHeight variable */
	var biggestHeight = 0;
	
	/* check each of them */
	$('.equal_height').each(function(){
		
		/*
			if the height of the current element is bigger 
			then the current biggestHeight value
		*/
		
		if($(this).height() > biggestHeight){
			/* update the biggestHeight with the height of the current elements */
			biggestHeight = $(this).height();
		}
	});
	
	/* when checking for biggestHeight is done set that height to all the elements */
	$('.equal_height').height(biggestHeight);
	
	$('a[rel=lightbox]').lightBox({
		imageLoading: 			'/img/libs/jquery-lightbox-0.5/lightbox-ico-loading.gif',
		imageBtnClose: 			'/img/graficos/lightbox/close.png',
		imageBtnPrev: 			'/img/graficos/lightbox/prev.png',
		imageBtnNext: 			'/img/graficos/lightbox/next.png',
		containerResizeSpeed: 	350,
		txtImage: 				'Imagen',
		txtOf: 					'de'
	});

});


/* Los enlaces que tengan el atributo rel="external" se abren en una nueva página */
$(document).ready(function(){
    $('a[rel^="external"]').attr({ target: "_blank", title: "Abre en una nueva p\u00E1gina" });
});


// Create our namespace
var Website = {};

/**
 * Outline our webservices
 * @param {String} action - AJAX action to perform
 * @param {Object} payload - Javascript object containing AJAX method properties
 */

Website.Webservice = function (action, payload) {

	switch (action){
	case 'create':
		payload.type = 'POST';
		payload.url = '/ajax/create_data.php';
		break;
	
	case 'read':
		payload.type = 'GET';
		payload.url = '/ajax/get_data.php';
		break;

	case 'update':
		payload.type = 'POST';
		payload.url = '/ajax/update_data.php';
		break;

	case 'delete':
		payload.type = 'POST';
		payload.url = '/ajax/delete_data.php';
		break;
	}

	// Call the global AJAX method
	Website.AJAX(payload);

};

/**
 * Fires off the AJAX object with user defined payload information.
 * @param {Object} payload - AJAX data options to bind to the jQuery object
 */

Website.AJAX = function (payload) {

	// If dataType wasn't specified in the payload, default to 'html'
	var dataType = (payload.dataType !== undefined) ? payload.dataType : 'html';

	// jQuery AJAX object
	$.ajax ({

		// Normal properties
		type: 		payload.type,
		url: 		payload.url,
		data: 		payload.data,
		dataType: 	dataType,

		// Global beforeSend wrapper with user defined function
		beforeSend: function () {

			// Execute some global method here

			// Execute user defined method
			if (typeof payload.beforeSend === 'function'){
				payload.beforeSend();
			}
		},
		
		// Global success wrapper with user defined function
		success: function (data) {

			// Execute some global method here

			// Execute user defined method
			if (typeof payload.success === 'function') {
				payload.success(data, payload.success_extra_params);
			}
		}
	});
};
