//extra functions from webtoolkit
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}



//for photo gallery
function show_big_photo(fn) {

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		//$('#mask').fadeIn(1000);	
		$('#mask').fadeTo(400,0.8);	
		//~ $("#mask").css({
			//~ "background-image":"url('images/img_loader.gif')",
			//~ "background-repeat":"no-repeat",
			//~ "background-position":"center"
			//~ });
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		var w = 0;
		var h = 0;
		var p = 0;
        var id = "#dialog";		
		//var img = document.getElementById("pic");
		var adjust = getScrollXY();	//kunin natin amount ng scrolled vertically in pixels
		$("#loader").css({	"top": adjust + (winH / 2) - (42 / 2),
							"left": (winW / 2) - (42 / 2)});
		
		$("#loader").fadeTo(400, 0.8);
		
		
			var img = new Image();
			$("#pic").append(img);
			$(img).attr("class","bigpic");
			$(img).load(function() {
				//$("#mask").css("background-image","none");
				w = $(this).attr('width');
				h = $(this).attr('height');
				if (w > h) {
					p = 500 / w;
				} else {
					p = 400 / h;
				}		
				p = 1;		
				//alert(img.width);
				$(this).attr("width", w * p);
				$(this).attr("height", h * p);
				$(id).width(w);
				$(id).css('top', adjust + winH/2-$(id).height()/2);
				$(id).css('left', winW/2-$(id).width()/2);
				//transition effect
				$(id).fadeIn(400); 
			}).attr('src', fn);				
		
	

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').hide();
		$(".bigpic").remove();
		$("#loader").hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
		$(".bigpic").remove();
		$("#loader").hide();
	});	
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}

