	$(document).ready(function() { 
		$('#navigation ul li').hover(function() {
			$(this).find('a').stop(true).animate({opacity:'0.5'},300);
			$(this).stop(true).animate({ backgroundColor: '#ffffff' }, 300);
		}, function() {
			$(this).find('a').stop(true).animate({opacity:'1'},300);
			$(this).stop(true).animate({ backgroundColor: '#f8f8f8' }, 300);
		});	
		
		$('#subnav ul li').hover(function() {
			$(this).find('a').stop(true).animate({opacity:'0.5'},300);
			$(this).stop(true).animate({ backgroundColor: '#ffffff' }, 300);
		}, function() {
			$(this).find('a').stop(true).animate({opacity:'1'},300);
			$(this).stop(true).animate({ backgroundColor: '#f8f8f8' }, 300);
		});		

		$('.gallery-thumb').hover(function() {
			$(this).children('.gallery-thumb-vote').fadeIn('slow');
		}, function() {
			$(this).children('.gallery-thumb-vote').fadeOut('slow');
		});			

		$('.talk-member').hover(function() {
			$(this).children('div.talk-member-info').fadeIn("fast");
		}, function() {
			$(this).children('div.talk-member-info').fadeOut("slow");
		});			

		$("#jobfilters input").click(function() {
			$("#jobfilters").submit();
		});		
		
		$("#directoryfilters input").click(function() {
			$("#directoryfilters").submit();
		});
		
		$("#forum-category-select select").change(function() {
			$("#forum-category-select").submit();
		});		

		$('#post-select').change(function() {
			$('#post-select').submit();
		});		
		
		$('#event-select').change(function() {
			$('#event-select').submit();
		});	
				
		
		$('.image-wrap').cycle({ 
			prev: '.image-controls-beta .prev',
			next: '.image-controls-beta .next',
			timeout: 0,
			before: onBefore
		});		
		
		function onBefore() { 
			$('.image-controls-alpha span').html(this.alt); 
		}; 	
		
		$('a[rel="external"],a.auto-embedded,a.external').click(function(){
		  this.target = "_blank";
		});
		
		$("a.fancy,a.vr-entry").fancybox({'titlePosition' : 'inside'});
		
		$(".delete").click( function() {
			var redirect_loc = $(this).attr('href');
			jConfirm('Can you confirm delete?', 'Confirmation Dialog', function(r) {
				if ( r == true ) {
					window.location = redirect_loc;
				}
			});
		});
		
		$(".apply").click( function() {
			$.getJSON("ajax/job_apply/"+$(this).attr('rel'));
		});	
		
		$("select#country").change(function(){
			$.getJSON("ajax/zones/"+$(this).val(),'', function(j){
				var options = '';
					for (var i = 0; i < j.length; i++) {
						options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
					}
				$("select#state").html(options);
			})
		})
		
		$("select#job-country").change(function(){
			$.getJSON("ajax/zones/"+$(this).val()+"/clean",'', function(j){
				var options = '';
					for (var i = 0; i < j.length; i++) {
						options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
					}
				$("select#job-state").html(options);
			})
		})		
		
		$("#categories").dropdownchecklist({ width: 260 });
		
	});

	Cufon.replace('#navigation ul li,#subnav ul li, h2', {
		hover: true,
		hoverables: { a: true }
	});
	
	function initialize(){
	
		$("img.auto-embedded").each(function() {
			if ($(this).width() > 780) {
				$(this).wrap('<a href="'+$(this).attr("src")+'">').fancybox({
				'onComplete':function(){
					$("#fancybox-inner").children("img.auto-embedded").removeAttr("style");
					$("#fancybox-inner").width($("#fancybox-inner").children("img.auto-embedded").width()+20);					
					$("#fancybox-inner").height($("#fancybox-inner").children("img.auto-embedded").height()+20);					
					$('#fancybox-wrap').width($("#fancybox-inner").children("img.auto-embedded").width()+20);
					$('#fancybox-wrap').height($("#fancybox-inner").children("img.auto-embedded").height()+20);
					$.fancybox.resize();
					$.fancybox.center();
                    },
				'onClosed':function(){
					initialize()
					}
				});
				$(this).width(780);
			}
		});
	}
	
