var ObjArray = new Array();
Aimg		=	new Image(270,130);
Aimg.src	=	"/im/ads/DKVPTUh5PZRw.jpg";
Atitle		=	"Відчуйте справжній відпочинок!";
Alink		=	"http://rixos.com.ua/ukr/corporate-information/offers.bhtml?article=162";
ObjArray[0]		=	new Array(Aimg, Atitle, Alink);
Aimg		=	new Image(270,130);
Aimg.src	=	"/im/ads/dgXYfcjTiqbJ.jpg";
Atitle		=	"Вихідні в РІКСОСІ";
Alink		=	"/ukr/corporate-information/offers.bhtml?article=117";
ObjArray[1]		=	new Array(Aimg, Atitle, Alink);
Aimg		=	new Image(270,130);
Aimg.src	=	"/im/ads/RXr9n05E6hAi.jpg";
Atitle		=	"\"Медовий тиждень\" у \"Ріксосі\"";
Alink		=	"http://rixos.com.ua/ukr/corporate-information/offers.bhtml?article=147";
ObjArray[2]		=	new Array(Aimg, Atitle, Alink);
Aimg		=	new Image(270,130);
Aimg.src	=	"/im/ads/MAB85vUCCC5m.jpg";
Atitle		=	"Подаруйте щастя";
Alink		=	"/ukr/corporate-information/offers.bhtml?article=120";
ObjArray[3]		=	new Array(Aimg, Atitle, Alink);

var ad			=0;
var adopacity	=0;
var ind			=1;
var frame_num	=0;
var imageID		='adImg';
var pagerID		='adpager';
var adstep		=20;
var adduration	=30;
var adstilltime	=5000;
var condition	='';
var stopMovie	=0;


function runAds(anchorID,pagerID){
	var aObj = 	document.getElementById(anchorID);
	aObj.innerHTML = "<img src='' id="+imageID+">";


	if (ObjArray.length == 1) {
		  transAd(anchorID, pagerID, ObjArray[0][0], ObjArray[0][1], ObjArray[0][2], 1);
	} else {
		var imgObj		=	document.getElementById(imageID);
		var pagerObj	=	document.getElementById(pagerID);
		pagerObj.innerHTML = buildPages(ObjArray.length);

		window.frameRunner= function() {runSlide(anchorID,pagerID,ObjArray,imgObj,aObj);}
		runSlide(anchorID,pagerID,ObjArray,imgObj,aObj);
	}
	
}


function transAd (aID, pID, Img, Txt, Lnk, direction){

	var aObj = 		document.getElementById(aID);
	var imgObj =	document.getElementById(imageID);
	window.addRunner= function() {changeOpacity(imgObj,direction);}
	if (!direction)
	{  
		imgObj.className = 'opaque';
		adopacity=100;
		if (eval(isdefined("downAd")))
		{
			clearTimeout(downAd);
		}
	} else {
		adopacity=0;
		imgObj.className = 'transparent';
		if (eval(isdefined("upAd")))
		{
			clearTimeout(upAd);
		}
	}

	imgObj.src	= Img.src;
	changeOpacity	(imgObj,direction);
	changeAnchor	(aObj,Txt,Lnk)
}



function changeOpacity (OP,direction){
	if (direction)
	{	
		if (adopacity < 100)
		{
			if (OP.filters)
			{ 
				OP.filters[0].opacity= adopacity+adstep;
			} else {
				OP.style.opacity =  (adopacity+adstep)/100;
				OP.style.MozOpacity =  (adopacity+adstep)/100;
			}
			adopacity+=adstep;
			downAd=setTimeout("addRunner()",adduration);
		} else {
			clearTimeout(downAd);
		}
			/*window.alert(adopacity); */
	} else {
		if (adopacity > 0)
		{
			if (OP.filters)
			{ 
				OP.filters[0].opacity= adopacity-adstep;
			} else {
				OP.style.opacity =  (adopacity-adstep)/100;
				OP.style.MozOpacity =  (adopacity-adstep)/100;
			}
			adopacity-=adstep;
			upAd=setTimeout("addRunner()",adduration);
		}   else {
			clearTimeout(upAd);
		}
	}
}



function changeAnchor(aObj,title,link){

	aObj.href	=		link;
	aObj.title	=		title;
	
}


function runSlide(aID, pID, wholeMovie, imgObj, aObj){
	adopacity=0;
	condition = 'fadeup';	
	if (frame_num>=wholeMovie.length) frame_num=0;
	changeAnchor(aObj,wholeMovie[frame_num][1],wholeMovie[frame_num][2]);
	changePagerState(frame_num,pagerID,wholeMovie.length);
	
	imgObj.className = 'transparent';
	imgObj.src = wholeMovie[frame_num][0].src; 

	window.frm= function() {runFrame(imgObj);}
	runFrame(imgObj);
}


function runFrame(OP){
	if (condition == 'fadeup'){
		if (adopacity < 100)
		{
			if (OP.filters)
			{ 
				OP.filters[0].opacity= adopacity+adstep;
			} else {
				OP.style.opacity =  (adopacity+adstep)/100;
				OP.style.MozOpacity =  (adopacity+adstep)/100;
			}
			adopacity+=adstep;
			
		} else {
			condition = 'still';
		}	
		frameTimer=setTimeout("frm()",adduration); 
		

	} else if (condition == 'still') {
		clearTimeout(frameTimer);
		condition = 'fadedown';
		if (!stopMovie) {
			condition = 'fadedown';
			frameTimer=setTimeout("frm()",adstilltime);
		}
	} else if (condition == 'fadedown') {
		if (adopacity > 0)
		{
			if (OP.filters)
			{ 
				OP.filters[0].opacity= adopacity-adstep;
			} else {
				OP.style.opacity =  (adopacity-adstep)/100;
				OP.style.MozOpacity =  (adopacity-adstep)/100;
			}
			adopacity-=adstep;
		}   else {
			condition = 'no';
		}

		frameTimer=setTimeout("frm()",adduration);

	} else if (condition == 'no'){
		clearTimeout(frameTimer);
		frame_num++;
		frameRunner();
	}

}



function changePagerState(frame_number,pagerid,qty){
	var class_a='pinact'
	for (var i=0; i<qty; i++){
		pageObj = document.getElementById(pagerid+"_"+i);
		class_a=(frame_number == i) ? 'pact' : 'pinact';
		pageObj.className = class_a;
		
	}
}

function buildPages(qty){
	var buff='';
	for (var i=0; i<qty; i++){
		buff+='<a href="" onClick="return jumpToFrame('+i+')" id="'+pagerID+'_'+i+'">'+(i+1)+'</a>';
	}
	return buff;
}


function  jumpToFrame(frameNo){

	if (isdefined(frameTimer)){
		clearTimeout(frameTimer);
	}
	stopMovie=1;
	frame_num=frameNo;
	frameRunner();
	return false;
}