var cookie = {
    
    setCookie: function (c_name,value,exdays)
    {
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value;
    }, 

    getCookie: function(c_name)
    {
        var i,x,y,ARRcookies=document.cookie.split(";");
        for (i=0;i<ARRcookies.length;i++)
        {
            x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
            y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
            x=x.replace(/^\s+|\s+$/g,"");
            if (x==c_name)
            {
                return unescape(y);
            }
        }
    }    
}
// usage: log('inside coolFunc', this, arguments);
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
      arguments.callee = arguments.callee.caller;
      console.log( Array.prototype.slice.call(arguments) );
  }
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


/**
 * This is a jquery slider plugin is a simple interface for adding an
 * animated carousel for paging.
 */
(function( $ ){
    // default settings
    var settings = {};
    var wrapper,height,width,page=1,pages=0,touched=false,timeoutId;
    // methods
    var methods = {
        init : function( options ) {
			if (options && options.width && options.height){
				height = options.height;
				width = options.width;
			} else {
				height = (this.height());
				width = (this.width());
			}
            this.css("position","relative");
            this.css("overflow","hidden");
            $.extend( settings, options );
            return this.each(function(){
		    var panels = $(this.children).wrapAll('<div id="brentisinyourdom"/>');
		    wrapper = panels.parent();
		    pages=wrapper[0].children.length;
		    wrapper.css('position','relative');
		    wrapper.height(height)
			wrapper.width( width* (wrapper[0].children.length) )
			wrapper.css('border','0px');
		    var i = 0;
		    panels.each(function(){
			    $(this).height(height)
				$(this).width(width)
				$(this).css('border','0px')
				$(this).css('padding','0px')
				i++;
			    $(this).css('display','block')
				$(this).css('position','relative')
				$(this).css('float','left')
				});
		});
        },
        /**
         * takes a callback who get this:
         * {page:page,pages:pages}
         */
        to : function( to, cb ) {
	    var expr="";
	    if(to>page){
		expr = '-='+(width*(to-page))
	    } else if (to<page) {
		expr = '+='+(width*(page-to))
	    } else return;
	    page=to;
            wrapper.animate({
		    left: expr
			}, 500, 'linear', function() {
			if(cb)cb({
				page:page,
				    pages:pages
				    });
		});
        },
        /**
         * takes a callback who get this:
         * {page:page,pages:pages}
         */
        rotate : function( timer, cb ) {
            timeoutId = setTimeout(function(){
                if(!touched)
                    (function r(){
                        if(page<pages){
                            if(cb)cb(page+1);
                            methods.next();
                            if(!touched)
                                timeoutId = setTimeout(function(){
                                    r()
                                },timer);
                        }else{
                            if(cb)cb(1);
                            methods.to(1);
                        }
                    })();
            },timer);
       },
        stopRotating : function() {
            clearTimeout(timeoutId)
            touched=true;
        },

        /**
         * takes a callback who get this:
         * {page:page,pages:pages}
         */
        next : function( cb ) {
            if(page==pages)return;
            page++;
            wrapper.animate({
		    left: '-='+width
			}, 500, 'swing', function() {
			if(cb)cb({
				page:page,
				    pages:pages
				    });
		});
        },
        /**
         * takes a callback who get this:
         * {page:page,pages:pages}
         */
        prev : function( cb ) {
            if(page==1)return;
            page--;
            wrapper.animate({
		    left: '+='+width
			}, 500, 'swing', function() {
			if(cb)cb({
				page:page,
				    pages:pages
				    });
		});
        }
    };
    $.fn.slide = function(method) {
        if ( methods[method] ) {
            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on jQuery.slide' );
        }
        return this;
    };

})( jQuery );

