window.log = function(){
  log.history = log.history || [];
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) 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||{});


// Custom selectboxes
(function($){
    $.fn.extend({
        customStyle : function(options) {
            if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
                return this.each(function() {
                    var currentSelected = $(this).find(':selected');
                    $(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
                    var selectBoxSpan = $(this).next();
                    var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
                    var selectBoxSpanInner = selectBoxSpan.find(':first-child');
                    selectBoxSpan.css({display:'inline-block'});
                    selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
                    var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
                    $(this).height(selectBoxHeight).change(function(){
                        // selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
                        selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
                        // Thanks to Juarez Filho & PaddyMurphy
                    });
                });
            }
        }
    });
})(this.jQuery);

// Custom checkboxes and radioboxes
(function($) {
  $.fn.ezMark = function(options) {
	options = options || {}; 
	var defaultOpt = { 
		checkboxCls   	: options.checkboxCls || 'ez-checkbox' , radioCls : options.radioCls || 'ez-radio' ,	
		checkedCls 		: options.checkedCls  || 'ez-checked'  , selectedCls : options.selectedCls || 'ez-selected' , 
		hideCls  	 	: 'ez-hide'
	};
    return this.each(function() {
    	var $this = $(this);
    	var wrapTag = $this.attr('type') == 'checkbox' ? '<div class="'+defaultOpt.checkboxCls+'">' : '<div class="'+defaultOpt.radioCls+'">';
    	// for checkbox
    	if( $this.attr('type') == 'checkbox') {
    		$this.addClass(defaultOpt.hideCls).wrap(wrapTag).change(function() {
    			if( $(this).is(':checked') ) { 
    				$(this).parent().addClass(defaultOpt.checkedCls); 
    			} 
    			else {	$(this).parent().removeClass(defaultOpt.checkedCls); 	}
    		});
    		
    		if( $this.is(':checked') ) {
				$this.parent().addClass(defaultOpt.checkedCls);    		
    		}
    	} 
    	else if( $this.attr('type') == 'radio') {

    		$this.addClass(defaultOpt.hideCls).wrap(wrapTag).change(function() {
    			// radio button may contain groups! - so check for group
   				$('input[name="'+$(this).attr('name')+'"]').each(function() {
   	    			if( $(this).is(':checked') ) { 
   	    				$(this).parent().addClass(defaultOpt.selectedCls); 
   	    			} else {
   	    				$(this).parent().removeClass(defaultOpt.selectedCls);     	    			
   	    			}
   				});
    		});
    		
    		if( $this.is(':checked') ) {
				$this.parent().addClass(defaultOpt.selectedCls);    		
    		}    		
    	}
    });
  }
})(jQuery);

var blogLatest = {
    slides: '',
    controls: '',
    activeSlide: '',
    executor: '',
    transitionTime: 300,
    slideChangeTime: 2000,
    
    init: function(slides, controls, prevButton, nextButton) {
        this.slides = slides;
        this.controls = controls;
        //$(this.slides).hide();
        //$(this.slides[0]).show();
        $(this.controls[0]).addClass('active');
        this.activeSlide = 0;
        
        var self = this;
        
        this.controls.each(function(i){
            $(this).click(function(){
                self.changeSlide(i);
                self.stopExecutor();
                return false;
            });
        });
        
        $(nextButton).click(function(){
            self.changeSlide((self.activeSlide + 1) % self.slides.length);
            return false;
        });
        $(prevButton).click(function(){
            self.changeSlide((self.activeSlide + self.slides.length - 1) % self.slides.length);
            return false;
        });
        
        //this.startExecutor();
    },
    
    changeSlide: function(nextSlide) {
        if (nextSlide == this.activeSlide) return true;
        $(this.slides[this.activeSlide]).fadeOut(this.transitionTime);
        $(this.slides[nextSlide]).fadeIn(this.transitionTime);
        $(this.controls[this.activeSlide]).removeClass('active');
        $(this.controls[nextSlide]).addClass('active');
        this.activeSlide = nextSlide;
    },
    
    startExecutor: function(){
        var self = this;
        this.executor = setInterval(function(){
            self.changeSlide((self.activeSlide + 1) % self.slides.length);
        }, this.slideChangeTime);
    },
    
    stopExecutor: function(){
        clearInterval(this.executor);
    }
}
