/* Author:

*/

$(document).ready(function() {
						   
	/* $('.twitter').cycle({
		fx: 'scrollDown', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:  6000   // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	*/

	$('.left-main').masonry({
		  itemSelector: '.box',
		  columnWidth: 145,
		  gutterWidth: 18
	});
	
	$('#trans-small').cycle({ 
		next:   '.next2-small', 
		prev:   '.prev2-small',
		timeout: 0
	});
	
	$('#trans-medium').cycle({ 
		next:   '.next2-medium', 
		prev:   '.prev2-medium',
		timeout: 0
	});
	
	/* Menu accordian */
	
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.width-1-body').removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
		$('.accordionContent').slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).children('.width-1-body').addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	
	$('.accordionButton').css( 'cursor', 'pointer' );

 
	//HIDE THE DIVS ON PAGE LOAD	
	$(".accordionContent").hide();

	 function filterPath(string) {
	  return string
	    .replace(/^\//,'')
	    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	    .replace(/\/$/,'');
	  }
	  var locationPath = filterPath(location.pathname);
	  var scrollElem = scrollableElement('html', 'body');

	  $('a[href*=#]').each(function() {
	    var thisPath = filterPath(this.pathname) || locationPath;
	    if (  locationPath == thisPath
	    && (location.hostname == this.hostname || !this.hostname)
	    && this.hash.replace(/#/,'') ) {
	      var $target = $(this.hash), target = this.hash;
	      if (target) {
	        var targetOffset = $target.offset().top;
	        $(this).click(function(event) {
	          event.preventDefault();
	          $(scrollElem).animate({scrollTop: targetOffset}, 1000, function() {
	            location.hash = target;
	          });
	        });
	      }
	    }
	  });

	  // use the first element that is "scrollable"
	  function scrollableElement(els) {
	    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
	      var el = arguments[i],
	          $scrollElement = $(el);
	      if ($scrollElement.scrollTop()> 0) {
	        return el;
	      } else {
	        $scrollElement.scrollTop(1);
	        var isScrollable = $scrollElement.scrollTop()> 0;
	        $scrollElement.scrollTop(0);
	        if (isScrollable) {
	          return el;
	        }
	      }
	    }
	    return [];
	}

});









