function addListener(element, type, expression, bubbling)
{
	bubbling = bubbling || false;
	if(window.addEventListener) { // Standard
	element.addEventListener(type, expression, bubbling);
	return true;
	} else if(window.attachEvent) { // IE
	element.attachEvent('on' + type, expression);
	return true;
	} 
	else 
	return false;
}
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function getXpromo(){
	var request = GetXmlHttpObject();
	if(request){
		request.onreadystatechange = function(){
			displayResponse(request);
			};
		url="/cp.adp?mod1="+moduleInstId+"|xpromoHeader&debug=0";
			
		request.open("GET", url, true);
		request.send(null);
	}
}

//DP implementation

function getXpromo_DB(spurl){
	var request = GetXmlHttpObject();
	if(request){
		request.onreadystatechange = function(){
			displayResponse(request);
			};
		url=cpurl;
			
		request.open("GET", url, true);
		request.send(null);
	}
}

function displayResponse(request){

	if(request.readyState == 4){

	    var element = document.getElementById("xpromoContnr");

	   	element.innerHTML = request.responseText;
		so_init();
	   	

	} 

}
var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;var timer;
var flg= 0;
var flgKe=0;
var cnt=0;
function so_init()
{
	if(!d.getElementById || !d.createElement)return;
	imgs = d.getElementById('rotator').getElementsByTagName('li');
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = 'block';
	imgs[0].xOpacity = .99;
	timer=setTimeout(callSofade,4000);
	function callSofade(){
		so_xfade("right");
	}
	cnt = d.getElementById('rotator').getElementsByTagName("a").length;
}

function so_xfade(direction)
{
	cOpacity = imgs[current].xOpacity;
	if (direction == "right"){
		nIndex = imgs[current+1]?current+1:0;
	}
	else{
		nIndex = current==0?imgs.length-1:current-1;
	}
	nOpacity = imgs[nIndex].xOpacity;
	cOpacity-=.05;
	nOpacity+=.05;
	imgs[nIndex].style.display = 'block';
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);
	function callSofade(){
		so_xfade(direction);
	}
	
	if(cOpacity<=0)
	{
		imgs[current].style.display = 'none';
		current = nIndex;
		if(flg==0) {
			timer=setTimeout(callSofade,4000);
		}
		else{
			clearTimeout(timer);
			timer=0;		
		}
	}
	else
	{
		timer=setTimeout(callSofade,20);
	}
	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}

function so_xfadeClk(direction)
{
	cOpacity = 1;
	if (direction == "right"){
		nIndex = imgs[current+1]?current+1:0;
	}
	else{
		nIndex = current==0?imgs.length-1:current-1;
	}
	nOpacity = imgs[nIndex].xOpacity;
	if(cOpacity==1)
		cOpacity=.99;
	cOpacity-=1;
	nOpacity+=1;
	imgs[nIndex].style.display = 'block';
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);
	function callSofade(){
		so_xfade(direction);
	}
	if(cOpacity<=0)
	{
		imgs[current].style.display = 'none';
		current = nIndex;
		if(flgKe==0) {
			timer=setTimeout(callSofade,4000);
		}
		else {
			clearTimeout(timer);
			timer=0;
		}
	}
	else
	{
		timer=setTimeout(callSofade,20);
	}
	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}

function calldirection(dir)
{	
	if((imgs[current].style.opacity)<.90 && (imgs[current].style.opacity)!="") {
		flgKe=0;
	}
	else {
		flgKe=1;
		so_xfadeClk(dir);
	}	
}
function mouseover()
{
	flg=1;
	for(var i=0;i<cnt;i++){
		d.getElementById('rotator').getElementsByTagName("a")[i].className="undrLine";
	}
	if((imgs[current].xOpacity>.90)){
		clearTimeout(timer);
		timer=0;
	}
}

function xpromoStart(){
	for(var i=0;i<cnt;i++){
		d.getElementById('rotator').getElementsByTagName("a")[i].className="";
	}
	flg= 0;
	flgKe= 0;
	clearTimeout(timer);
	timer=0;
	timer=setTimeout(callSofade,1000);
	function callSofade(){
		so_xfade("right");
	}
}
function overBtn()
{
	flg=1;
	if((imgs[current].xOpacity>.90)){
		clearTimeout(timer);
		timer=0;
	}
}
