/* accordion for quicklinks */
(function($){ 
     $.fn.extend({  
         accordion: function() {       
            return this.each(function() {
				if($(this).data('accordiated'))
					return false;									
				$.each($(this).find('ul, li>div'), function(){
					$(this).data('accordiated', true);
					$(this).hide();
				});
				$.each($(this).find('a:not(.foo)'), function(){
					$(this).click(function(e){
						activate(e.target);
						return void(0);
					});
				});
				
				var active = false;
				if(location.hash)
					active = $(this).find('a[href=' + location.hash + ']')[0];
				else if($(this).find('li.current'))
					active = $(this).find('li.current a')[0]; 
				
				if(active){
					activate(active, 'toggle','parents');
					$(active).parents().show();
				}
				
				function activate(el,effect,parents){
					$(el)[(parents || 'parent')]('li').toggleClass('active').siblings().removeClass('active').children('ul, div').slideUp('fast');
					$(el).siblings('ul, div')[(effect || 'slideToggle')]((!effect)?'fast':null);
				}
				
            });
        } 
    }); 
})(jQuery);

/*jflickrfeed */
/*
* Copyright (C) 2009 Joel Sutherland
* Licenced under the MIT license
* http://www.newmediacampaigns.com/page/jquery-flickr-plugin
*
* Available tags for templates:
* title, link, date_taken, description, published, author, author_id, tags, image*
*/
(function($){$.fn.jflickrfeed=function(settings,callback){settings=$.extend(true,{flickrbase:'http://api.flickr.com/services/feeds/',feedapi:'photos_public.gne',limit:20,qstrings:{lang:'en-us',format:'json',jsoncallback:'?'},cleanDescription:true,useTemplate:true,itemTemplate:'',itemCallback:function(){}},settings);var url=settings.flickrbase+settings.feedapi+'?';var first=true;for(var key in settings.qstrings){if(!first)
url+='&';url+=key+'='+settings.qstrings[key];first=false;}
return $(this).each(function(){var $container=$(this);var container=this;$.getJSON(url,function(data){$.each(data.items,function(i,item){if(i<settings.limit){if(settings.cleanDescription){var regex=/<p>(.*?)<\/p>/g;var input=item.description;if(regex.test(input)){item.description=input.match(regex)[2]
if(item.description!=undefined)
item.description=item.description.replace('<p>','').replace('</p>','');}}
item['image_s']=item.media.m.replace('_m','_s');item['image_t']=item.media.m.replace('_m','_t');item['image_m']=item.media.m.replace('_m','_m');item['image']=item.media.m.replace('_m','');item['image_b']=item.media.m.replace('_m','_b');delete item.media;if(settings.useTemplate){var template=settings.itemTemplate;for(var key in item){var rgx=new RegExp('{{'+key+'}}','g');template=template.replace(rgx,item[key]);}
$container.append(template)}
settings.itemCallback.call(container,item);}});if($.isFunction(callback)){callback.call(container,data);}});});}})(jQuery);

/*
 * jQuery jclock - Clock plugin - v 1.2.0
 * http://plugins.jquery.com/project/jclock
 *
 * Copyright (c) 2007-2008 Doug Sparling <http://www.dougsparling.com>
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
(function($) {

  $.fn.jclock = function(options) {
    var version = '1.2.0';

    // options
    var opts = $.extend({}, $.fn.jclock.defaults, options);
         
    return this.each(function() {
      $this = $(this);
      $this.timerID = null;
      $this.running = false;

      var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

      $this.timeNotation = o.timeNotation;
      $this.am_pm = o.am_pm;
      $this.utc = o.utc;
      $this.utc_offset = o.utc_offset;

      $this.css({
        fontFamily: o.fontFamily,
        fontSize: o.fontSize,
        backgroundColor: o.background,
        color: o.foreground
      });

      $.fn.jclock.startClock($this);

    });
  };
       
  $.fn.jclock.startClock = function(el) {
    $.fn.jclock.stopClock(el);
    $.fn.jclock.displayTime(el);
  }
  $.fn.jclock.stopClock = function(el) {
    if(el.running) {
      clearTimeout(el.timerID);
    }
    el.running = false;
  }
  $.fn.jclock.displayTime = function(el) {
    var time = $.fn.jclock.getTime(el);
    el.html(time);
    el.timerID = setTimeout(function(){$.fn.jclock.displayTime(el)},1000);
  }
  $.fn.jclock.getTime = function(el) {
    var now = new Date();
    var hours, minutes, seconds;
	var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec");
    if(el.utc == true) {
      var localTime = now.getTime();
      var localOffset = now.getTimezoneOffset() * 60000;
      var utc = localTime + localOffset;
      var utcTime = utc + (3600000 * el.utc_offset);
      now = new Date(utcTime);
    }
    hours = now.getHours();
    minutes = now.getMinutes();
    seconds = now.getSeconds();
    day = now.getDate();
    month = now.getMonth();
    year = now.getFullYear();

    var am_pm_text = '';
    (hours >= 12) ? am_pm_text = " pm" : am_pm_text = " am";

    if (el.timeNotation == '12h') {
      hours = ((hours > 12) ? hours - 12 : hours);
    } else if (el.timeNotation == '12hh') {
      hours = ((hours > 12) ? hours - 12 : hours);
      hours   = ((hours <  10) ? "0" : "") + hours;
    } else {
      hours   = ((hours <  10) ? "0" : "") + hours;
    }

    minutes = ((minutes <  10) ? "0" : "") + minutes;
    seconds = ((seconds <  10) ? "0" : "") + seconds;

    var timeNow = hours + ":" + minutes + "<small>:" + seconds +"</small>";
    //var timeNow = hours + ":" + minutes;
    if ( (el.timeNotation == '12h' || el.timeNotation == '12hh') && (el.am_pm == true) ) {
     timeNow += am_pm_text;
    }
	timeNow +=  " <strong>"+day+" "+m_names[month]+" "+year+"</strong>";
    return timeNow;
  };
       
  // plugin defaults
  $.fn.jclock.defaults = {
    timeNotation: '12h',
    am_pm: true,
    utc: false,
    fontFamily: '',
    fontSize: '',
    foreground: '',
    background: '',
    utc_offset: 0
  };

})(jQuery);

function doAjax(url,container){
				$.ajax({
			        url: url,
			        timeout:5000,
			        success: function(data){
			          container.html(data);
			        },
			        error: function(req,error){
			          if(error === 'error'){error = req.statusText;}
			          var errormsg = 'There was a communication error: '+error;
			          container.html(errormsg);
			        },
			        beforeSend: function(data){
			          container.html('<p class="loader">Loading...</p>');
			        }
			 	});
			}	
			
$(document).ready(function () {
			Cufon.replace('h2,#footer p,.gc, .pagenav h3, .follow h3, #leftcol h3, .news h3, .donate h3');
			Cufon.replace('div.tabs span',{hover: true})
			if ($('#flickr_div').length>0) {
				$('#flickr_div').flickrGallery('72157625432639549','3266a48f6561ce70d0076d7a5f63bf8d');
			}
			$('#flickr_gallery').jflickrfeed({
			    limit: 14,
			    qstrings: {
			        id: '56817065@N04',
					tags: 'Archive'
			    },
			    itemTemplate: 
			    '<li>' +
			        '<a rel="colorbox" href="{{image_b}}"><img src="{{image_s}}" alt="{{title}}" width="60" height="60" /></a>' +
			    '</li>'
			}, function(data) {
				$('#flickr_gallery a').colorbox();
			});
			$('ul.accordion').accordion();
			$('.clock').jclock();
			$('.roundbox,.news,ul#sub_navigation').corner('10px');
			$('.pagenav h3').corner('tl tr 10px')
			$('#testimonials p').addClass("dontsplit");
			$('.columnize-list').columnize({columns:2,buildOnce:true});
			$('.bloglink').live("click", function(event){
				doAjax($(this).attr('href'),$('#blog_container'));
				return false;
			  });
			$('.newslink').live("click", function(event){
				doAjax($(this).attr('href'),$('#news'));
				return false;
			  });
			$(".tab_content").hide(); //Hide all content
				$(".tabs span:first").addClass("active").show(); //Activate first tab
				$(".tab_content:first").show(); //Show first tab content
				
				//On Click Event
				$(".tabs span").click(function() {
					$(".tabs span").removeClass("activetab"); //Remove any "active" class
					$(this).addClass("activetab"); //Add "active" class to selected tab
					$(".tab_content").hide(); //Hide all tab content
					var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
					$(activeTab).fadeIn(); //Fade in the active content
					return false;
				});
			if(window.opera) {
		        if ($("a.bookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
		            $("a.bookmark").attr("rel","sidebar");
		        }
		    }
		    $("a.bookmark").click(function(event){
		        event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		        var url = this.href;
		        var title = this.title;
		        if (window.sidebar) { // Mozilla Firefox Bookmark
		            window.sidebar.addPanel(title, url,"");
		        } else if( window.external ) { // IE Favorite
		            window.external.AddFavorite( url, title);
		        } else if(window.opera) { // Opera 7+
		            return false; // do nothing - the rel="sidebar" should do the trick
		        } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
		             alert('Unfortunately, this browser does not support the requested action,'
		             + ' please bookmark this page manually.');
		        }
		    });

		});
