/*
$(document).ready(function() {
alert('loaded');
});

$('h1.test').hover(function() { 
	$(this).addClass('ohmy');
});

$('p.ingress').click(function() { 
	$(this).toggleClass('ohmy');
});
*/

$(document).ready(function() {

	/* BOUNCE SCROLL LINK ON HOVER
	$('a.scroll').hover(function() { 
		$(this).effect("bounce", { times:1 }, 300);
	});*/

	// FADE SCROLL LINK ON HOVER
	$('a.scroll').mouseover(function() { 
		$(this).fadeTo(300, 0.3);
	});
	$('a.scroll').mouseout(function() { 
		$(this).fadeTo(300, 1);
	});
	
	$('div.project_short').mouseover(function() { 
		$('img', this).fadeTo(100, 0.7);
	});
	$('div.project_short').mouseout(function() { 
		$('img', this).fadeTo(100, 1);
	});
	
	
	// PROJECT_SHORT IMAGE HOVER
	/*$('div.project_short a img').mouseover(function() { 
		$(this).fadeTo(300, 0.7);
	});
	$('div.project_short a img').mouseout(function() { 
		$(this).fadeTo(300, 1);
	});*/

	// SCROLL
	$('a.testi').mouseup(function() { 
		//alert('eee');
		//$.scrollTo('#post-4', 800, {easing:'elasout'} );
		//$.scrollTo('#post-4', 800 );		
		//alert('eee1');
		$(this).scrollTo("#post-4", 1000, {easing:"easeInOutCubic"});
		alert('eee2');
		
	});
	
	// SMOOTH SCROLLING FOR THE ANCHORS
	function scroll(direction, here) {

		var scroll, i,
			positions = [],
			collection = $('.scroll');

		collection.each(function() {
			positions.push(parseInt($(this).offset()['top'],10));
    });

    for(i = 0; i < positions.length; i++) {
			if (direction == 'next' && positions[i] > here) { scroll = collection.get(i); break; }
			if (direction == 'prev' && i > 0 && positions[i] >= here) { scroll = collection.get(i-1); break; }
		}

		if (scroll) {
			$.scrollTo(scroll, {
				duration: 750       
			});

		}

		return false;
  }

  $("#next,#prev").click(function() {        
  	return scroll($(this).attr('id'), parseInt($(this).offset()['top'],10));        
  });

  $(".scrolltoanchor").click(function() {
    $.scrollTo($($(this).attr("href"), parseInt($(this).offset()['top'],10)), {
        duration: 750
    });
    return false;
  });
	
	
	
	// SHOW MORE/LESS GIGS
	
	// Configuration
	var DEFAULT_NUMBER_OF_GIGS_SHOWN = 3;
	
	// Initialize gigs to show max DEFAULT_NUMBER_OF_GIGS_SHOWN entries
	// And add "show more" -button if needed
	number_of_items = $('.coming_gigs').length;
	if (number_of_items > DEFAULT_NUMBER_OF_GIGS_SHOWN) {
		div_height =  DEFAULT_NUMBER_OF_GIGS_SHOWN * $('.coming_gigs').height();			
		$('<a id="toggle_coming_gigs" href="#">N&auml;yt&auml; lis&auml;&auml; &rsaquo;</a></li>') .insertAfter('#gigs');
		//$('<li><a href="" class="more" id="toggle_coming_gigs">N&auml;yt&auml; lis&auml;&auml; &rsaquo;</a></li>') .append('.gigs');
		//$('.gigs').append('<li><a href="" class="more" id="toggle_coming_gigs">N&auml;yt&auml; lis&auml;&auml; &rsaquo;</a></li>');
		
		
		
	}
	else {
		div_height = number_of_items * $('.coming_gigs').height();			
	}
	
	$("#gigs").css({ height: div_height + "px" });
	
		
	// Toggle between show all and show DEFAULT_NUMBER_OF_GIGS_SHOWN
	$('#toggle_coming_gigs').toggle(function() {		
		div_height = $('.coming_gigs').length * $('.coming_gigs').height();
		$("#gigs").animate({ height: div_height + "px" });
				
		$('#toggle_coming_gigs').html("N&auml;yt&auml; v&auml;hemm&auml;n &rsaquo;");			
		
	}, function() { 
		number_of_items = $('.coming_gigs').length;
		if (number_of_items > DEFAULT_NUMBER_OF_GIGS_SHOWN) {
			div_height =  DEFAULT_NUMBER_OF_GIGS_SHOWN * $('.coming_gigs').height();			
		}
		else {
			div_height = number_of_items * $('.coming_gigs').height();	
		}
		$("#gigs").animate({ height: div_height + "px" });
		
		$('#toggle_coming_gigs').html("N&auml;yt&auml; lis&auml;&auml; &rsaquo;");
		
	});
	 

});


