﻿var length = 4;
var time = 5000;
﻿var pic = ['images/p_pic_1.jpg','images/p_pic_2.jpg'];
var title = [];
function loadTitle(func){
	var html = [];
	html[0] = '<div class="title_01"><ul><li id="se1">01</li><li id="se2">02</li><li id="se3">03</li><li id="se4">04</li></ul></div>';
	html[1] = '<div class="title_02"><ul>';
	html[2] = '<div class="title_03"><ul><li><img src="' + pic[0] + '" /></li><li><img src="' + pic[1] + '" /></li></ul></div>'
	html[3] = '<div class="title_04"><ul>';
	this.ID = 0;
	this.tempID = 0;
	this.myMar = null;
	this.init = function(){
		for(var i = 0; i < length; i++){
			if(i == 0){
				html[1] += '<li id="tl' + (i + 1) + '" style="display:block"><a href="Article-' + title[i][0] + '.aspx">' + title[i][1] + '</a></li>';
				html[3] += '<li id="ct' + (i + 1) + '" style="display:block">' + title[i][2] + '</li>';
			} else {
				html[1] += '<li id="tl' + (i + 1) + '" style="display:none"><a href="Article-' + title[i][0] + '.aspx">' + title[i][1] + '</a></li>';
				html[3] += '<li id="ct' + (i + 1) + '" style="display:none">' + title[i][2] + '</li>';
			}
		}
		html[1] += '</ul></div>';
		html[3] += '</ul></div>';
		$('#title').html(html[0] + html[1] + html[2] + html[3]);
		for(var i = 0; i < length; i++){
			$('#se' + (i + 1)).click(function(){
				eval(func + '.click(' + this.id.replace('se','') + ')')
			})
		}
		this.click(1);
		this.start();
	}
	this.click = function(id){
		if(id == this.ID) { return;}
		try{
			$('#tl' + this.ID).css({display:'none'});
			$('#ct' + this.ID).css({display:'none'});
			$('#se' + this.ID).css({background:'#ccc',color:'#000'});
		}catch(e){}
		$('#se' + id).css({background:'#930',color:'#fff'});
		$('#tl' + id).css({display:'block'});
		$('#ct' + id).css({display:'block'});
		this.ID = id;
		this.tempID = id;
	}
	this.start = function(){
		this.myMar = setInterval(this.move, time);
	}
	this.move = function(){
		var i = eval(func + '.tempID');
		if(i > length) i = 1;
		eval(func + '.click(' + i + ')');
		i++;
		eval(func + '.tempID=' + i);
	}
}
var ca = new loadTitle('ca');