//custom javascript
 $(document).ready(function() {
     
     //get url file
     var currentfile = jQuery.url.attr("file");
     var currentdir = jQuery.url.attr("directory").replace("/","").replace("/","");
     //$("body").append(currentfile);
     //highlight selected link
     $(".newslist li").removeClass('selectednav');
     $(".quick-links li").removeClass('selectedsidebar');
     if(currentdir!="/"){
         $(".newslist li a").each(function (i) {
            if ($(this).attr('href') == "../"+currentdir) {
                $(this).parents("li").addClass('selectednav');          
            }
            
          });
          $(".quick-links li a").each(function (i) {
            if ($(this).attr('href') == "../"+currentdir+"/"+currentfile) {
                $(this).parents("li").addClass('selectedsidebar');          
            }
            if (!currentfile) {
                $(".quick-links li:first").addClass('selectedsidebar');
            } 
          });
      }
      
      //newsletter form
      $(".emailsignup").bind("submit", function() {
            $(this).ajaxSubmit({
                target: ".emailmsg"
            });
            return false; // <-- important!
       });
      
      //submit button hover
      $("#submit").hover(
                         function(){$(this).css({'background-color':'#993333','color':'#fff'});},
                         function(){$(this).css({'background-color':'#fff','color':'#993333'});
                         });
   
      //prepopulate form fields
      $("#search_bottom, #search_top").val("SEARCH");
      $("#email_top, #email_bottom").val("YOUR EMAIL ADDRESS");
      $("#name_top, #name_bottom").val("YOUR NAME");
      
      $("#name_top, #email_top, #search_top, #name_bottom, #email_bottom, #search_bottom").focus(function(){$(this).val("");});
      
      //collapse additional dated
      //if($(".eventstable").children("tbody").children("tr").lenght > 1){
          //$(".eventstable tbody").append('<tr  class="showallevents" collspan="2"><td>    Show All    </td></tr>');
          //$(".eventstable tbody tr").not(".eventstable tbody tr:first-child, .eventstable tbody tr:last-child").addClass("collapse");
      //}
     // $(".eventstable tbody tr:first-child td *").show();
      $(".showallevents").unbind('click').click(function(){
                if($(".collapse").length > 0){
                    $(this).parents(".eventstable").children("tbody").children("tr").removeClass("collapse");
                    $(this).children("tr").children("th").text("Hide");
                }else{
                    $(".eventstable tbody tr").not(".eventstable tbody tr:first-child, .eventstable tbody tr:last-child").addClass("collapse");
                    $(this).children("tr").children("th").text("Show All");
                }
       });
      
      //hide navitem that doesn't have any content.
      if($(".latest-from-cat li").length < 1){
            $(".latest-from-cat").parents(".navitem").hide();  
      }
      //about hover
     /* $(".logo").stop().mouseover(function(){
          $("#about").slideDown();
      }); */
     
      
      //category nav
      $("#latestcategorynav a").unbind("click").click(function(){
         $("#latestposts").html('<span class="loader">LOADING...</span>');
         var href = $(this).attr("href");
         var splitcat = href.split("?");
         var cat =splitcat[1];// href.replace(/..\/index.php\?/, "");
         $("#latestposts").load('../ajax.php?action=loadlatestpost&'+cat);
         $("#latestcategorynav li").removeClass('selectednav');
         $(this).parents("li").addClass('selectednav');
         return false;
                                                         
      });
      
      //alphabetnav
      $("#alphabeth a").unbind("click").click(function(){
          var letter = $(this).text().toLowerCase();
          $("#alphabeth li").removeClass('selectednav');
          $(this).parents("li").addClass('selectednav');
          if(letter == "view all"){
            $("#members .member").show();
          }else{
          $("#members .member").each(function (i) {
            if ($(this).attr('title') == letter) {
                $(this).show();
            }else{
                $(this).hide();
            } 
          });
          }
          return false;
          
      });
     //promo slides
     if($('#promoslides').length > 0) {
         $('#promoslides').cycle({ 
            fx:     'fade', 
            delay:  -2000,
            timeout: 8000
        });
     }
     //gallery
	 if($('.gallery').length > 0) {
		 $('ul.gallery').galleria({
				history   : true, // activates the history object for bookmarking, back-button etc.
				clickNext : true, // helper for making the image clickable
				insert    : '#main_image', // the containing selector for our main image
				onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
					
					// fade in the image & caption
					if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
						image.css('display','none').fadeIn(1000);
					}
					caption.css('display','none').fadeIn(1000);
					
					// fetch the thumbnail container
					var _li = thumb.parents('li');
					
					// fade out inactive thumbnail
					_li.siblings().children('img.selected').fadeTo(500,0.3);
					
					// fade in active thumbnail
					thumb.fadeTo('fast',1).addClass('selected');
					
					// add a title for the clickable image
					image.attr('title','Next image >>');
				},
				onThumb : function(thumb) { // thumbnail effects goes here
					
					// fetch the thumbnail container
					var _li = thumb.parents('li');
					
					// if thumbnail is active, fade all the way.
					var _fadeTo = _li.is('.active') ? '1' : '0.3';
					
					// fade in the thumbnail when finnished loading
					thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
					
					// hover effects
					thumb.hover(
						function() { thumb.fadeTo('fast',1); },
						function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
					)
				}
			}); 
	 }
    if($(".sidecal").length > 0){
        $(".maincontentblock .sidecal").each(function(){
            var id = $(this).attr("id");
            var filename = id.split("_-");
            highlightdates(filename[1],filename[2]);
        });
    }
    
    if($(".cal_times").length > 0){
        $(".maincontentblock .cal_times").each(function(){
            var id = $(this).attr("id");
            var filename = id.split("_-");
            showcaltimes(filename[1]);
        });
    }
     //PAGINATION
    //how much items per page to show
    var show_per_page = 12;
    //getting the amount of elements inside content div
    var number_of_items = $('.page-content').children().size();
    //calculate the number of pages we are going to have
    var number_of_pages = Math.ceil(number_of_items/show_per_page);

    //set the value of our hidden input fields
    $('#current_page').val(0);
    $('#show_per_page').val(show_per_page);

    //now when we got all we need for the navigation let's make it '

    /*
    what are we going to have in the navigation?
        - link to previous page
        - links to specific pages
        - link to next page
    */
    var navigation_html = '<a class="previous_link" href="javascript:previous();" target="_top">Prev</a>';
    var current_link = 0;
    while(number_of_pages > current_link){
        navigation_html += '<a class="page_link" href="javascript:go_to_page(' + current_link +')" longdesc="' + current_link +'" target="_top">'+ (current_link + 1) +'</a>';
        current_link++;
    }
    navigation_html += '<a class="next_link" href="javascript:next();" target="_top">Next</a>';

    $('.page_navigation').html(navigation_html);

    //add active_page class to the first page link
    $('.page_navigation .page_link:first').addClass('active_page');

    //hide all the elements inside content div
    $('.page-content').children().css('display', 'none');

    //and show the first n (show_per_page) elements
    $('.page-content').children().slice(0, show_per_page).css('display', 'block');
    //end  //PAGINATION
 });
 
 //PAGINATION
function previous(){

    new_page = parseInt($('#current_page').val()) - 1;
    //if there is an item before the current active link run the function
    if($('.active_page').prev('.page_link').length==true){
        go_to_page(new_page);
    }

}

function next(){
    new_page = parseInt($('#current_page').val()) + 1;
    //if there is an item after the current active link run the function
    if($('.active_page').next('.page_link').length==true){
        go_to_page(new_page);
    }

}
function go_to_page(page_num){
    //get the number of items shown per page
    var show_per_page = parseInt($('#show_per_page').val());

    //get the element number where to start the slice from
    start_from = page_num * show_per_page;

    //get the element number where to end the slice
    end_on = start_from + show_per_page;

    //hide all children elements of content div, get specific items and show them
    $('.page-content').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');

    /*get the page link that has longdesc attribute of the current page and add active_page class to it
    and remove that class from previously active page link*/
    $('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');

    //update the current page input field
    $('#current_page').val(page_num);
    //scroll to top
    $('html, body').animate({scrollTop:0}, 1);
    var page = parseInt(page_num) + 1;
    //update heading
    if($(".post-title span").length < 1){
        //page number
        
        $(".post-title").append('<span> - Page: '+page+'</span>');
    }else{
        $(".post-title span").text(' - Page: '+page);   
    }
    
}
//END PAGINATION
 
  //highlight dates  
  function highlightdates(filename, article){   
    $.ajax({
          url: "../ajax.php",
          data: "action=getevents&filename="+filename+"&article="+article,
          dataType: "json",
          success: function(natDays){
                     var monthLocale = new Array(12);
                                        monthLocale[1] = "January";
                                        monthLocale[2] = "February";
                                        monthLocale[3] = "March";
                                        monthLocale[4] = "April";
                                        monthLocale[5] = "May";
                                        monthLocale[6] = "June";
                                        monthLocale[7] = "July";
                                        monthLocale[8] = "August";
                                        monthLocale[9] = "September";
                                        monthLocale[10] = "October";
                                        monthLocale[11] = "November";
                                        monthLocale[12] = "December";
                     var defaultdate = monthLocale[natDays[0][0]]+" "+ natDays[0][1] +","+ natDays[0][2];
                     $("#cal_-"+filename+"_-"+article).datepicker({
                        numberOfMonths: [1, 1],
                        showCurrentAtPos: 0,
                        beforeShowDay: function (date){
                            for (i = 0; i < natDays.length; i++) {
                                  if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]  && date.getFullYear() == natDays[i][2]) {
                                     
                                    return [true,"ui-state-active tooltip"];
                                  }
                                }
                                
                              
                              
                              return [false, ""];
                              
                        },
                        defaultDate: new Date (defaultdate),
                        onSelect: function(dateText, inst) { alert(dateText);}
                        
                    });
                   }
                   
         });
              
  }
  
  //highlight dates  
  function showcaltimes(article){   
    $.ajax({
          url: "../ajax.php",
          data: "action=geteventtimes&article="+article,
          success: function(caltimes){
                     $("#cal_-"+article).html(caltimes);
                   }
                   
         });
              
  }

/* Pushup
 * Copyright (c) 2009 Nick Stakenburg (www.nickstakenburg.com)
 *
 * License: MIT-style license.
 * Website: http://www.pushuptheweb.com
 *
 */

var Pushup = {
  Version: '1.0.3',
  options: {
    appearDelay: .5,
    fadeDelay: 6,
    images: '../images/',
    message: 'Important browser update available',
    reminder: {
      hours: 6,
      message: 'Remind me again in #{hours}'
    },
    skip: true
  },
  updateLinks: {
    IE: 'http://www.microsoft.com/windows/downloads/ie/',
    Firefox: 'http://www.getfirefox.com',
    Safari: 'http://www.apple.com/safari/download/',
    Opera: 'http://www.opera.com/download/'
  },
  Browser: {
    IE: !!(window.attachEvent &&
      navigator.userAgent.indexOf('Opera') === -1),
    Firefox: navigator.userAgent.indexOf('Firefox') > -1,
    Safari: navigator.userAgent.indexOf('AppleWebKit/') > -1 &&
      /Apple/.test(navigator.vendor),
    Opera: navigator.userAgent.indexOf('Opera') > -1
  }
};

Pushup.conditions = {
  IE: (function(agent) {
    var version = /MSIE ([\d.]+)/.exec(agent);
    return version && parseFloat(version[1]) < 7;
  })(navigator.userAgent),
  Firefox: Pushup.Browser.Firefox &&
    parseFloat(navigator.userAgent.match(/Firefox[\/\s](\d+)/)[1]) < 3,
  Safari: Pushup.Browser.Safari &&
    parseFloat(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1]) < 500,
  Opera: Pushup.Browser.Opera && (!window.opera.version ||
    parseFloat(window.opera.version()) < 9.5)
};

(function() {
// find current browser and check if it needs an update
for (var browser in Pushup.Browser)
  if (Pushup.Browser[browser]) Pushup._browserUsed = browser;
Pushup._updateBrowser = Pushup.conditions[Pushup._browserUsed] &&
  Pushup._browserUsed;

// stop if no update is required and we want to skip build
if (!Pushup._updateBrowser && Pushup.options.skip) return;

function Extend(destination, source) {
  for (var property in source)
    destination[property] = source[property];
  return destination;
}

Extend(Pushup, {
  start: function() {
    // get the image directory
    if (/^(https?:\/\/|\/)/.test(this.options.images))
      this.images = this.options.images;
    else {
      var srcMatch = /pushup(?:-[\w\d.]+)?\.js(.*)/,
       scripts = document.getElementsByTagName('script');
      for (var i = 0, l = scripts.length; i < l; i++) {
        var s = scripts[i];
        if (s.src && s.src.match(srcMatch))
          this.images = s.src.replace(srcMatch, '') + this.options.images;
      }
    }
    if (Pushup._updateBrowser) this.show();
  },

  build: function() {
    this.pushup = document.createElement('div');
    Opacity.set(this.pushup, 0);
    this.pushup.id = 'pushup';

    this.messageLink = this.pushup.appendChild(document.createElement('a'));
    this.messageLink.className = 'pushup_messageLink';
    this.messageLink.target = '_blank';

    this.messageLink.appendChild(this.icon = document.createElement('div'));
    this.icon.className = 'pushup_icon';

    this.messageLink.appendChild(this.message = document.createElement('span'));
    this.message.className = 'pushup_message';
    this.message.innerHTML = this.options.message;

    // reminder message if cookies are enabled
    var hours = this.options.reminder.hours;
    if (hours && Pushup.cookiesEnabled) {
      this.pushup.appendChild(this.reminder = document.createElement('a'));
      this.reminder.href = '#';
      this.reminder.className = 'pushup_reminder';
      this.pushup.className = 'withReminder';
      var H = hours + ' hour' + (hours > 1 ? 's' : ''),
       message = this.options.reminder.message.replace('#{hours}', H);
      this.reminder.innerHTML = message;
    }

    // Older Opera doesn't handle float correctly
    if (Pushup.Browser.Opera &&
       (!window.opera.version || parseFloat(window.opera.version()) < 9.25)) {
      this.messageLink.style.cssFloat = 'none';
      this.reminder.style.cssFloat = 'none';
    }

    Pushup.setBrowser(Pushup._updateBrowser);
    document.body.appendChild(this.pushup);
    Pushup.addEvents();
  },

  addEvents: function() {
    if (this.reminder) {
      Event.add(this.reminder, 'click', function(event) {
        Event.stop(event);
        Pushup.setReminder(Pushup.options.reminder.hours);
        Pushup.fade();
      });
    }
    Event.add(this.pushup, 'mouseover', Pushup.clearFade);
    Event.add(this.pushup, 'mouseout', function() {
      Pushup.fade({ delay: Pushup.options.fadeDelay })
    });
  },

  setBrowser: function(browser) {
    browser = browser || 'IE';
    setPngBackground(this.icon, this.images + browser.toLowerCase() + '.png');
    this.messageLink.href = this.updateLinks[browser];
  },

  show: function() {
    // default to IE if no browser was detected
    var browser = typeof arguments[0] == 'string' ?
      arguments[0] : Pushup._browserUsed || 'IE',
     options = arguments[browser ? 1 : 0] || {};

    if (options.resetReminder) Pushup.resetReminder();

    // show if not blocked by cookie
    if (!options.ignoreReminder && Pushup.cookiesEnabled &&
      Cookie.get('_pushupBlocked')) return;

    if (!Pushup.pushup) Pushup.build();
    Opacity.set(Pushup.pushup, 0);
    Pushup.pushup.style.display = 'block';
    if (browser) Pushup.setBrowser(browser);
    this.appear({ fadeAfter: true, delay: Pushup.options.appearDelay });
  },

  appear: function(delay) {
    Pushup.clearFade();
    var options = arguments[0] || {};
    return window.setTimeout(function() {
      Appear(Pushup.pushup, { afterFinish: function() {
        if (options.fadeAfter)
          Pushup.fade({ delay: Pushup.options.fadeDelay });
      }});
    }, (options.delay || 0.01) * 1000);
  },

  clearFade: function() {
    if (Pushup._fadeTimer) {
      window.clearTimeout(Pushup._fadeTimer);
      Pushup._fadeTimer = null;
    }
  },

  fade: function() {
    var options = arguments[0] || {};
    Pushup._fadeTimer = window.setTimeout(function() {
      Fade(Pushup.pushup);
    }, (options.delay || 0.01) * 1000);
  },

  setReminder: function(hours) {
    Cookie.set('_pushupBlocked', 'blocked', { duration: 1 / 24 * hours })
  },

  resetReminder: function() { Cookie.remove('_pushupBlocked') }
});

// Opacity adapted from the Prototype JavaScript framework
// http://www.prototypejs.org
var Opacity = {
  set: function(element, value) {
    element.style.opacity = (value == 1 || value === '') ? '' :
      (value < 0.00001) ? 0 : value;
  },

  get:  function(element) {
    var opacity = element.style.opacity;
    return opacity ? parseFloat(opacity) : 1.0;
  }
};

if (Pushup.Browser.IE) {
  Opacity.get = function(element) {
    var opacity = element.style.opacity;
    if (!opacity && element.currentStyle) opacity = element.currentStyle[opacity];

    if (opacity = (element.style.filter || '').match(/alpha\(opacity=(.*)\)/))
      if (opacity[1]) return parseFloat(opacity[1]) / 100;
    return 1.0;
  };

  Opacity.set = function(element, value) {
    function stripAlpha(filter) {
      return filter.replace(/alpha\([^\)]*\)/gi,'')
    }
    var currentStyle = element.currentStyle;
    if ((currentStyle && !currentStyle.hasLayout) ||
      (!currentStyle && element.style.zoom == 'normal'))
        element.style.zoom = 1;
    var filter = element.style.filter,
     style = element.style;
    if (value == 1 || value === '') (filter = stripAlpha(filter)) ?
      style.filter = filter : style.filter = '';
    else style.filter = stripAlpha(filter) +
      'alpha(opacity=' + (value * 100) + ')';
  };
}

function Appear(element) {
  var current = Opacity.get(element),
   options = arguments[1] || {};
  if (element.style.display != 'block')
    element.style.display = 'block';
  if (current < 1) {
    setTimeout(function() {
      Opacity.set(element, current += 0.05);
      Appear(element, options);
    }, 0.01);
  }
  else {
    if (Pushup.Browser.IE && element.style.filter)
      element.style.removeAttribute('filter');
    if (options.afterFinish) options.afterFinish.call();
  }
}

function Fade(element) {
  var current = Opacity.get(element),
   options = arguments[1] || {};
  if (current > 0) {
    setTimeout(function() {
      Opacity.set(element, current -= 0.05);
      Fade(element, options);
    }, 0.01);
  }
  else {
    element.style.display = 'none';
    if (options.afterFinish) options.afterFinish.call();
  }
}

function setPngBackground(element, url) {
  var options = Extend({
    align: 'top left',
    repeat: 'no-repeat',
    sizingMethod: 'crop',
    backgroundColor: ''
  }, arguments[2] || {});

  Extend(element.style, arguments.callee.IEBelow7 ? {
    filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' +
      url + '\'\', sizingMethod=\'' + options.sizingMethod + '\')'
  } : {
    background: options.backgroundColor + ' url(' + url + ') ' +
      options.align + ' ' + options.repeat
  });
}
setPngBackground.IEBelow7 = Pushup.Browser.IE &&
  parseFloat(/MSIE ([\d.]+)/.exec(navigator.userAgent)[1]) < 7;

// Based on the work of Peter-Paul Koch - http://www.quirksmode.org
var Cookie = {
  set: function(name, value) {
    var expires = '', options = arguments[2] || {};
    if (options.duration) {
      var date = new Date();
      date.setTime(date.getTime() + options.duration * 1000 * 60 * 60 * 24);
      value += '; expires=' + date.toGMTString();
    }
    document.cookie = name + "=" + value + expires + "; path=/";
  },

  remove: function(name) { this.set(name, '', -1) },

  get: function(name) {
    var cookies = document.cookie.split(';'), nameEQ = name + "=";
    for (var i = 0, l = cookies.length; i < l; i++) {
      var c = cookies[i];
      while (c.charAt(0) == ' ')
        c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0)
        return c.substring(nameEQ.length, c.length);
    }
    return null;
  }
};

// check if cookies are enabled
Pushup.cookiesEnabled = (function(test) {
  if (Cookie.get(test)) return true;
  Cookie.set(test, 'test', { duration: 15 });
  return Cookie.get(test);
})('_pushupCookiesEnabled');

var Event = {
  add: function(obj, type, fn) {
    if (obj.attachEvent) {
      obj['e' + type + fn] = fn;
      obj[type + fn] = function(){ obj['e' + type +fn](window.event) };
      obj.attachEvent('on' + type, obj[type + fn]);
    }
    else obj.addEventListener(type, fn, false);
  },

  stop: function(event) {
    if (Pushup.Browser.IE) {
      event.cancelBubble = true;
      event.returnValue = false;
    }
    else {
      event.preventDefault();
      event.stopPropagation();
    }
  }
};

Event.add(window, 'load', function() { Pushup.start() });
})();
/*END PUSHUP*/