/**
 * wSlide 0.1 - http://www.webinventif.fr/wslide-plugin/
 * 
 * Rendez vos sites glissant !
 *
 * Copyright (c) 2008 Julien Chauvin (webinventif.fr)
 * Licensed under the Creative Commons License:
 * http://creativecommons.org/licenses/by/3.0/
 *
 * Date: 2008-01-27

(function($){$.fn.wslide=function(h){
  h=jQuery.extend({
  width:150,height:150,pos:1,col:1,effect:'swing',fade:false,horiz:false,autolink:true,duration:1500},h);

  function gogogo(g){g.each(function(i){
  var a=$(this);var e=a.attr('id');
  if(e==undefined){e='wslide'+i}
  $(this).wrap('<div class="wslide-wrap" id="'+e+'-wrap"></div>');a=$('#'+e+'-wrap');
  var b=a.find('ul li');
  var f=h.effect;
  if(jQuery.easing.easeInQuad==undefined&&(f!='swing'||f!='normal')){f='swing'}
  var g=h.width;var j=h.height;function resultante(a){
  var b=a;b=b.split('px');b=b[0];return Number(b)}var k=g-(resultante(b.css('padding-left'))+resultante(b.css('padding-right')));
  var l=j-(resultante(b.css('padding-top'))+resultante(b.css('padding-bottom')));
  var m=h.col;if(h.horiz){m=Number(b.length+1)}
  var n='';
  var o=Math.ceil(Number(b.length)/m);a.css('overflow','hidden').css('position','relative').css('text-align','left').css('height',j+'px').css('width',g+'px').css('margin','0').css('padding','0');a.find('ul').css('position','absolute').css('margin','0').css('padding','0').css('width',Number((m+0)*g)+'px').css('height',Number(o*j)+'px');b.css('display','block').css('overflow','hidden').css('float','left').css('height',l+'px').css('width',k+'px');
  b.each(function(i){
    var b=a.offset();
    var c=$(this).offset();
    $(this).attr('id',e+'-'+Number(i+1)).attr('rel',Number(c.left-b.left)+':'+Number(c.top-b.top));
    n+='<a href="#'+e+'-'+Number(i+1)+'">'+Number(i+1)+'</a>';  
  });  
  if(typeof h.autolink=='boolean'){if(h.autolink){a.after('<div class="wslide-menu" id="'+e+'-menu">'+n+'</div>')}}
  else if(typeof h.autolink=='string'){if($('#'+h.autolink).length){$('#'+h.autolink).html(n)}else{a.after('<div id="#'+h.autolink+'">'+n+'</div>')}}var p='#'+e+'-';var q="";$('a[href*="'+p+'"]').click(function(){$('a[href*="'+q+'"]').removeClass("wactive");
  $(this).addClass("wactive");
  var b=$(this).attr('href');b=b.split('#');b='#'+b[1];q=b;var c=$(b).attr('rel');c=c.split(':');
  var d=c[1];d=-d;c=c[0];c=-c;if(h.fade){a.find('ul').animate({opacity:0},h.duration/2,f,function(){$(this).css('top',d+'px').css('left',c+'px');
  $(this).animate({opacity:1},h.duration/2,f)})}else{a.find('ul').animate({top:d+'px',left:c+'px'},h.duration,f)}return false});if(h.pos<=0){h.pos=1}$('a[href$="'+p+h.pos+'"]').addClass("wactive");var r=$('a[href*="'+p+'"]:eq('+Number(h.pos-1)+')').attr('href');r=r.split('#');r='#'+r[1];q=r;
  var s=$(r).attr('rel');s=s.split(':');
  var t=s[1];t=-t;s=s[0];s=-s;a.find('ul').css('top',t+'px').css('left',s+'px')})}gogogo(this);return this}})(jQuery);
  */
  
/**
 * wSlide 0.1 - http://www.webinventif.fr/wslide-plugin/
 *
 * Rendez vos sites glissant !
 *
 * Copyright (c) 2008 Julien Chauvin (webinventif.fr)
 * Licensed under the Creative Commons License:
 * http://creativecommons.org/licenses/by/3.0/
 *
 * Date: 2008-01-27
 * Modified by Shikiryu : http://shikiryu.com/
 * Date: 2011-02-24
 */
(function($){
    $.fn.wslide = function(h){
        h = jQuery.extend({
            width: 150,
			height: 150,
			pos: 1,
			col: 1,
			effect: 'swing',
			fade: false,
			horiz: false,
			autolink: true,
			duration: 1500,
			button: true,
			autoplay: false,
			pause: 4501
        }, h);
		
		function goNext(){
			$('#nextBtn').trigger('click', [true]);
			timeOut = setTimeout(goNext,h.pause);
			//console.log('goNext'+' - timeOut id: '+timeOut);
		}
        function gogogo(g){
            g.each(function(i){
                var a = $(this);
				var uniqid = a.attr('id');
				if(uniqid == undefined){
					uniqid = 'wslide'+i;
				}
				$(this).wrap('<div class="wslide-wrap" id="'+uniqid+'-wrap"></div>');
				if(h.button){
					$('.wslide-wrap').prepend('<a href="#" class="navBtn" id="previousBtn" title="Precedent"><</a><a href="#" class="navBtn" id="nextBtn" title="Suivant">></a>');
				}
				a = $('#'+uniqid+'-wrap');
				var b = a.find('ul li');
				var nbElem = b.length;
               	var effets = h.effect;
				if(jQuery.easing.easeInQuad == undefined && (effets!='swing' || effets!='normal')){
					effets = 'swing';
				}
				var typex = h.width;
				var typey = h.height;
				function resultante(prop){
					var tempcalc = prop;
					tempcalc = tempcalc.split('px');
					tempcalc = tempcalc[0];
					return Number(tempcalc);
				}
				var litypex = typex-(resultante(b.css('padding-left'))+resultante(b.css('padding-right')));
				var litypey = typey-(resultante(b.css('padding-top'))+resultante(b.css('padding-bottom')));
				var col = h.col;
				if(h.horiz){
					col =  Number(b.length+1);
				}
				var manip = '';
				var ligne = Math.ceil(Number(b.length)/col);
				a.css('overflow','hidden').css('position','relative').css('text-align','left').css('height',typey+'px').css('width',typex+'px').css('margin','0').css('padding','0');
				a.find('ul').css('position','absolute').css('margin','0').css('padding','0').css('width',Number((col+0)*typex)+'px').css('height',Number(ligne*typey)+'px');
				b.css('display','block').css('overflow','hidden').css('float','left').css('height',litypey+'px').css('width',litypex+'px');
				b.each(function (i) {
					var offset = a.offset();
					var thisoffset = $(this).offset();
					$(this).attr('id',uniqid+'-'+Number(i+1)).attr('rel', Number(thisoffset.left-offset.left)+':'+Number(thisoffset.top-offset.top));
					manip += ' <a href="#'+uniqid+'-'+Number(i+1)+'">'+Number(i+1)+'</a>';
				});
				if(typeof h.autolink == 'boolean'){
					if(h.autolink){
						a.after('<div class="wslide-menu" id="'+uniqid+'-menu">'+manip+'</div>');
					}
				}else if (typeof h.autolink == 'string'){
					if($('#'+h.autolink).length){
						$('#'+h.autolink).html(manip);
					}else{
						a.after('<div id="#'+h.autolink+'">'+manip+'</div>');
					}
				}
				var start = '#'+uniqid+'-';
				var stoccurent = "";
				$('a[href*="'+start+'"]').click(function () {
						$('a[href*="'+stoccurent+'"]').removeClass("wactive");
						$(this).addClass("wactive");
						var tri = $(this).attr('href');
						tri=tri.split('#');
						position = tri[1].split('-');
						h.pos = position[1];
						tri='#'+tri[1];
						stoccurent = tri;
						var decal = $(tri).attr('rel');
						decal = decal.split(':');
						var decal2 = decal[1];
						decal2 = -decal2;
						decal = decal[0];
						decal = -decal;
						if(h.fade){
							a.find('ul').animate({ opacity: 0 }, h.duration/2, effets, function(){$(this).css('top',decal2+'px').css('left',decal+'px');$(this).animate({ opacity: 1 }, h.duration/2, effets)} );
						}else{
							a.find('ul').animate({ top: decal2+'px',left: decal+'px' }, h.duration, effets );
						}
						return false;
				});
				$('a.navBtn').click(function () {
						$('a[href*="'+stoccurent+'"]').removeClass("wactive");
						switch($(this).attr('title')){
							case 'Precedent':
								h.pos --;
								if(h.pos <= 0){
									h.pos = nbElem;
								}
								break;
							case 'Suivant':
								h.pos ++;
								if(h.pos > nbElem){
									h.pos = 1;
								}
								break;
							default:
								break;
						}
						$('a[href$="'+start+h.pos+'"]').addClass("wactive");
						var tri = start+h.pos;
						stoccurent = tri;
						var decal = $(tri).attr('rel');
						decal = decal.split(':');
						var decal2 = decal[1];
						decal2 = -decal2;
						decal = decal[0];
						decal = -decal;
						if(h.fade){
							a.find('ul').animate({ opacity: 0 }, h.duration/2, effets, function(){$(this).css('top',decal2+'px').css('left',decal+'px');$(this).animate({ opacity: 1 }, h.duration/2, effets)} );
						}else{
							a.find('ul').animate({ top: decal2+'px',left: decal+'px' }, h.duration, effets );
						}
						return false;
				});
				if(h.pos <= 0){
					h.pos = 1;
				}
				$('a[href$="'+start+h.pos+'"]').addClass("wactive");
				var tri = $('a[href*="'+start+'"]:eq('+Number(h.pos-1)+')').attr('href');
				tri=tri.split('#');
				tri='#'+tri[1];
				stoccurent = tri;
				var decal = $(tri).attr('rel');
				decal = decal.split(':');
				var decal2 = decal[1];
				decal2 = -decal2;
				decal = decal[0];
				decal = -decal;
				a.find('ul').css('top',decal2+'px').css('left',decal+'px');
            })
        }
		var timeOut = null;
        gogogo(this);
		if(h.autoplay){
			//setTimeout(goNext, Math.round(h.pause/2));
		}
		$('.wslide-wrap').mouseenter(function(e,simulated){
			if(!simulated){
				//console.log('mouse enter: '+this.id+' - timeOut id: '+timeOut);
				clearTimeout(timeOut);
				timeOut = null;
				$(this).find('.caption').slideToggle();
				if(h.button){
					$('.navBtn').fadeIn();
				}
			}
		}); 
		/*$('.wslide-wrap').mouseleave(function(){
			//console.log('mouse leave '+this.id+' - timeOut id: '+timeOut);
			if(timeOut == null){setTimeout(goNext, Math.round(h.pause/2));}
			$(this).find('.caption').slideToggle();
			if(h.button){
				$('.navBtn').fadeOut();
			}
		});*/
		return this;
    }
})(jQuery);


