function AjaxLoader(id) {
	var url = "http://www.konstructive.com/?page_id=56&pid="+id;
	//alert(url);
	$('#proj-deets').load(url, function(){
		//alert($(this).html());
		//$.getScript('http://konstructive.com/wp-content/themes/konstructive/js/konstructive.js');
		projInit();
		
	}).fadeIn('slow');

}
function scrollHome(){

}
function scrollToPosition(element) {
    if (element !== undefined) {
        $("#proj-screen-canvas").scrollTo(element, 200);
    }
	return false;
}
function projInit(){
	/*
	var next;
	$('.nextslide').click(function() {
	    if ( next === undefined ) {
	        next = $('.proj-slide img').next();
	    } else {
	         next = next.next();   
	    }
		if ( $('.proj-slide img').next() == false){
			next = 0;
		}
	    $("#proj-screen-canvas").scrollTo(next, 200);	
		return false;
	});	
		return false;
		*/
		$('.nextslide, .prevslide').click(function(){
			return false;
		});
		var posts = $('.proj-slide img');
		    var position = 0; //Start Position
		    var next = $('.nextslide');
			if (posts.length == 1) {
		    	next.hide();				
			}
			else {
				$('.nextslide').show();	
				
			}
		    var prev = $('.prevslide').hide();

		    //Better performance to use Id selectors than class selectors
		    next.click(function(evt) {
		        //Scroll to next position
		        prev.show();
		        scrollToPosition(posts[position += 1]);
		        if (position === posts.length - 1) {
		            next.hide();
		        }
		    });

		    prev.click(function(evt) {
		        //Scroll to prev position    
		        next.show();
		        scrollToPosition(posts[position -= 1]);
		        if (position === 0) {
		            prev.hide();
		        }
		    });	
		$('.scroll-back').click(function(){
			$('#list-grid').scrollTo(0, 200 );
			$('#proj-deets').fadeOut('slow');
			return false;
		});
		return false;
}
$('document').ready(function() {
	//$('#proj-deets').live();
	$.localScroll.defaults.axis = 'y';
	$.localScroll();
	// Hovers for projects
			$('.proj-info h2').after('<div class="proj-spyglass"></div>');
	$('.project').hover(function(){
		$(this).children('.proj-info').fadeIn('fast');
	});
	$('.project').mouseleave(function(){
		$(this).children('.proj-info').fadeOut('fast');
		
	});
	$('.proj-info').click(function(){
		$(this).siblings('.proj-img').children('a').trigger('click');
	});
	// loads projects and slides stuff
	$('.proj-img a').click(function(){
		AjaxLoader($(this).attr('href').match('[1-9]*$'));
		$('#list-grid').scrollTo( 2050, 300 );
		return false;
	});
	$('.scroll-back').click(function(){
		$('#list-grid').scrollTo(0, 300 );
		return false;
	});
});
