//##############################################################################
//##  DOM																	  ##
//##############################################################################
$(document).ready( externalLinks );
/*###########################################
##  Dropdown Menus						   ##
###########################################*/
/* Options */
var __global_menuContainer = '.navMenu';
/* Controls */
$(document).ready(function() {
	var lis = $(__global_menuContainer).children('li').get();
    $.each(lis, function(){
      $(this).hover(
	    function () { //on
	      $(this).addClass("sfhover")
	    }, 
	    function () { //off
	      $(this).removeClass("sfhover")
	    }
	  );
    });
});

/*###########################################
##  Legacy Transparency					   ##
###########################################*/
$(document).ready(function() {
  /* Body */
  $("img").each(function(){ //fix legacy transparency
    var fileExtension = $(this).attr("src").substr($(this).attr("src").lastIndexOf(".png"));
    if (fileExtension == ".png") { $(this).addClass("transparent"); }
  });
});

/*###########################################
##  Cufón Init							   ##
###########################################*/
Cufon.replace('.heading, .firstColumn h2, .secondColumn h2, #chooseYourCounty h2, #newAndNoteworthy h2, #calendarOfEvents h3, #latestIssue h3, #latestIssue h4, #upcomingEvents h2, #upcomingEvents h4, .advertisement h4', { fontFamily: 'Frutiger LT Std', hover: true });
Cufon.replace('#bodyContent #body h1, #bodyContent #body h2, #bodyContent #body h3, #bodyContent #body h4, #bodyBottomHeaders h2', { fontFamily: 'Frutiger LT Std', hover: true });
Cufon.replace('#navigation h2, #search h2, #login h2', { hover: true, 
													     fontFamily: 'Frutiger LT Std',
													     textShadow: '2px 2px rgba(0, 0, 0, 0.3)'
												       });
Cufon.replace('#body .left #welcome, #body .left p b, #pageTitle', { fontFamily: 'Constantia', hover: true });

//##############################################################################
//##############################################################################
//##  User Handler Functions												  ##
//##############################################################################
function externalLinks() {
  var exs = $('a[rel=external]');
  $.each(exs, function() {
    if ($(this).attr('href')) { $(this).attr('target','_blank'); }
  });
}
//##############################################################################
//##############################################################################


$(document).ready(function() {
	if($('#choosecounty').length > 0) {
		$('#choosecounty').change(function() {
			if ($(this).val() != 'notset') {
				window.location = '/counties/detail/' + $(this).val();
			}	
		});
	}
	
	if($('#tweets').length > 0) {
		$('#tweets').twitterize('arcounties',{count:3});
	}
	
	
	if($('#gallery_loading').length > 0)
	jQuery(function($) {
		$('#gallery_loading').hide();
		$('#gallery_container').slideDown('slow');
		$('.colorbox').click(function(e) {
			var $this = $(this);
			var sel = $this.attr('href')+'>a:not(.loaded)';
			$(sel).each(function() { $('<img src="'+$(this).attr('thumb')+'" width="75" height="75" />').appendTo(this); })
				.addClass('loaded')
				.colorbox({slideshow: true,slideshowSpeed:6000, onLoad: function() { $(this).parent().hide(); }});
			$this.colorbox({
				inline: true, initialWidth: 300, initialHeight: 300, href: $(this).attr('href'), title: $this.attr('title'),
				maxHeight:'50%', open: true,
				onLoad: function() { $($(this).attr('href')).show(); },
				onCleanup: function() {
					$($(this).attr('href')).hide();
				}
		});
		return false;
		});
	});
	
	calendar_links();
	
});

function calendar_links() {
	$('.prev h4 a').click(function() {
		var link = $(this).attr('href');
		
		// alert(link);
		$.ajax({
			url: link,
			success: function(data) {
				$('#calendarOfEvents').html(data);
				calendar_links();
			}
		});
		
		return false;
	});
	
	$('.next h4 a').click(function() {
		var link = $(this).attr('href');
		
		// alert(link);
		$.ajax({
			url: link,
			success: function(data) {
				$('#calendarOfEvents').html(data);
				calendar_links();
			}
		});
		
		return false;
	});
}

