$(document).ready(function(){

var exit_txt = '[template] Exiting script: no item found :)!',
theDiv = '#feature_img',	
theElement = $(theDiv);
 
if($('#feature_box').length){

	function before(){

		var theOne = $(this).index();
	
	
		if($('#feature_box div:visible').length==0){

			$('#feature_box div:first').fadeIn();

		}else{
			$('#feature_box div:visible').fadeOut('fast',function(){
		
				$('#feature_box div').eq(theOne).fadeIn();	
			
			});
		}		
	}	

	theElement.cycle({ 
	    fx:     'fade', 
	    speed:   500, 
	    timeout: 5000, 
	    next:   theDiv, 
	    pause:   0,
	    before: before,
	    pager: '#feature_pager',
	    pagerAnchorBuilder:	function(index, slide){
		return '<a href="'+ slide.src + '">&middot;</a>"';
	} 
	});


	$('#feature_wrap').hover(function(){
	theElement.cycle('pause');
		$('.pauze').stop().fadeTo('slow',1);

	},function(){
	theElement.cycle('resume');
		$('.pauze').stop().fadeTo('slow',0);

	});

}else{ 
	console.log(exit_txt);
}

$(".content").append('<div class="load"></div>');


$(window).load(function(){

$(".content").find(".load").remove();
       

        function fadeLI(elem){
            elem.fadeIn(180, function(){
                fadeLI($(this).next());
            });
        }

        $('ul.content').each(function(){
            fadeLI($(this).find("li:first"));
        });
    });

    $('.boxgrid.captionfull').hover(function(){
        $(".cover", this).stop().animate({ 
            top:'108px'
        },{
            queue:false,
            duration:500,
            easing:'easeOutElastic'
        });
    }, function() {
        $(".cover", this).stop().animate({
            top:'168px'
        },{
            queue:false,
            duration:250,
            easing:'easeInQuad'
        });
    });

	if($('h3 a:[name]').length){
		$('<ul class="anchormenu"></ul>').prependTo('#contentWrap');	
		$('#wrapper').prepend('<div id="up" style="display:none;"><a href="#top">&uarr;top</a></div>');
		var 	str = "",
			options = {hash:true, reset:false,easing:'easeInOutQuad', duration:1500};
		$('h3 a:[name]').each(function(){
			var text = $(this).parent().text().replace(/[^a-zA-Z 0-9]+/g,'');
			
				str += '<li><a href="#'+$(this).attr('name')+'">&darr;&nbsp;'+text+'</a></li>';
		});		
			
		str += "</ul>";
		$(str).appendTo('#contentWrap ul:first');
		str = "";
		
		$('body').prepend( '<a name="top"></a>');		
		
		
		
		$(window).scroll(function(){
			if ($(window).scrollTop()>200 && $('#up').is(':hidden'))$('#up').fadeIn('slow');
			if ($(window).scrollTop()<200 && $('#up').is(':visible'))$('#up').fadeOut('slow');

		});
		$.localScroll.hash(options);

		

		$.localScroll(options);
	}else{
		console.log(exit_txt); 
	}

});

