var l = function(x){console.log(x);};
if(typeof window != 'undefined') {
	window.Aiwa = new Object ;
}else{Aiwa = new Object;}

Aiwa.$ = function(arg,dom){
	return Aiwa.$.prototype.init(arg,dom);
};
Aiwa.$.prototype.author = 'Aiwa-20090713';
// toLowerCase
Aiwa.$.prototype.init = function(arg,dom){
	
	this.length = 0;
	var cl = arguments.callee ;
	//args is node ;
	if(arg.nodeType){
		this[this.length] = arg;
		this.length ++ ;
		return this ;
	}
	//string 
	if(typeof arg == 'string'){
		if(typeof dom == 'undefined'){
			dom = new Array;
			dom.push(document);
		}
		if(dom.nodeType){
			var tmp = new Array;
			tmp.push(dom);
			dom = tmp;
		}
		if((typeof dom).toLowerCase() == 'object'){
			var indx = 0;
			var tmp = new Array;
			while(typeof dom[indx] != 'undefined'){
				tmp.push(dom[indx]);
				indx ++ ;
			}
			dom = tmp ;
		}
		
		while(arg.match(/\s\s/)){
			arg = arg.replace(/\s\s/g,' ');
		}
		arg = arg.split(' ');
	}
	///////////////
	
	if(arg.length==1) {
		if(/.*?#(\w*)$/.test(arg[0])){ //'#xxx' by id ;
			this[0] = document.getElementById(RegExp.$1);
			this.length = 1 ;
			return this ;
		}
		
		for(var k=0;k<dom.length;k++){
			if(arg[0].indexOf('.')>0){
				
				var b = arg[0].split('.');
				var c = dom[k].getElementsByTagName(b[0]);
				for(var i=0;i<c.length;i++){
					if(c[i].className.indexOf(b[1])>=0){
						this[this.length] = c[i];
						this.length ++ ;
					}
				}
			}else {
				var c = dom[k].getElementsByTagName(arg[0]);
				for(var i=0;i<c.length;i++){
					this[this.length] = c[i];
					this.length ++ ;
				}
			}
		}
		return this ;
	}
	
	if(arg.length >1){
		var arr = new Array ;
		var str0 = arg[0];
		arg.shift();
		if(/.*?#(\w*)$/.test(str0)) return new cl(arg,Aiwa.$(str0));
		
		for(var k=0;k<dom.length;k++){
			if(str0.indexOf('.')>0){
				var b = str0.split('.');
				var c = dom[k].getElementsByTagName(b[0]);
				for(var i=0;i<c.length;i++){
					if(c[i].className.indexOf(b[1])>=0) arr.push(c[i]);
				}
			}else {
				var c = dom[k].getElementsByTagName(str0);
				for(var i=0;i<c.length;i++){
					arr.push(c[i]);
				}
			}
		}
		return new cl(arg,arr);
	}
	return this ;
};

Aiwa.$.prototype.first = function(){
	return Aiwa.$(this[0]);
};
Aiwa.$.prototype.last = function(){
	return Aiwa.$(this[this.length-1]);
};

Aiwa.$.prototype.css = function(k,v){
	if(typeof k =='string' && typeof v == 'undefined'){
		return this[0].style[k];
	}
	
	if((typeof k).toLowerCase() == 'object'){
		for(var i=0;i<this.length;i++){
			for(var j in k){
				this[i].style[j] = k[j];
			}
		}
		return this ;
	}
	if(typeof v == 'string' && typeof v == 'string'){
		for(var i=0;i<this.length;i++){
			this[i].style[k] = v;
		}
		return this ;
	}
	return this ;
};


Aiwa.$.prototype.html = function(hm){
	if(typeof hm == 'undefined') return this[0].innerHTML;
	if(typeof hm == 'string'){
		for(var i=0;i<this.length;i++){
			this[i].innerHTML = hm;
		}
		return this;
	}
	return this ;
};
/////////////////////////////////////////////////////////////////////////////////
var onloadlist = new Array ;

var bottomScroll = false ;
var showImg = function(option){
	var selThis = this;
	this.pre = option.pre ;
	this.next = option.next ;
	this.img = option.img;
	
	Aiwa.$(this.pre).css({cursor:'pointer',textDecoration:'underline'});
	Aiwa.$(this.next).css({cursor:'pointer',textDecoration:'underline'});
	this.currentIndex = 0;
	
	this.imgs = new Array;
	this.addImg = function(img){
		if(img.indexOf('.jpg')>=0)
			selThis.imgs.push(img);
	};
	
	this.pre.onclick = function(e){
		selThis.currentIndex --;
		if(selThis.currentIndex <0){
			selThis.currentIndex =0;
			return ;
		}
		selThis.img.src = selThis.imgs[selThis.currentIndex];
	};
	this.init = function(){
		selThis.img.src = selThis.imgs[selThis.currentIndex];
	};
	
	this.next.onclick = function(){
		var len = selThis.imgs.length ;
		selThis.currentIndex ++;
		if(selThis.currentIndex >len-1){
			selThis.currentIndex =len-1;
			return;
		}
		selThis.img.src = selThis.imgs[selThis.currentIndex];
	};
};


window.onload = function(){
	for(var i=0;i<onloadlist.length;i++){
		(onloadlist[i])();
	}
};

var scrollPic = function(option){
	var selThis = this ;
	this.elFrame = option.elFrame;
	this.pre = option.pre;
	this.next = option.next ;
	this.pannelWidth = 0;
	this.timers = null ;
	this.floatLeft = 0 ;
	this.picArr = new Array ;
	Aiwa.$(this.elFrame).css({width:'750px',height:'128px',position:'relative',overflow:'hidden'});
	Aiwa.$('#addpicid').css({height:'128px',position:'absolute',left:'0'});
	this.pannel = Aiwa.$('#addpicid')[0]; 
	
	this.init = function(){
		selThis.pannelWidth = Aiwa.$('#addpicid div.box2').length * 150 ;
		Aiwa.$(selThis.pannel).css('width',selThis.pannelWidth+'px');
	};
	
	this.pre.onclick = function(){
		if(selThis.floatLeft>=0) return ;
		var tmpScrollLeft = selThis.floatLeft;
		selThis.floatLeft += 750;
		if(selThis.floatLeft>0){
			selThis.floatLeft = 0;
		}
		if(typeof topScroll == 'undefined' || topScroll == false){
			(function(){
				tmpScrollLeft -=  -30;
				Aiwa.$(selThis.pannel).css('left',tmpScrollLeft+'px');
				if(tmpScrollLeft<selThis.floatLeft){
					bottomScroll = true;
					selThis.timers = setTimeout(arguments.callee,20);
				}else{
					clearTimeout(selThis.timers);
					bottomScroll = false;
				}
			})();
		}else{
			setTimeout(function(){
				(function(){
				tmpScrollLeft -=  -30;
				Aiwa.$(selThis.pannel).css('left',tmpScrollLeft+'px');
				if(tmpScrollLeft<selThis.floatLeft){
					bottomScroll = true;
					selThis.timers = setTimeout(arguments.callee,20);
				}else{
					clearTimeout(selThis.timers);
					bottomScroll = false;
				}
			})();
			},1000);
		}
	};
	
	this.next.onclick = function(){
		if(selThis.floatLeft<=750-selThis.pannelWidth) return ;
		var tmpScrollLeft = selThis.floatLeft;
		selThis.floatLeft -= 750;
		if(selThis.floatLeft<750-selThis.pannelWidth){
			selThis.floatLeft = 750-selThis.pannelWidth;
		}
		if(typeof topScroll == 'undefined' || topScroll == false){
		(function(){
			tmpScrollLeft -= 30;
			Aiwa.$(selThis.pannel).css('left',tmpScrollLeft+'px');
			if(tmpScrollLeft>selThis.floatLeft){
				bottomScroll = true;
				selThis.timers = setTimeout(arguments.callee,20);
			}else{
				clearTimeout(selThis.timers);
				bottomScroll = false;
			}
		})();
		}else{
			setTimeout(function(){
				(function(){
			tmpScrollLeft -= 30;
			Aiwa.$(selThis.pannel).css('left',tmpScrollLeft+'px');
			if(tmpScrollLeft>selThis.floatLeft){
				bottomScroll = true;
				selThis.timers = setTimeout(arguments.callee,40);
			}else{
				clearTimeout(selThis.timers);
				bottomScroll = false;
			}
			})();
			},1000);
		}
	};
};







