
function start_slide(fx){
	var t = this;
	with (t.prt.style) {
		width = t.width + "px"; 
		height = t.height + "px"; 
		position = "absolute";
		left = t.x + "px"; 
		top = t.y + "px"; 
		overflow = "hidden"; 			
	}
	with (t.elem1.style) {
		width = t.width + "px"; 
		height = t.height + "px"; 
		position = "absolute";		
		left = t.img1_left_pos;
		top = t.img1_top_pos;
	}	
	with (t.elem2.style) {
		width = t.width + "px"; 
		height = t.height + "px"; 
		position = "absolute";
		left = t.img2_left_pos;	
		top = t.img2_top_pos;		
	}	
	with (t.img1.style) {
		height = t.height;
		width = t.width;		
		filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + t.max_alpha + ')';
		filter = 'alpha(opacity='+t.max_alpha+')';		
		opacity = t.max_alpha/100;
		position = "absolute";
		left = 0;	
		top = 0;
	}	
	with (t.img2.style) {
		height = t.height;
		width = t.width;
		filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + t.max_alpha + ')';
		filter = 'alpha(opacity='+t.max_alpha+')';
		opacity = t.max_alpha/100;
		position = "absolute";
		left = 0;	
		top = 0;
	}	
	
	var src_1 = "img/"+ t.banner_name + "_" + t.fst_banner + ".jpg";	
	t.img1.src = src_1;	
	t.img2.src = src_1;	
	if (t.click) {
		t.prt.style.cursor = "pointer";
		t.prt.onclick = function() {open(t.img1.src , '', 'menubar = no, toolbar = no, location = no, status = no, height = ' + t.height + ', width = ' + t.width + '');};
	}	
	//alert(t.prt.getAttribute('onclick'));
	t.fx = fx;
	switch (t.fx) {
		case "move_up":
			t.step = -t.STEP || -6;
			t.img2_left_pos = 0;
			t.img2_top_pos = t.height + "px";
			t.fx_method = "img_slide_v()";
			break;
		case "move_down":
			t.step = t.STEP || 6;
			t.img2_left_pos = 0;
			t.img2_top_pos = - t.height + "px";
			t.fx_method = "img_slide_v()";
			break;
		case "move_left":
			t.step = -t.STEP || -6;
			t.img2_left_pos = t.width + "px";
			t.img2_top_pos = 0;
			t.fx_method = "img_slide_h()";
			break;
		case "move_right":
			t.step = t.STEP || 6
			t.img2_left_pos = - t.width + "px";
			t.img2_top_pos = 0;
			t.fx_method = "img_slide_h()";
			break;	
		case "fade":
			t.step = t.STEP || 3;
			t.img2_left_pos = 0;
			t.img2_top_pos = 0;			
			with (t.elem2.style) {
				filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=0)';
				filter = 'alpha(opacity=0)';
				opacity = 0;							
			}
			t.fx_method = "img_fade()";				
			break;	
		case "roll_left" :
			t.step = -t.STEP || -4;
			t.img2_left_pos = t.width  + "px";
			t.img2_top_pos = 0;
			t.img1.style.width = t.width + "px";
			t.img2.style.width = 0;			
			t.fx_method = "img_roll_x()";
			break;		
		case "roll_right" :
			t.step = t.STEP || 4;
			t.img2_left_pos = -t.width  + "px";
			t.img2_top_pos = 0;
			t.img1.style.width = t.width + "px";
			t.img2.style.width = 0;			
			t.fx_method = "img_roll_x()";
			break;			
		case "roll_down" :
			t.step = t.STEP || 6;
			t.img2_left_pos = 0;
			t.img2_top_pos = 0;
			t.img1.style.height = t.height + "px";
			t.img2.style.height = 0;			
			t.fx_method = "img_roll_y()";
			break;		
		case "roll_up" :
			t.step = -t.STEP || -6;
			t.img2_left_pos = 0;
			t.img2_top_pos = t.height + "px";
			t.img1.style.height = t.height + "px";
			t.img2.style.height = 0;			
			t.fx_method = "img_roll_y()";
			break;						
		case "explode" :
			t.step_x = Math.round(t.width / 50);
			t.step_y = Math.round(t.height / t.width * t.step_x);
			t.img2_left_pos = t.width/2  + "px";
			t.img2_top_pos = t.height/2 + "px";
			t.img2.style.height = 0;	
			t.img2.style.width = 0;					
			t.fx_method = "img_explode()";
			break;	
		case "strip_v" :			
		case "strip_h" :			
			t.img2_left_pos =  - t.width + "px";
			t.el_strip = new Array();
			t.img_strip = new Array();
			t.step = t.STEP || 2;
			if (t.fx == "strip_v") {
				t.n_strip = 6;							
				t.strip_w = Math.round(t.width / t.n_strip);
				t.fx_method = "img_strip_v()";
			}
			else {
				t.n_strip = 8;			
				t.strip_h = Math.round(t.height / t.n_strip);
				t.fx_method = "img_strip_h()";
			}	
			for (i = 0; i < t.n_strip; i++){
				t.el_strip[i] = document.createElement("div");
				with (t.el_strip[i].style) {
					position = "absolute";
					left = 0; 
					top = 0;
					width = t.width + "px";
					height = t.height + "px";
					clip = "rect(0, 0, 0, 0)"; 
					overflow = "hidden"; 
				}				
				t.img_strip[i] = document.createElement("img");
				t.img_strip[i].src = t.img2.src;
				with (t.img_strip[i].style) {
					width = t.width + "px";	
					height = t.height + "px";	
					position = "absolute";		
					left = 0;
					top = 0;					
				}
				t.el_strip[i].appendChild(t.img_strip[i]);	
				t.prt.appendChild(t.el_strip[i]);					
			}			
			break;		
		default :
			return;
		}				
	t.img_interval = setInterval('Banner.Instances['+t.id+'].img_change()', t.delay);	
}

function img_change (){
	var t = this;		
	
	t.fst_banner = (t.fst_banner + 1 > t.lst_banner) ? 1 : ++t.fst_banner;	
	t.elem2.style.left = t.img2_left_pos;	
	t.elem2.style.top = t.img2_top_pos;	
	var src_2 = "img/"+ t.banner_name + "_" + t.fst_banner + ".jpg";
	t.img2.src = src_2;	
	if (t.click) {
		t.prt.onclick = function() {open(t.img1.src , '', 'menubar = no, toolbar = no, location = no, status = no, height = ' + t.height + ', width = ' + t.width + '');};
	}	
	if (t.fx_method == "img_strip_h()" || t.fx_method == "img_strip_v()") {
		for (i = 0; i < t.n_strip; i++) {
			t.img_strip[i].src = t.img2.src;			
		}
	}
	t.idInterval = setInterval('Banner.Instances['+t.id+'].'+t.fx_method, Banner.rate);	
	
}  

function img_slide_h() {
	var t = this;
	t.slide_pos += t.step;	
	if (t.step > 0 && t.slide_pos > t.width - t.step || t.step < 0 && t.slide_pos <  - t.width)  {
		clearInterval(t.idInterval);
		t.img1.src = t.img2.src;
		t.elem1.style.left = t.img1_left_pos;
		t.elem2.style.left = t.img2_left_pos;
		t.slide_pos = 0;
	}
	else {
		t.elem1.style.left = parseInt(t.elem1.style.left) + t.step + "px";
		t.elem2.style.left = parseInt(t.elem2.style.left) + t.step + "px";				
	}
}

function img_slide_v() {
	var t = this;
	t.slide_pos += t.step;	
	if (t.step > 0 && t.slide_pos > t.height - t.step || t.step < 0 && t.slide_pos < - t.height)  {
		clearInterval(t.idInterval);
		t.img1.src = t.img2.src;
		t.elem1.style.top = t.img1_top_pos;
		t.elem2.style.top = t.img2_top_pos;
		t.slide_pos = 0;
	}
	else {
		t.elem1.style.top = parseInt(t.elem1.style.top) + t.step + "px";
		t.elem2.style.top = parseInt(t.elem2.style.top) + t.step + "px";		
	}			
}

function img_roll_x() {
	var t = this;
	t.slide_pos += t.step;	
	if (t.step > 0) {
		if (t.slide_pos > t.width)  {
			clearInterval(t.idInterval);
			t.img1.src = t.img2.src;
			t.elem1.style.left =  0;
			t.img1.style.width = t.width + "px";
			t.img2.style.width = 0;
			t.slide_pos = 0;		
		}
		else {			
			t.img1.style.width = parseInt(t.img1.style.width) - t.step + "px";	
			t.elem1.style.left = parseInt(t.elem1.style.left) + t.step + "px";	
			t.img2.style.width = parseInt(t.img2.style.width) + t.step + "px";		
		}	
	}
	else if (t.step < 0) {
		 if (t.slide_pos < -t.width)  {
		 	clearInterval(t.idInterval);
			t.img1.src = t.img2.src;
			t.elem1.style.left =  0;
			t.img1.style.width = t.width + "px";
			t.img2.style.width = 0;
			t.slide_pos = 0;	
		 }
		else {			
			t.img1.style.width = parseInt(t.img1.style.width) + t.step + "px";	
			t.img2.style.width = parseInt(t.img2.style.width) - t.step + "px";	
			t.elem2.style.left = parseInt(t.elem2.style.left) + t.step + "px";			
		}	
	}	
}

function img_roll_y() {
	var t = this;
	t.slide_pos += t.step;	
	if (t.step > 0) {
		if (t.slide_pos > t.height)  {
			clearInterval(t.idInterval);
			t.img1.src = t.img2.src;
			t.elem1.style.top =  0;
			t.img1.style.height = t.height + "px";
			t.img2.style.height = 0;
			t.slide_pos = 0;		
		}
		else {			
			t.img1.style.height = parseInt(t.img1.style.height) - t.step + "px";	
			t.elem1.style.top = parseInt(t.elem1.style.top) + t.step + "px";	
			t.img2.style.height = parseInt(t.img2.style.height) + t.step + "px";		
		}	
	}
	else if (t.step < 0) {
		 if (t.slide_pos < -t.height)  {
		 	clearInterval(t.idInterval);
			t.img1.src = t.img2.src;
			t.elem1.style.top =  0;
			t.img1.style.height = t.height + "px";
			t.img2.style.height = 0;
			t.slide_pos = 0;	
		 }
		else {			
			t.img1.style.height = parseInt(t.img1.style.height) + t.step + "px";	
			t.img2.style.height = parseInt(t.img2.style.height) - t.step + "px";	
			t.elem2.style.top = parseInt(t.elem2.style.top) + t.step + "px";			
		}	
	}
}

function img_fade() {
	var t = this;	
	t.slide_pos += t.step;
	if (t.slide_pos > t.max_alpha) {
		clearInterval(t.idInterval);
		t.elem1.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=0)';
		t.elem1.style.filter = 'alpha(opacity=0)';
		t.elem1.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + t.max_alpha + ')';
		t.elem1.style.filter = 'alpha(opacity=' + t.max_alpha + ')';
		t.elem1.style.opacity =  0; 
		t.elem2.style.opacity = t.max_alpha / 100;
		t.img1.src = t.img2.src;
		t.elem2.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=0)';
		t.elem2.style.filter = 'alpha(opacity=0)';
		t.elem1.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + t.max_alpha + ')';
		t.elem1.style.filter = 'alpha(opacity=' + t.max_alpha + ')';
		t.elem1.style.opacity = t.max_alpha / 100; 
		t.elem2.style.opacity = 0;
		t.slide_pos = 0;
	}
	else {
		t.elem1.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + (t.max_alpha - t.slide_pos) + ')';
		t.elem1.style.filter = 'alpha(opacity=' + (t.max_alpha - t.slide_pos) + ')';
		t.elem2.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + t.slide_pos + ')';
		t.elem2.style.filter = 'alpha(opacity=' + t.slide_pos + ')';
		t.elem1.style.opacity = (t.max_alpha - t.slide_pos) / 100;
		t.elem2.style.opacity = t.slide_pos / 100;
	}
}


function img_explode() {
	var t = this;
	t.slide_pos += t.step_x * 2;	
	
	if (t.slide_pos > t.width - t.step_x * 2) {
		clearInterval(t.idInterval);
		t.img1.src = t.img2.src;
		t.img2.style.height = 0;
		t.img2.style.width = 0;
		t.elem2.style.top = t.img2_top_pos;
		t.elem2.style.left = t.img2_left_pos;
		t.slide_pos = 0;		
	}
	else {
		t.img2.style.height = parseInt(t.img2.style.height) + t.step_y * 2 + "px";
		t.img2.style.width = parseInt(t.img2.style.width) + t.step_x * 2 + "px";
		t.elem2.style.top = parseInt(t.elem2.style.top) - t.step_y + "px";
		t.elem2.style.left = parseInt(t.elem2.style.left) - t.step_x + "px";
	} 
} 

function img_strip_v() {
	var t = this;
	t.slide_pos += t.step;		
	
	if (t.slide_pos > t.strip_w) {
		clearInterval(t.idInterval);
		t.img1.src = t.img2.src;		
		for (i = 0; i < t.n_strip; i++) {
			t.el_strip[i].style.clip = "rect(0, 0, 0, 0)"; 
		}			
		t.slide_pos = 0;		
	}
	else {
		for (i = 0; i < t.n_strip; i++) {
			t.el_strip[i].style.clip = "rect(0px, " + (t.strip_w * i + t.slide_pos) + "px," + t.height + "px," + (t.strip_w * i) + "px )"; 
		}	
	}	
}


function img_strip_h() {
	var t = this;
	t.slide_pos += t.step;		
	
	if (t.slide_pos > t.strip_h) {
		clearInterval(t.idInterval);
		t.img1.src = t.img2.src;		
		for (i = 0; i < t.n_strip; i++) {
			t.el_strip[i].style.clip = "rect(0, 0, 0, 0)"; 
		}			
		t.slide_pos = 0;		
	}
	else {
		for (i = 0; i < t.n_strip; i++) {
			t.el_strip[i].style.clip = "rect(" + t.strip_h * i + "px, " + t.width + "px," + (t.strip_h * i + t.slide_pos) + "px, 0)"; 
		}	
	}	
}


function setBorder(px, style, color) {
	this.prt.style.borderWidth = px +"px" || 0;
	this.prt.style.borderStyle = style || "solid"
	this.prt.style.borderColor = color || "#fff";	
}

function setMaxAlpha(alpha) {	
	if (alpha < 0) this.max_alpha = 0;
	else if (alpha > 100) this.max_alpha = 100;
	else this.max_alpha = alpha;
}

function setDelay(delay) {	
	this.delay = delay < Banner.rate + 1500 ? Banner.rate + 1500 : delay;
}

function setStep(step) {
	this.STEP = step;
}

function Banner(w, h, x, y, b_n, l_b, click){
	var t = this;
	t.id = Banner.Instances.length;
  	Banner.Instances[t.id] = t;
	Banner.rate = 70 + t.id * 5;
	t.delay = Banner.rate < 8000 ? 8000 : Banner.rate;
	t.width = w;
	t.height = h;
	t.x = x;
	t.y = y;		
	t.slide_pos = 0;
	t.img1_left_pos = 0;
	t.img1_top_pos = 0;	
	t.img2_left_pos = 0;
	t.img2_top_pos = 0;	
	t.banner_name = b_n;	
	t.lst_banner = l_b;	
	t.fst_banner = Math.floor(Math.random() * t.lst_banner + 1);
	t.click = click || false;
	
	t.idInterval = null;	
	
	t.max_alpha = 70;
	t.fx = "move_right";	
	
	var prt = document.createElement("div");	
	document.getElementById('pagina').appendChild(prt);
	prt.id = t.banner_name + "_" + (t.id + 1);
	var el1 = document.createElement("div");	
	el1.id = t.banner_name + "_img_1";
	var img1 =  document.createElement("img");
	el1.appendChild(img1);
	prt.appendChild(el1);
	var el2 = document.createElement("div");	
	el2.id = t.banner_name + "_img_2";
	var img2 =  document.createElement("img");
	el2.appendChild(img2);
	prt.appendChild(el2);	
	
	
	t.elem1 = el1;
	t.elem2 = el2;
	t.img1 = img1;
	t.img2 = img2;
	t.prt = prt;
	
	
}

	Banner.Instances = new Array();
	
//***** METHODS *****		
	Banner.prototype.start_slide = start_slide;
	Banner.prototype.img_change = img_change;
// Effects	
	Banner.prototype.img_slide_h = img_slide_h;
	Banner.prototype.img_slide_v = img_slide_v;
	Banner.prototype.img_fade = img_fade;
	Banner.prototype.img_roll_x = img_roll_x;
	Banner.prototype.img_roll_y = img_roll_y;
	Banner.prototype.img_explode = img_explode;
	Banner.prototype.img_strip_h = img_strip_h;
	Banner.prototype.img_strip_v = img_strip_v;
// Set parameters
	Banner.prototype.setMaxAlpha = setMaxAlpha;
	Banner.prototype.setBorder = setBorder;
	Banner.prototype.setDelay = setDelay;
	Banner.prototype.setStep = setStep;
