/**
 ** __animate_gallery_image
 ** __bind_tabs_click_handler
 ** __disable_buttons
 ** __format_phone
 ** __get_quick_login
 ** __handle_plus_on_resize
 ** __submit_contact_form
 **/
 
function __animate_gallery_image()
{
	if (jQuery('#gallery-image').length > 0)
	{
		jQuery('#gallery-image')
			.stop()
			.mouseover(
				function()
				{
					var position = jQuery('#gallery-image').position();
					
					jQuery('#plus')
						.appendTo('#text')
						.css({
							'display': 'block',
							'left': (position.left) + 'px',
							'top': (position.top + 20) + 'px'
						});
					
					jQuery('#gallery-image').fadeTo(200,0.5);
				}
			).
			mouseout(
				function()
				{
					jQuery('#gallery-image').fadeTo(200,1.0);	
				}
			);
	}
}
 
function __bind_tabs_click_handler()
{
	if (jQuery('#tabs a').length > 0)
	{
		jQuery('#tabs a').click
		(
			function()
			{	
				jQuery('#tabs a').removeClass('active');
				jQuery(this).addClass('active');
				
				jQuery.ajax
				(
					{
						type: 		'POST',
						url: 		'/rpc.php?mode=get_sidebar_content',
						data: 		'mode=get_sidebar_content&tab=' + jQuery(this).text().toLowerCase().replace(/\s+/g,'_'),
						dataType:	'html',
						
						success:	function(html)
						{
							jQuery('#column-right').hide();
							jQuery('#column-right').html(html);
							jQuery('#column-right').fadeIn(200);
						}
					}
				);
							
				return false;
			}
		);
	}
}

function __disable_buttons()
{
	var form = document.forms['form'];
	
	if (form)
		jQuery('input:button',form).attr('disabled','disabled');
}

function __format_phone(string,target)
{	
	string = string.replace(/[^\d]/g,'');
	
	if (string.length > 0)
	{		
		phone = '';		
		if (string.length >= 3)
			phone += '(' + string.substr(0,3) + ')';
		
		if (string.length > 3 && string.length >= 6)
			phone += ' ' + string.substr(3,3);
		
		if (string.length > 6 && string.length >= 10)
			phone += '-' + string.substr(6,4);
		
		if (string.length > 10)
			phone += ' ext. ' + string.substr(10,(string.length)-1);
		
		target.value = phone;
	}				
}

 
function __get_quick_login()
{
	var position = jQuery('#sign-in').position();
	
	if (jQuery('#login-quick').is(':hidden'))
	{
		jQuery('#login-quick').css('left',(position.left - 165) + 'px');
		jQuery('#login-quick').show();
		jQuery('#sign-in').attr('class','rounded sign-in-active');
	}
	else
	{
		jQuery('#login-quick').hide();
		jQuery('#sign-in').attr('class','rounded sign-in');
	}
}

function __handle_plus_on_resize()
{
	if (jQuery('#plus').length > 0)
	{
		if (jQuery('#plus').is(':visible'))
			jQuery('#plus').hide();
	}
}

function __submit_contact_form()
{
	var form = document.forms['form'];
	
	if (form)
	{
		__disable_buttons();
		form['mode'].value = 'contact';
		form.submit();
	}
}

jQuery(document).ready(
	function()
	{
		__animate_gallery_image();
		__bind_tabs_click_handler();
		
		window.onresize = __handle_plus_on_resize;
	}
);
