oo1=new Object();

oo1.curCov = 1;
oo1.curCovArr = -1;

oo1.animate = 0;
oo1.covloaded = 0;

var covers=new Array();
var coverurls=new Array();
var covtitles = new Array();


// CALL TO START

function goCovers() {
	if(jQuery('.fullcovers li').length) { // IF COVERS
		jQuery('.fullcovers li').each(function(index) {
			covers[index] = jQuery(".cvrlnk", this).attr('href');
			coverurls[index] = jQuery(".artlnk", this).attr('href');
			covtitles[index] = jQuery(".artlnk", this).text();
		});
		
		var logodiv = jQuery("#coverlogo").html();
		
		jQuery('#mag_content').append("<div class=\"blackcover foapa0\">"+logodiv+"</div>");
		jQuery(".blackcover").animate({ opacity: 1 }, 250, function() {
			jQuery('#mag_content').replaceWith("<div id=\"pgfullcovers\"><img src=\""+homedir+"img/gif/empty.png\" class=\"coverimg1\" /><img src=\""+homedir+"img/gif/empty.png\" class=\"coverimg2\" /><div class=\"openbox1 foapa0\"><div class=\"openmag\"><a href=\"\" class=\"opentxt\">J.J. Abrams Mystery Box</a><br /><a href=\"\" class=\"openarrow\"> &nbsp; &rarr;</a></div></div><div class=\"openbox2 foapa0\"><div class=\"openmag\"><a href=\"\" class=\"opentxt\">Open The Magazine</a><br /><a href=\"\" class=\"openarrow\"> &nbsp; &rarr;</a></div></div>" + "<div id=\"coverlogo\">"+logodiv+"</div>" + "</div>");
			
			oo1.startCover();
		});
	}
}


// START

oo1.startCover = function (){
	jQuery(".openbox"+1).animate({ opacity: 0 }, 50);
	jQuery(".openbox"+2).animate({ opacity: 0 }, 50);
	jQuery(".coverimg"+1).animate({ opacity: 0 }, 50);
	jQuery(".coverimg"+2).animate({ opacity: 0 }, 50, function() { oo1.goNextCov(); }); 
}


oo1.loadedCover = function (){
	if((oo1.animate == 0) && (oo1.covloaded = 1)) {

		oo1.covhei = jQuery(".coverimg"+oo1.curCov).height(); oo1.covwid = jQuery(".coverimg"+oo1.curCov).width();
		
		oo1.wider = 0; oo1.higher = 0;
		if((oo1.covhei/4) > (oo1.covwid/3)) { // HIGHER
			oo1.tarwid = 1024;
			oo1.tarhei = Math.round((oo1.covhei/oo1.covwid)*1024);
			oo1.higher = oo1.tarhei - 1365;			
		} else { // WIDER
			oo1.tarhei = 1365;
			oo1.tarwid = Math.round((oo1.covwid/oo1.covhei)*1365);
			oo1.wider = oo1.tarwid - 1024;
		}
		
		// SIZE AND RESET //
		jQuery(".coverimg"+oo1.curCov).animate({ height: oo1.tarhei+"px", width: oo1.tarwid+"px", left: "0px", top: "0px" }, 1);
		
		jQuery(".coverimg"+oo1.curCov).unbind("load");
		
		oo1.covAnimate();
	} else {
	 //alert("not yet");
	 // THIS CAUSES BLUP!
	 }
	
}

oo1.goNextCov = function (){
	if(oo1.curCov == 1) { oo1.curCov++; } else { oo1.curCov = 1; }
	oo1.curCovArr++;
	if (covers[oo1.curCovArr] == undefined) { oo1.curCovArr = 0; }
	//oo1.covUrl = "00coversystem/"+covers[oo1.curCovArr]+".jpg";
	oo1.covUrl = covers[oo1.curCovArr];
	oo1.covloaded = 0;
	jQuery(".coverimg"+oo1.curCov).css({ height: "", width: "" });
	jQuery(".coverimg"+oo1.curCov).attr("src", oo1.covUrl); 
	jQuery(".coverimg"+oo1.curCov).load(function() {		oo1.covloaded = 1; oo1.loadedCover(); 		});
}

oo1.covAnimate = function (){
	// ANIMATE //
	oo1.animate = 1;
	
	oo1.beginleft = 0; oo1.begintop = 0; oo1.beginwidth = oo1.tarwid; oo1.beginheight = oo1.tarhei;
	oo1.moveleft = 0; oo1.movetop = 0; oo1.movewidth = oo1.tarwid; oo1.moveheight = oo1.tarhei;
	
	if (oo1.wider > 0) {
		oo1.beginleft = Math.round(Math.random()*oo1.wider*-1); oo1.moveleft = Math.round(Math.random()*oo1.wider*-1);
	} else if (oo1.higher > 0) {
		oo1.begintop = Math.round(Math.random()*oo1.higher*-1); oo1.movetop = Math.round(Math.random()*oo1.higher*-1);
	} 
	oo1.covResize = (1+(0.3*Math.random()));
	if (Math.random() > 0.5) { // CHANCE
		if (Math.random() > 0.5) {
			oo1.beginwidth = oo1.beginwidth * oo1.covResize; oo1.beginheight = oo1.beginheight * oo1.covResize;
		} else {
			oo1.movewidth = oo1.beginwidth * oo1.covResize; oo1.moveheight = oo1.beginheight * oo1.covResize;
		}
	}
	
	jQuery(".openbox"+oo1.curCov+" .openmag .opentxt").text(covtitles[oo1.curCovArr]);
	jQuery(".openbox"+oo1.curCov+" .openmag .opentxt").attr("href", coverurls[oo1.curCovArr]);
	jQuery(".openbox"+oo1.curCov+" .openmag .openarrow").attr("href", coverurls[oo1.curCovArr]);
	
	if(oo1.curCov == 1) {
		jQuery(".openbox"+2).animate({ opacity: 0 }, 300, function() { jQuery(".openbox"+2).hide(); });
		jQuery(".openbox"+1).show();
		jQuery(".openbox"+1).animate({ opacity: .85 }, 300);
	} else {
		jQuery(".openbox"+2).show();
		jQuery(".openbox"+2).animate({ opacity: .85 }, 300);
		jQuery(".openbox"+1).animate({ opacity: 0 }, 300, function() { jQuery(".openbox"+1).hide(); });
	}
	
	if(oo1.curCov == 1) {
		jQuery(".coverimg"+2).animate({ opacity: 0 }, 400);
	}

	
	// END // START
	jQuery(".coverimg"+oo1.curCov).animate({ height: oo1.beginheight+"px", width: oo1.beginwidth+"px", left: oo1.beginleft+"px", top: oo1.begintop+"px", opacity: 0 }, 50, function() { jQuery(".coverimg"+oo1.curCov).animate({ opacity: 1 }, 400, function() {   jQuery(".coverimg"+oo1.curCov).animate({ height: oo1.moveheight+"px", width: oo1.movewidth+"px", left: oo1.moveleft+"px", top: oo1.movetop+"px" },4000);    }); }); 
	
		
	setTimeout(function(){ oo1.animate = 0; oo1.loadedCover(); }, 5500);
	setTimeout(function(){ oo1.goNextCov(); }, 4500);	
};
/*************************************************
jquery.animate-enhanced plugin v0.80
Author: www.benbarnett.net || @benpbarnett

Copyright (c) 2011 Ben Barnett
Licensed under the MIT license
http://www.opensource.org/licenses/mit-license.php
**************************************************/
(function(a,b,c){function u(a,b,c,d){var e=h.exec(b),f=a.css(c)==="auto"?0:a.css(c),g=typeof f=="string"?A(f):f,i=typeof b=="string"?A(b):b,j=d===!0?0:g,k=a.is(":hidden"),l=a.translation();c=="left"&&(j=parseInt(g,10)+l.x),c=="right"&&(j=parseInt(g,10)+l.x),c=="top"&&(j=parseInt(g,10)+l.y),c=="bottom"&&(j=parseInt(g,10)+l.y),!e&&b=="show"?(j=1,k&&a.css({display:"block",opacity:0})):!e&&b=="hide"&&(j=0);if(e){var m=parseFloat(e[2]);return e[1]&&(m=(e[1]==="-="?-1:1)*m+parseInt(j,10)),m}return j}function v(a,b,c){return(c===!0||n==!0&&c!=!1)&&t?"translate3d("+a+"px,"+b+"px,0)":"translate("+a+"px,"+b+"px)"}function w(b,c,d,f,g,h,i,l){var m=b.data(k)?z(b.data(k))?a.extend(!0,{},j):b.data(k):a.extend(!0,{},j),n=g,o=a.inArray(c,e)>-1;if(o){var p=m.meta,q=A(b.css(c))||0,r=c+"_o";n=g-q,p[c]=n,p[r]=b.css(c)=="auto"?0+n:q+n||0,m.meta=p,i&&n===0&&(n=0-p[r],p[c]=n,p[r]=0)}return b.data(k,x(m,c,d,f,n,h,i,l))}function x(a,b,c,d,e,g,h,i){a=typeof a=="undefined"?{}:a,a.secondary=typeof a.secondary=="undefined"?{}:a.secondary;for(var j=f.length-1;j>=0;j--)typeof a[f[j]+"transition-property"]=="undefined"&&(a[f[j]+"transition-property"]=""),a[f[j]+"transition-property"]+=", "+(g===!0&&h===!0?f[j]+"transform":b),a[f[j]+"transition-duration"]=c+"ms",a[f[j]+"transition-timing-function"]=d,a.secondary[g===!0&&h===!0?f[j]+"transform":b]=g===!0&&h===!0?v(a.meta.left,a.meta.top,i):e;return a}function y(a){for(var b in a)if((b=="width"||b=="height")&&(a[b]=="show"||a[b]=="hide"||a[b]=="toggle"))return!0;return!1}function z(a){for(var b in a)return!1;return!0}function A(a){return parseFloat(a.replace(/px/i,""))}function B(b,c,e){var f=a.inArray(b,d)>-1;return(b=="width"||b=="height")&&c===parseFloat(e.css(b))&&(f=!1),f}var d=["top","right","bottom","left","opacity","height","width"],e=["top","right","bottom","left"],f=["","-webkit-","-moz-","-o-"],g=["avoidTransforms","useTranslate3d","leaveTransforms"],h=/^([+-]=)?([\d+-.]+)(.*)$/,i=/([A-Z])/g,j={secondary:{},meta:{top:0,right:0,bottom:0,left:0}},k="jQe",l="cubic-bezier(",m=")",n=!1,o=null,p=document.body||document.documentElement,q=p.style,r=q.WebkitTransition!==undefined?"webkitTransitionEnd":q.OTransition!==undefined?"oTransitionEnd":"transitionend",s=q.WebkitTransition!==undefined||q.MozTransition!==undefined||q.OTransition!==undefined||q.transition!==undefined,t=n="WebKitCSSMatrix"in window&&"m11"in new WebKitCSSMatrix;a.expr&&a.expr.filters&&(o=a.expr.filters.animated,a.expr.filters.animated=function(b){return a(b).data("events")&&a(b).data("events")[r]?!0:o.call(this,b)}),a.extend({toggle3DByDefault:function(){n=!n}}),a.fn.translation=function(){if(!this[0])return null;var a=this[0],b=window.getComputedStyle(a,null),c={x:0,y:0};for(var d=f.length-1;d>=0;d--){var e=b.getPropertyValue(f[d]+"transform");if(e&&/matrix/i.test(e)){var g=e.replace(/^matrix\(/i,"").split(/, |\)$/g);c={x:parseInt(g[4],10),y:parseInt(g[5],10)};break}}return c},a.fn.animate=function(c,d,h,i){c=c||{};var j=typeof c.bottom=="undefined"&&typeof c.right=="undefined",n=a.speed(d,h,i),o=this,p=0,q=function(){p--,p===0&&typeof n.complete=="function"&&n.complete.apply(o[0],arguments)};return!s||z(c)||y(c)||n.duration<=0||a.fn.animate.defaults.avoidTransforms===!0&&c.avoidTransforms!==!1?b.apply(this,arguments):this[n.queue===!0?"queue":"each"](function(){var d=a(this),h=a.extend({},n),i=function(){var a={};for(var b=f.length-1;b>=0;b--)a[f[b]+"transition-property"]="none",a[f[b]+"transition-duration"]="",a[f[b]+"transition-timing-function"]="";d.unbind(r);if(!c.leaveTransforms==!0){var g=d.data(k)||{},h={};for(b=f.length-1;b>=0;b--)h[f[b]+"transform"]="";if(j&&typeof g.meta!="undefined")for(var i=0,l;l=e[i];++i)h[l]=g.meta[l+"_o"]+"px";d.css(a).css(h)}c.opacity==="hide"&&d.css("display","none"),d.data(k,null),q.call(d)},o={bounce:l+"0.0, 0.35, .5, 1.3"+m,linear:"linear",swing:"ease-in-out",easeInQuad:l+"0.550, 0.085, 0.680, 0.530"+m,easeInCubic:l+"0.550, 0.055, 0.675, 0.190"+m,easeInQuart:l+"0.895, 0.030, 0.685, 0.220"+m,easeInQuint:l+"0.755, 0.050, 0.855, 0.060"+m,easeInSine:l+"0.470, 0.000, 0.745, 0.715"+m,easeInExpo:l+"0.950, 0.050, 0.795, 0.035"+m,easeInCirc:l+"0.600, 0.040, 0.980, 0.335"+m,easeOutQuad:l+"0.250, 0.460, 0.450, 0.940"+m,easeOutCubic:l+"0.215, 0.610, 0.355, 1.000"+m,easeOutQuart:l+"0.165, 0.840, 0.440, 1.000"+m,easeOutQuint:l+"0.230, 1.000, 0.320, 1.000"+m,easeOutSine:l+"0.390, 0.575, 0.565, 1.000"+m,easeOutExpo:l+"0.190, 1.000, 0.220, 1.000"+m,easeOutCirc:l+"0.075, 0.820, 0.165, 1.000"+m,easeInOutQuad:l+"0.455, 0.030, 0.515, 0.955"+m,easeInOutCubic:l+"0.645, 0.045, 0.355, 1.000"+m,easeInOutQuart:l+"0.770, 0.000, 0.175, 1.000"+m,easeInOutQuint:l+"0.860, 0.000, 0.070, 1.000"+m,easeInOutSine:l+"0.445, 0.050, 0.550, 0.950"+m,easeInOutExpo:l+"1.000, 0.000, 0.000, 1.000"+m,easeInOutCirc:l+"0.785, 0.135, 0.150, 0.860"+m},s={},t=o[h.easing||"swing"]?o[h.easing||"swing"]:h.easing||"swing";for(var v in c)if(a.inArray(v,g)===-1){var x=a.inArray(v,e)>-1,y=u(d,c[v],v,x&&c.avoidTransforms!==!0);c.avoidTransforms!==!0&&B(v,y,d)?w(d,v,h.duration,t,x&&c.avoidTransforms===!0?y+"px":y,x&&c.avoidTransforms!==!0,j,c.useTranslate3d===!0):s[v]=c[v]}var A=d.data(k)||{};for(var C=f.length-1;C>=0;C--)typeof A[f[C]+"transition-property"]!="undefined"&&(A[f[C]+"transition-property"]=A[f[C]+"transition-property"].substr(2));d.data(k,A).unbind(r);if(!z(d.data(k))&&!z(d.data(k).secondary)){p++,d.css(d.data(k));var D=d.data(k).secondary;setTimeout(function(){d.bind(r,i).css(D)})}else h.queue=!1;return z(s)||(p++,b.apply(d,[s,{duration:h.duration,easing:a.easing[h.easing]?h.easing:a.easing.swing?"swing":"linear",complete:q,queue:h.queue}])),!0})},a.fn.animate.defaults={},a.fn.stop=function(b,d,e){if(!s)return c.apply(this,[b,d]);b&&this.queue([]);var g={};for(var h=f.length-1;h>=0;h--)g[f[h]+"transition-property"]="none",g[f[h]+"transition-duration"]="",g[f[h]+"transition-timing-function"]="";return this.each(function(){var h=a(this),j=window.getComputedStyle(this,null),l={},m;if(!z(h.data(k))&&!z(h.data(k).secondary)){var n=h.data(k);if(d){l=n.secondary;if(!e&&typeof n.meta.left_o!==undefined||typeof n.meta.top_o!==undefined){l.left=typeof n.meta.left_o!==undefined?n.meta.left_o:"auto",l.top=typeof n.meta.top_o!==undefined?n.meta.top_o:"auto";for(m=f.length-1;m>=0;m--)l[f[m]+"transform"]=""}}else for(var o in h.data(k).secondary){o=o.replace(i,"-$1").toLowerCase(),l[o]=j.getPropertyValue(o);if(!e&&/matrix/i.test(l[o])){var p=l[o].replace(/^matrix\(/i,"").split(/, |\)$/g);l.left=parseFloat(p[4])+parseFloat(h.css("left"))+"px"||"auto",l.top=parseFloat(p[5])+parseFloat(h.css("top"))+"px"||"auto";for(m=f.length-1;m>=0;m--)l[f[m]+"transform"]=""}}h.unbind(r).css(g).css(l).data(k,null)}else c.apply(h,[b,d])}),this}})(jQuery,jQuery.fn.animate,jQuery.fn.stop);

