// JavaScript Document
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

$(document).ready(function(){
						   
	$("#dialog-form").dialog({ 
		autoOpen: false,
		height: 400,
		width: 650,
		modal: true,
		close: function(event, ui) { 
			$("#stud_date").datepicker("disable");
			$("#stud_bdate").datepicker("disable");
			$("#stud_dateofbaptism").datepicker("disable");
		}
	})
	
	$('#castrillo-banner-slider').cycle({
		fx: 'fade',
		startingSlide: Math.floor(Math.random() * 2),
		speed:  3500,
		timeout: 3500
	});
	
	$("ul.photo-gallery-pics li").hover(function() {
		$(this).css({'z-index' : '100'}); 
		$(this).find('img').stop() 
			.animate({
				marginTop: '-10px',
				marginLeft: '-10px',
				top: '-10px',
				left: '-10px',
				width: '118px',
				height: '108px'
			}, 200); 

		} , function() {
		$(this).css({'z-index' : '0'});
		$(this).find('img').stop()  
			.animate({
				marginTop: '0', 
				marginLeft: '0',
				top: '0',
				left: '0',
				width: '98px',
				height: '88px',
				padding: '0px'

			}, 500);
	});

});

function close_main_photo() {
	slideContainerWidth = 636;
	$('#sliderContainer').animate({
		'marginLeft' : slideContainerWidth*(-1)
	});
	$('#photo-gallery-content-big').html("");
}

function showGalleryPhoto(txtpath, galleryphoto_id) {
	$('#image-loader-div').fadeIn();
	$.ajax({
	  url: txtpath+'/'+galleryphoto_id,
	  success: function(data) {
		  $('#image-loader-div').fadeOut();
		  $('#photo-gallery-content-big').html(data);
		  $('#sliderContainer').animate({
				'marginLeft' : 0
			});
	  }
	});
}

function loadPhotoPage(page,totalpage,txtpath) {
	$('#photo-gallery-thumb-content').hide(100);
	$.ajax({
	  url: txtpath+'/'+page,
	  success: function(data) {
		  $('#photo-gallery-thumb-content').html(data);
		  $('.photo-gallery-pagination').html('<center>'+page+' of '+totalpage+'</center>');
		  $('#photo-gallery-thumb-content').show(100);
	  }
	});
}
	
function header_menu_mouseover(objname, txt) {
	$(objname).html(txt);
}

function header_menu_mouseout(objname, txt) {
	$(objname).html(txt);
}

function load_parentform_ajax(txtpath) {
	$('#dialog-form').dialog('open');
	$('#parents-form').load(txtpath);
}

function delete_confirm(txtpath) {
	var answerdelete = confirm("Are you sure you want to delete this?");
	if (answerdelete) {
		window.location = txtpath;
	} else {
		alert("Delete cancel");
	}
	return false;
}

function password_hashmd5(tbid) {
	(function($) { 
		txtpass = $(tbid).val();
		var s_txtpass = new String(txtpass);
		txtpass = s_txtpass.trim();
	})(jQuery);
	hashmd5 = hex_md5(txtpass);
	(function($) { 
		$(tbid).val(hashmd5);
	})(jQuery);
}
