function unblockUI(type) {	

	$.unblockUI();	
	switch(type) {

		case 'login':
			window.location.replace("/home/login.php");	
			break;

		case 'register':
			window.location.replace("/home/signup.php");	
			break;

		case 'buy_time':
			window.location.replace("/home/buy.php");	
			break;

		case 'community_appointments':

			//Add the location of the message on the page
			if(location.href.match(/#community_appointments/)===null)
				location.href += '#community_appointments';
			location.reload();	
			break;

		case 'community_messages':

			//Add the location of the message on the page
			if(location.href.match(/#community_messages/)===null)
				location.href += '#community_messages';
			location.reload();	
			break;

		default: 
			break;

	}

}


function appointmentAdd(object, url, type) {

	switch(type) {

		case 'small':
			$('#community_appointment_input_box').css('background-image', 'url(/home/templates/images/community_message_sendBox.jpg)');
			$('#community_appointment_input_box').css('height', '262px');
			$('#community_appointment_input_box').html('<iframe src="' + url + '" width="748" height="261" frameborder="0"></iframe>');
			blockUI(262, 750, 'community_appointment_input');
			break;

		case 'large':
			$('#community_appointment_input_box').html('<iframe src="' + url + '" width="748" height="370" frameborder="0"></iframe>');
			blockUI(371, 750, 'community_appointment_input');
			break;
	}
}


function blockUI(height, width, elementId) {

	//Blocking the user interface and show the send message form
    $.blockUI({ 
		message: $('#'+elementId), 
        css: { 
	       'border': 'none', 
           'top':  ($(window).height() - height) /2 + 'px', 
           'left': ($(window).width() - 750) /2 + 'px', 
           'width': width+'px',
		   'height': height+'px'
		} 
    }); 
			
	//Unblock the UI when clicking on the grey overlay
	$('.blockOverlay').click(function(){	$.unblockUI();	}); 

}


function mypopup(mylink, windowname){
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')   href=mylink;
	else   href=mylink.href;
	window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
	return false;
}



/**
* assigns mouse events for phototacious buttons
*
*@param object		a jquery object
*@param handler		the type of handler mousedown, mouseup, mouseover & mouseout
*/
function phototaciousSwapImages() {

	$('img.phototacious').mousedown(function() {
		phototaciousSwapImage(this, 'mousedown');
	});

	$('img.phototacious').mouseup(function() {
		phototaciousSwapImage(this, 'mouseup');
	});

	$('img.phototacious').mouseout(function() {
		phototaciousSwapImage(this, 'mouseout');
	});

	$('img.phototacious').mouseover(function() {
		phototaciousSwapImage(this, 'mouseover');
	});

}
    

/**
* swaps image of phototacious around on mouse events down/up and over
*
*@param object		a jquery object
*@param handler		the type of handler mousedown, mouseup, mouseover & mouseout
*/
function phototaciousSwapImage(object, handler) {

	var image = $(object).attr('src');
	var match = image.match(/([^_]+)(.*).(png|gif|jpg)/);
	if(match===null)	return;

	switch(handler) {

		case 'mousedown':
			$(object).attr('src', match[1]+'_on.'+match[3]);
			break;
		case 'mouseup':
		case 'mouseover':
			$(object).attr('src', match[1]+'_over.'+match[3]);
			break;
		case 'mouseout':
			$(object).attr('src', match[1]+'.'+match[3]);
			break;
	}
}


