/* 

Author: 			Stefan Vervoort
Author URI: 		http://www.divitomedia.com/

Description:		This little JavaScript library adds the standard features I need in projects.

*/


/* Suckerfish - 						http://htmldog.com/articles/suckerfish/dropdowns/ */

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


/* Add Search functionality */

function FunctionSearch(Element) {
	if (Element.value == 'Search Query') {
		Element.value = '';
		} else if (Element.value == '') {
		Element.value = 'Search Query';
		}
		return true;
	}
	
/* For changing image banner */

$(function() {
    $('#section_img_header').cycle({ 
    fx:    'fade', 
    speed:  4000,
    timeout:  3000,
	random: true
 });
});

/* Accordion */

$(document).ready(function(){
			
	/*	$(".accordion h2:first").addClass("active"); */ /* Activates first one on load*/
	/* 	$(".accordion .accordion_content:not(:first)").hide(); */ /* Opens first tab on load */
	$(".accordion .accordion_content").hide();	/* Hide all tabs when page loads*/

	$(".accordion h2").click(function(){
		$(this).next(".accordion_content").slideToggle("slow")
		.siblings(".accordion_content:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h2").removeClass("active");
	});

});

/* Smooth scroll */

      $(document).ready(function(){
        $('a[href*=#]').click(function() {
          if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
          && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target
            || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
              var targetOffset = $target.offset().top;
              $('html,body')
              .animate({scrollTop: targetOffset}, 1000);
             return false;
            }
          }
        });
      });
	  
/* Set main nav active tag */

function setActive() {
  aObj = document.getElementById('nav').getElementsByTagName('a');
  for(i=0;i<aObj.length;i++) { 
    if(document.location.href.indexOf(aObj[i].href)>=0) {
      aObj[i].className +=' active';
    }
  }
}
