﻿/**
 * @author Administrator
 */


function ShowPhoto(aData, options){
	this.options={
		id : ''
		, path: 'images/index'
	};
	this.data = aData;
	$.extend(this.options, options);
	this.init();
};

ShowPhoto.prototype = {
	init : function(){
		var _this = this;
		var items = $('#'+this.options.id+'>div'); 
		var item1 = new AutoPlay(this.data[0].small, {
			'htmlObj': items.get(0)
		});
	}
};


function AutoPlay(aData, options){
	this.options={
		htmlObj : ''
		,interval : 1000
		, path: 'images/index'
	};
	$.extend(this.options, options);
	this.obj = this.options.htmlObj;
	this.data = aData;
	this.timer = new Object();
	this.auto();
};

AutoPlay.prototype = {
    auto: function() {
        var _this = this;
        setInterval(function() {
            var index = _this.getRandom(0, _this.data.length-1);
            var src = _this.options.path + '/' + _this.data[index];
            $(_this.obj).find('img').attr('src', src);            
        }, this.options.interval);
    }
	, stop: function() {
	    clearInterval(this.timer);
	}
	, getRandom: function(under, over) {
	    switch (arguments.length) {
	        case 1:
	            return parseInt(Math.random() * under + 1);
	        case 2:
	            return parseInt(Math.random() * (over - under + 1) + under);
	        default:
	            return 0;
	    }
	}
};


$(document).ready(function(){
var data = [{ 'small': ['nindex_mazpic.jpg', 'wic_starpic_ad.jpg']}];

	new ShowPhoto(data, { id: 'scrollPhoto' });
});



