$(document).ready(
	function ()
	{
		FireTabButtonEvents();
		FireBxSlider('#CommuniqueContainer');
		ReFire();
	}
);

function ReFire()
{
	$('a[class*="FancyForce"]').FancyForceLink();
	$('button[class*="Fancy"]').FancyForce();
}

function FireTabButtonEvents()
{
	links_selector = '#TabGroups ul li a';
	
	$(links_selector).PreventSelect();
	
	$(links_selector).click(
		function()
		{
			$('#TabGroups').find('a').each(
				function()
				{
					$(this).removeClass('Active');
				}
			);
			
			switch ($(this).attr('id'))
			{
				case 'News':
					local_uri = 'news.php';
					content_selector = '#CommuniqueContainer';
				break;
				
				case 'Announcements':
					local_uri = 'announcements.php';
					content_selector = '#CommuniqueContainer';
				break;
		
				case 'Doctors':
					local_uri = 'doctors.php';
					content_selector = '#DoctorsContainer';
				break;
				
				case 'Services':
					local_uri = 'services.php';
					content_selector = '#ServicesContainer';
				break;
							
				case 'Lab':
					local_uri = 'lab.php';
					content_selector = '#LabContainer';
				break;
				
				case 'Appointment':
					local_uri = 'appointment.php';
					content_selector = '#AppointmentContainer';
				break;
				
				case 'Personnel':
					local_uri = 'personnel.php';
					content_selector = '#PersonnelContainer';
				break;
				
				case 'PersonnelLogged':
					local_uri = 'pms.php';
					content_selector = '#PersonnelContainer';
				break;
				
				case 'Rights':
					local_uri = 'rights.php';
					content_selector = '#RightsContainer';
				break;
				
				case 'About':
					local_uri = 'about.php';
					content_selector = '#AboutContainer';
				break;
				
				case 'Contact':
					local_uri = 'contact.php';
					content_selector = '#ContactContainer';
				break;
				
				default:
					return (false);
				break;
			}

			$(this).addClass('Active');
			
			$('#Pane')
				.fadeOut('fast')
				.load('ajax/' + local_uri,
					function()
					{
						try 
						{
							FireBxSlider(content_selector);
							ReFire();
						}
						catch (TryExp){}
						
						//$('#Pane').fadeIn('fast');
					}
				)
				.fadeIn('fast');
			;
		}
	);
}

function FireBxSlider(selector)
{
	$(selector).bxSlider(
	{
		auto: true,
		autoHover: true,
		controls: false,
   		autoControls: false,
		infiniteLoop: false,
		prevText: 'Önceki',
		nextText: 'Sonraki',
		pager: true,
		pagerActiveClass: 'Active',
		speed: 1000,
		pause: 5000
	});
}

function SwitchLabs()
{
	$('a[id=Lab]').trigger('click');	
}

function SwitchContact()
{
	$('a[id=Contact]').trigger('click');
}

function SwitchAppointment()
{
	$('a[id=Appointment]').trigger('click');
}

Array.prototype.IfContains = function(SearchValue) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == SearchValue) {
			return true;
		}
	}
	return false;
}

jQuery.fn.PreventNonNumericKeyPress = function(){
    return this.each(function(){
        $(this).keydown(function(eventReference){
            var pressedKey = eventReference.charCode || eventReference.keyCode || 0; //backspace, tab, delete, arrows, numbers, keypad numbers
            return (pressedKey == 8 || pressedKey == 9 || pressedKey == 46 || (pressedKey >= 37 && pressedKey <= 40) || (pressedKey >= 48 && pressedKey <= 57) || (pressedKey >= 96 && pressedKey <= 105));
        });
    })
};

jQuery.fn.PreventSelect = function(){
    return this.each(function(){
        $(this).css({'MozUserSelect': 'none'}).bind('selectstart', function(){ return false; }).mousedown(function(){ return false; });
    })
};

jQuery.fn.FancyForce = function(){
    return this.each(function(){
		source = $(this).attr('value');
		
		$(this).fancybox({'type': 'image', 'href': source, 'transitionIn': 'none', 'transitionOut': 'none', 'titlePosition': 'over', 'titleFormat': function(title, currentArray, currentIndex, currentOpts){ return '<span id="fancybox-title-over">Fotoğraf ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>'; }});
    })
};

jQuery.fn.FancyForceLink = function(){
    return this.each(function(){
		source = $(this).attr('href');

		$(this).fancybox({'type': 'ajax', 'href': source, 'transitionIn': 'none', 'transitionOut': 'none', 'titlePosition': 'over'});
    })
};
