/**
 * jQuery Diagonal Matrix Fade Plugin
 * Examples and documentation at: http://jonobr1.github.com/diagonalFade
 * Copyright (c) 2010 Jono Brandel
 * Version: .01 (18-MAY-2010)
 * Requires: jQuery v1.3.2 or later
 *
 * To Do:
 * + Extend Cycle or write own (based on jquery.cycle.lite.js)
 * + Make it so it's not just for a fixed container
 *
 * Copyright 2010 jonobr1
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
(function(a){if(a.support==undefined){a.support={opacity:!(a.browser.msie)}}a.fn.diagonalFade=function(b){var d=a.extend({},a.fn.diagonalFade.defaultOptions,b);return this.each(function(){var y=a(this);var s=y.width();var e=y.height();var k=y.children();var B=k[0].offsetWidth;var v=k[0].offsetHeight;var p=parseInt(e/v);var l=parseInt(s/B);var A=[];var x=[];var z=0;for(var u=0;u<p;u++){A[u]=new Array(l);for(var r=0;r<l;r++){if(k[u*l+r]&&k[u*l+r].offsetWidth>0&&k[u*l+r].offsetHeight>0){A[u][r]=z;z++}}}switch(d.fade){case"in":var g=1;break;case"out":var g=0;break}if((d.fadeDirection_y=="top-bottom"&&d.fadeDirection_x=="left-right")||(d.fadeDirection_y=="bottom-top"&&d.fadeDirection_x=="right-left")){for(var u=0;u<p+l-1;u++){var t=(u<l)?0:u-l+1;var q=(u<p)?0:u-p+1;var C=new Array();for(var r=u-q;r>=t;r--){C.push(A[r][u-r])}x.push(C)}if(d.fadeDirection_y=="top-bottom"&&d.fadeDirection_x=="left-right"){z=-1;c(y,x,z,d.fadeDirection_x,d.fadeDirection_y,g)}else{if(d.fadeDirection_y=="bottom-top"&&d.fadeDirection_x=="right-left"){z=x.length;c(y,x,z,d.fadeDirection_x,d.fadeDirection_y,g)}}}else{if((d.fadeDirection_y=="bottom-top"&&d.fadeDirection_x=="left-right")||(d.fadeDirection_y=="top-bottom"&&d.fadeDirection_x=="right-left")){for(var u=1-p;u<l;u++){var C=new Array();for(var r=0;r<p;r++){if((u+r)>=0&&(u+r)<l){C.push(A[r][u+r])}}x.push(C)}if(d.fadeDirection_y=="bottom-top"&&d.fadeDirection_x=="left-right"){z=-1;c(y,x,z,d.fadeDirection_x,d.fadeDirection_y,g)}else{if(d.fadeDirection_y=="top-bottom"&&d.fadeDirection_x=="right-left"){z=x.length;c(y,x,z,d.fadeDirection_x,d.fadeDirection_y,g)}}}}});function c(x,s,n,r,q,w){var y=x;var u=s;var p=n;var e=w;var h=r;var g=q;var v=true;if((h=="left-right"&&g=="top-bottom")||(h=="left-right"&&g=="bottom-top")){p++;if(u[p]){for(var m=0;m<u[p].length;m++){var l=u[p][m]+1;y.children(":nth-child("+l+")").animate({opacity:e},d.time,function(){if(v){c(y,u,p,h,g,e);v=false}})}}else{if(a.isFunction(d.complete)){d.complete.apply(this)}}}else{if((h=="right-left"&&g=="top-bottom")||(h=="right-left"&&g=="bottom-top")){p--;if(p>=0){for(var m=0;m<u[p].length;m++){var l=u[p][m]+1;y.children(":nth-child("+l+")").animate({opacity:e},d.time,function(){if(v){c(y,u,p,h,g,e);v=false}})}}else{if(a.isFunction(d.complete)){d.complete.apply(this)}}}}}};a.fn.diagonalFade.defaultOptions={time:100,fadeDirection_x:"left-right",fadeDirection_y:"top-bottom",fade:"out",complete:null}})(jQuery);
