//CLICK N SLIDE
//� Websir(websir.co.uk)
//created by Alex Oliver on 02/12/09 15:50 GMT
//
//VARIABLES
// aniSpeed = the speed of the element animation 
// easing = the jquery effect used in the animation of the content
// direction = determines what direction the element should slide. usage: left or right
//
//USAGE
//$('.cnsC').clickNslide();

(function($) {
    $.fn.extend({
        clickNslide:function(options){
            var defaults={aniSpeed:300,easing:'linear',direction:'right'};
            var options = $.extend(defaults, options);
            return this.each(function() {
                var thsObj=$(this);
                var secLft=thsObj.children('.secLft');
                var secRte=thsObj.children('.secRte');
                var aniWidth=secRte.width();
                var aniDir='';
                var aniOut='-';
                if(options.direction=='right'){aniDir='-';aniOut='';}
				
				secRte.children('.cnsSec')
                .css({left:aniDir+aniWidth+'px',display:'block'})
                .eq(0).css({left:0});
				

                secLft.children('ul').children('li').children('a').click(function(){
                   thsIndex=$(this).parent().parent().children('li').children('a').index(this);
                   secRte.children('.cnsSec').each(function(){
                       if($(this).css('left')=="0px"){aniOutIndx=$(this).parent().children('.cnsSec').index(this);}
                   });

                   if(thsIndex!=aniOutIndx){
                       secLft.children('.mask').css({display:'block',zIndex:10});
                       secRte.children('.cnsSec').eq(thsIndex).animate({left:0},
                       {duration:options.aniSpeed,queue:false,'easing':options.easing});
                       secRte.children('.cnsSec').eq(aniOutIndx).animate({left:aniOut+aniWidth},
                       options.aniSpeed,options.easing,function(){
                           $(this).css({left:aniDir+aniWidth+'px'});
                           secLft.children('.mask').css({display:'none'});
                       });
                   }
                   return false;
                });
            });
        }
    });
})(jQuery);