var cntr = 0;

$(document).ready(function(){
	
	navbarCurrent();
						   
	arrowAdd();
	timer = setInterval("findNext(cntr)", 4500);
	$('.arrow').click(function(){
		var pick = $(this).attr("rel");
		hideShow(pick);
		clearInterval(timer);
		timer = setInterval("findNext(cntr)", 4500);
	});
});

function navbarCurrent(){
	if ( $('body').hasClass('page-id-2') || $('body').hasClass('parent-pageid-2') ) {
		$('.main_nav ul li:eq(0)').addClass('here');
	} else if ( $('body').hasClass('page-id-14') || $('body').hasClass('parent-pageid-14') ) {
		$('.main_nav ul li:eq(1)').addClass('here');
	} else if ( $('body').hasClass('blog') || $('body').hasClass('single-post') || $('body').hasClass('archive') ) {
		$('.main_nav ul li:eq(2)').addClass('here');
	} else if ( $('body').hasClass('page-id-22') || $('body').hasClass('parent-pageid-22') ) {
		$('.main_nav ul li:eq(3)').addClass('here');
	} else if ( $('body').hasClass('page-id-31') || $('body').hasClass('parent-pageid-31') ) {
		$('.main_nav ul li:eq(4)').addClass('here');
	}
}

function arrowAdd(){
	$('.homefade').each(function(){
		$(this).attr('rel', cntr);
		$('.dots').append('<div class="arrow" rel="'+ cntr +'"><a></a></div>');
		cntr = cntr+1;
	});
	cntr = cntr-1;
	$('.dots div:first-child, .homefade:first-child').addClass('select');
}

function findNext(cntr){
	var pick = $('.homefade.select').attr("rel");
	if ( pick < cntr ){
		pick = parseFloat(pick) + 1;
	} else {
		pick = 0;
	}
	hideShow(pick);
}

function hideShow(pick){
	$('.homefade.select h1, .homefade.select p, .homefade.select .home_img img').animate({opacity:0}, 750);
	$('.homefade:eq('+ pick +') h1, .homefade:eq('+ pick +') p, .homefade:eq('+ pick +') .home_img img').animate({opacity:1}, 750);
	$('.arrow.select, .homefade.select').removeClass('select');
	$('.arrow:eq('+ pick +'), .homefade:eq('+ pick +')').addClass('select');
}

