/*function mycarousel_initCallback(carousel) {
	
    $('.project-carousel .paging a').bind('click', function() {
        carousel.scroll($.jcarousel.intval(jQuery(this).text()));
        return false;
    });
}*/
		

$(document).ready(function(){ 

    // font replacement
		Cufon.replace('#content h1', {});
		Cufon.replace('#content h2', {});

		// menu
		$('#nav-1 ul').menu({
			//startItem: startItem,
			fx: 'swing',
			speed: 333
		});

    //
		$('#footer-nav').addRandomClass({
		  defaultClassName: 'square',
			classNames: ['bubble','organic','scribble','spike','zigzag']
		});
		
		// carousel homepage
		if ($('.home-carousel ul li').size()>0) {
			$('.home-carousel ul').before('<a class="prev"></a><a class="next"></a>').cycle({
				fx: 'scrollLeft',
				//speedIn:  600, 
				//speedOut: 300, 
				//easeIn:  'easeOut', 
				//easeOut: 'easeIn', 
				speed:  900, 
				timeout: 9000, 
				next:   '.next', 
				prev:   '.prev',
				random: 0,
				pause: 1,
				delay: 0
			});
		};
		
		// carousel news footer
		if ($('#footer-news ul li').size()>0) {
			$('#footer-news ul').cycle({
				fx: 'scrollLeft', 
				timeout: 4000,
				random: 1,
				pause: 1,
				delay: 0
			});		 
		};
		
		// carousel project page
		if ($('.project-carousel ul li').size()>0) {
			$('.project-carousel ul').after('<div id="paging" class="paging"></div>').cycle({
        fx: 'scrollLeft', 
				speed: 333,
				timeout: 0, 
				pager:   '#paging', 
				//activePagerClass: 'active',
				pause: 1,
				delay: 0
				
			});
		};
		
		//
		$('.project-overview a').thumbRollover({ 
				labelClass: 'label'		 
		});
	

		// accordion
		$('.accordion').accordion({ 
				active: true, 
				header: '.accordion-head', 
				alwaysOpen: false,
				autoheight: false,
				navigation: true,
				navigationFilter: function(){  return this.href.substring(this.href.indexOf('#'),this.href.length).toLowerCase() == location.hash.toLowerCase(); }
		});


});

 	$('.project-overview a').each( function() {
		 		
    });
	
// THUMB ROLLOVER
			
(function($){
	jQuery.fn.thumbRollover = function(options) {
		
		return this.each(function() {
			
			var $thumb = $(this);
			var $border = $('<div class="border">').prependTo($thumb).hide();
			var $label = $('.'+options.labelClass,$thumb);
      $label.H = $label.height()+20;
			$label.css('bottom','-'+$label.H+'px');
		 
			//var $label = 
    	//$('.rollover',this).hide();
			$thumb.mouseenter( function() { showLabel(); }).mouseleave( function() { hideLabel(); });
		
			function showLabel() {
				$border.show();
 				$label.animate({
					bottom: 0
				}, 200, function() {
					// Animation complete.
				});
			};
			
			function hideLabel() {
				$border.hide();
				$label.animate({
					bottom: '-'+$label.H+'px'
				}, 100, function() {
					// Animation complete.
				});
			};
		
		});
		
	};
})(jQuery);	


// MENU
			
(function($){
	jQuery.fn.menu = function(options) {
		
		menuSettings = jQuery.extend({
			 direction: 'horizontal',													 
			 fx:   			'swing',  
			 speed: 		333
			 //slidesContainer: '.slideshow',
			 //timeout: 10000
		}, options);
	
		return this.each(function() {
															
      var $menu  = $(this);
			var $items = $('a',$(this));
			var $back;
			var activeItem = 0;
			var hoverItem = null;
			var timeOut;
			
			// 
			$items.each( function(i) {
				 if($(this).hasClass('active')) activeItem = i;
				 $(this).mouseover( function(e) { 
					 clearTimeout(timeOut);
				   move(i);													 
				 });
				 $(this).mouseout( function(e) { 
				   timeOut = setTimeout(autoReturn,menuSettings.speed);													 
				 });				 
		  });
			activeEl = $items[activeItem];
			$(activeEl).addClass('hover');
			$back = $('<li class="background">&nbsp;</li>').appendTo($menu).css({'width':activeEl.offsetWidth+'px','left':activeEl.offsetLeft+'px','top':activeEl.offsetTop+'px'});
			
			function move(i) {
				var el = $items[i];
		    $items.removeClass('hover');
				//$(el).addClass('hover');
				$back.stop().animate({'width':el.offsetWidth+'px','left':el.offsetLeft+'px','top':el.offsetTop+'px'}, menuSettings.speed, menuSettings.fx, function() { $(el).addClass('hover');});
				hoverItem = i;
			};
			
			function autoReturn() {
				if (hoverItem!=activeItem) {
					var el = $items[activeItem];
					$items.removeClass('hover');
					$back.stop().animate({'width':el.offsetWidth+'px','left':el.offsetLeft+'px','top':el.offsetTop+'px'}, menuSettings.speed, menuSettings.fx, function() { $(el).addClass('hover');});
				}
			};
		
		});
		
	};
})(jQuery);		

	
// PLUGINS

(function($){
	$.fn.addRandomClass = function(options) {
		
		return this.each(function() {
		 								
    		var $container = $(this);
				var to;
				var currentClass;
			  var randomClass;
				
			  $.fn.setClass = function() {
						$container.addClass(randomClass);
						currentClass = randomClass;
						setTimeout('$.fn.changeClass()',5000);
				};
				
				$.fn.changeClass = function() {
					 
						randomClass =  getRandomClass();
						if (currentClass) { $container.removeClass(currentClass); }
						$container.addClass(options.defaultClassName);
						setTimeout('$.fn.setClass()',200);
						 
				};	
				
				function getRandomClass() {
						var className;
						//console.log(className);
						while ( className==undefined || className==currentClass ) className = options.classNames[Math.floor(Math.random()*options.classNames.length)];
						
						return className;
				};
				
 				$.fn.changeClass();
				//
		});
		//'$.fn.glowUpAtRandom()'
				
		
	};
})(jQuery);	

