
 /* 1  TODO -- profile 

 */ 
$.fn.pageflip=function(options){var ul=this,o=$(this).data('pageflip');if(o){o._dispatch.apply(o,arguments);}else{$(this).data('pageflip',(function(options){var page=0,pages=$('li',ul).length;var w=$(ul).width()>>1;var animationDelay=options&&options.animationDelay||1000;$('li',ul).each(function(index){$(this).data('index',index);}).hide().css({position:'absolute','float':'none',left:0,top:0});function getIndex(index){if(typeof index==='number'||typeof index==='string'&&index.match(/^\d+$/)){return pageRef(index).data('index');}
return $(index,ul).data('index');}
function pageRef(index){return $('li:eq('+index+')',ul);}
function turnPrev(newPage,animate,callback){var delay=animate?animationDelay:0;if(!callback){callback=function(){};}
page=getIndex(newPage);var p1=pageRef(page),p2=pageRef(page+1),p3=pageRef(page+2),p4=pageRef(page+3);$('li',ul).hide();p1.css({zIndex:1,left:0}).show();p2.css({clip:'rect(auto 0px auto auto)',zIndex:3,left:w}).show().animate({left:w,clip:'rect(auto auto auto auto)'},delay,callback);p3.css({zIndex:4,left:0}).show().animate({left:w*2,clip:'rect(auto 0px auto auto)'},delay,function(){$(this).hide().css('clip','rect(auto auto auto auto)');});p4.css({zIndex:2,left:w}).show();}
function turnNext(newPage,animate,callback){var delay=animate?animationDelay:0;if(!callback){callback=function(){};}
page=getIndex(newPage);var p1=pageRef(page-2),p2=pageRef(page-1),p3=pageRef(page),p4=pageRef(page+1);$('li',ul).hide();p1.css({zIndex:1,left:0}).show();p2.css({clip:'rect(auto auto auto auto)',zIndex:3,left:w}).show().animate({clip:'rect(auto 0px auto auto)'},delay,function(){$(this).hide();});p3.css({clip:'rect(auto 0px auto auto)',zIndex:4,left:w*2}).show().animate({left:0,clip:'rect(auto auto auto auto)'},delay,callback);p4.css({zIndex:2,left:w}).show();}
function setPage(newPage,animate){var index=(getIndex(newPage)|1)-1;if(index<page){(function(){if(index<page){turnPrev(page-2,animate,arguments.callee);}}());}else if(index>page){(function(){if(index>page){turnNext(page+2,animate,arguments.callee);}}());}}
var controller={prevPage:function(){if(page>=2){turnPrev(page-2,true);}},nextPage:function(){if(page<pages-2){turnNext(page+2,true);}},setPage:function(index){return setPage(index,true);},_dispatch:function(op,arg1,arg2,arg3){if(this[op]){this[op](arg1,arg2,arg3);}}};$('li',ul).click(function(){if(page==$(this).data('index')){controller.prevPage();}else if(page+1==$(this).data('index')){controller.nextPage();}});turnPrev(0,false);return controller;}(options)));}
return this;};