/**
 * Mang cac logo doi tac
 * @var _ads
 */ 
var _ads = [];

/**
 * Bien ghi nhan Canh le trai ban dau
 * @var _ads
 */ 
var _vleft = 0;

/**
 * Khach hang doi tac
 * 
 * @param id 		Ma noi dung tra ve
 * @param logo 		Thuoc tinh hinh anh
 * @param hint 		Ghi chu
 * @param hspace 	Khoang cach giua cac hinh
 * 
 * @return void
 */
function marquee(id, logo, hint, hspase) {
    this.obj=document.getElementById(id);
    this.obj.onmouseout=function() {marqueeSequence(_ads);};
    this.obj.onmouseover=function() {clearTimeout(_ads[0].TO);};
    this.obj.logo=[];
    var _length = logo.length;

    for (var i=0;i<_length;i++){
	// Logo doi tac
	var img=document.createElement('img');
	img.src=logo[i][0];
	img.title=hint[i];
	img.alt=hint[i];
	img.style.border="0";

	// Lien ket den doi tac
	var _link=document.createElement('a');
	_link.href=logo[i][1];
	_link.target="_blank";
	_link.style.border="0";
	_link.appendChild(img);

	// Tao doi tuong
	this.obj.logo[i]=document.createElement('div');
	this.obj.logo[i].appendChild(_link);

	// Style cua doi tuong
	this.obj.logo[i].style.position = 'absolute';
	this.obj.logo[i].style.left = _vleft+'px';
	this.obj.logo[i].style.width = logo[i][2]+'px';
	this.obj.logo[i].style.height = logo[i][3];
	this.obj.appendChild(this.obj.logo[i]);
	_vleft += logo[i][2] + hspase;
    }
    _ads.push(this.obj);
}

/**
 * Chay logo quang cao theo trinh tu
 * 
 * @param _ads 		Mang doi tuong
 * 
 * @return void
 */
function marqueeSequence(_ads) {
    // Ket thuc neu ko ton tai doi tuong
    if (!_ads) return; 

    // Di chuyen hinh anh
    for (var j=_ads.length - 1; j > -1; j--) {
	var _length = _ads[j].logo.length;
	for (var i=0;i<_length;i++){
	    var x = _ads[j].logo[i].style;
	    x.left=(parseInt(x.left,10)-1)+'px';
	}

	// Logo dau tien
	var y = _ads[j].logo[0].style;
	if (parseInt(y.left,10)+parseInt(y.width,10)<0) {
	    // Logo dau tien chay het thi cho xuong cuoi cung
	    var z = _ads[j].logo.shift();
	    z.style.left = _vleft - (parseInt(z.style.width)) + 'px';
	    _ads[j].logo.push(z);
	}
    }
    _ads[0].TO=setTimeout('marqueeSequence(_ads)',10);
}