var wSet = function(wEff) {
	wEff.set({
		'opacity': 0
	});
}

var wShow = function(wEff) {
	wEff.start({
		'opacity': 1
	});
}

var wHide = function(wEff) {
	wEff.start({
		'opacity': 0
	});
}

window.addEvent('domready', function() {
        //create your array to pass to Fx.elements
	var contentElems = $$('.content');
	var wrapElems = $('contentwrap'); 
	var pageturn = $$('.pageturn_tit');

        //create a new Fx object
	wrapEffects = new Fx.Morph(wrapElems, {
		link: 'cancel',
		duration: 800,
		frames: 120
	});

	//Blogposts=0,Stories=1 on top by default
	var frame = 1;
	//Random default page
//	var frame=Math.floor(Math.random()*2);

	this.addEvent('load', function(){
		contentElems[frame].addClass('inactive');
		pageturn[frame].removeClass('active');
		other_frame=frame+1;
		if(other_frame == 2){other_frame=0;}
		pageturn[other_frame].removeClass('active');
		pageturn[frame].addClass('active');
	});

	//Flip between two content sets
	$('pageturn').addEvent('click', function(e){
		e.stop();
		wHide(wrapEffects);
		setTimeout(function(){
			contentElems[frame].removeClass('inactive');
			pageturn[frame].removeClass('active');
			frame = frame+1;
			if(frame == 2){frame=0;}
			wSet(wrapEffects);
			pageturn[frame].addClass('active');
			contentElems[frame].addClass('inactive');
			wShow(wrapEffects);
			}.bind(wrapEffects), 800);
		}.bind(wrapEffects)
	);
});

