(function($) {
$(document).ready(function() {
	
	$('.fullprofile, .featured-degree').click(function(event) {
			
			event.preventDefault();
			
			//$.colorbox({ width: '500px', inline:true, href: '#profile', opacity: 0 });
			$('#listing-'+this.id).animate({'height': 'toggle'}, 'slow');
			
		});
	$('.vidpic').bind('click', function() {
					$('.vidpic').colorbox();
				});	
	$('#country').change(function() {
		
		$('#loader').css('display', 'inline');
		var p = {};
		p['country']=$('#country').val();
		$('#state').load("http://www.wilsonssyndrome.com/wp-content/themes/WTSMed/response.php", p, function() {
			$('#loader').css('display', 'none'); 
			});
		
	});
	$('#state').change(function() {
		
		var p = {};
		p['country']=$('#country').val();
		p['state']=$('#state').val();
		$('#loader').css('display', 'inline');
		$('#doctorslist').css('display', 'none');
		
		$('#doctorslist').load("http://www.wilsonssyndrome.com/wp-content/themes/WTSMed/response.php", p, function() {
			$('#loader').css('display', 'none');
			$('#doctorslist').fadeIn();
			$('.view').bind('click', function(event) {
				event.preventDefault();
				$.colorbox({ width: '500px', inline:true, href: '#info-' + $(this).attr('id'), opacity: 0 });	
				});
			var urlhash = $('#country').val() + "!" + $('#state').val(); 
			$.history.load(urlhash);
		});
	});
	$.history.init(function(hash) {
		
		if (hash != "") {
			var parts = {};
			var p = {};
			parts = hash.split("!");
			p['country'] = parts[0];
			p['state'] = parts[1];
			$('#loader').css('display', 'inline');
			$("#country [value='" + parts[0] + "']").attr("selected", "selected");
			
			$('#doctorslist').load("http://www.wilsonssyndrome.com/wp-content/themes/WTSMed/response.php", p, function() {
				$('.view').bind('click', function(event) {
					event.preventDefault();
					$.colorbox({ width: '500px', inline:true, href: '#info-' + $(this).attr('id'), opacity: 0 });
				});
				
				$('#loader').css('display', 'none');
				$('#doctorslist').fadeIn();
				var country = {};
				country['country'] = $('#country').val(); 
				$('#state').load("http://www.wilsonssyndrome.com/wp-content/themes/WTSMed/response.php", country, function() {
					$('#loader').css('display', 'none'); 
					$("#state [value='" + parts[1] + "']").attr("selected", "selected");
				});
			});
		}		
	});
});
}) (jQuery);
