

function CNN_changeImg(which,flag) {
	switch(which) {
		case "cnnImgChngrNxtBtn":
			switch (flag) {
				case 1:
					document.getElementById(which).src = "http://vps.wsmdusa.net/macandrewsandforbes/images/next_over.gif"
				break;
				default:
					document.getElementById(which).src = "http://vps.wsmdusa.net/macandrewsandforbes/images/next.gif"				
			}
		
		break;
		case "cnnImgChngrPrvsBtn":
			switch (flag) {
				case 1:
					document.getElementById(which).src = "http://vps.wsmdusa.net/macandrewsandforbes/images/prev_over.gif"
				break;
				default:
					document.getElementById(which).src = "http://vps.wsmdusa.net/macandrewsandforbes/images/prev.gif"				
			}		
		break;
		
		default:
	}
}


function CNN_imageChanger(id, url,numSlides,chngrPos) {
	this.id = id;
	this.url = url;
	this.chngrPos = chngrPos;
	this.numSlides = numSlides;
	this.currentSlidePos = 0;
	this.disabledNxtBtn = 'http://vps.wsmdusa.net/macandrewsandforbes/images/right_gray_btn.gif';
	this.enabledNxtBtn = 'http://vps.wsmdusa.net/macandrewsandforbes/images/next.gif';
	this.disabledPrvsBtn = 'http://vps.wsmdusa.net/macandrewsandforbes/images/left_gray_btn.gif';
	this.enabledPrvsBtn = 'http://vps.wsmdusa.net/macandrewsandforbes/images/prev.gif';
	this.nxtLnkNode;
	this.prvsLnkNode;
	this.nxtLnkActive = true;
	this.prvLnkActive = false;
	
	this.CNN_navChngInitLoad();
}

function CNN_navChngInitLoad() { //make initial http request

	var totalImg = this.numSlides + 1;
	var currentImg = this.currentSlidePos + 1;
	
			new Ajax.Updater({success: this.id}, this.url,
			{
				onComplete:function(obj) {
					$('cnnImgChngrLbl').innerHTML = currentImg + " of " + totalImg;
					CNN_ArticleChanger.CNN_navDisablePrvsBtn();
				},
				method:'get',
				evalScripts:true,
				asynchronous:true
				})
}
CNN_imageChanger.prototype.CNN_navChngInitLoad = CNN_navChngInitLoad;

function CNN_navChngFrwd() {
	if (this.currentSlidePos < this.numSlides) {
		this.currentSlidePos++;
	} else {
		this.currentSlidePos = 0;
	}
	this.url = 'imgChng/p'+this.chngrPos+'-'+this.currentSlidePos+'.exclude.html';
	this.CNN_navChngManage();
}
CNN_imageChanger.prototype.CNN_navChngFrwd = CNN_navChngFrwd;

function CNN_navChngBack() { //update pos, update url

	if (this.currentSlidePos > 0) {
		this.currentSlidePos--;
	} else {
		this.currentSlidePos = this.numSlides;
	}
	this.url = 'imgChng/p'+this.chngrPos+'-'+this.currentSlidePos+'.exclude.html';
	this.CNN_navChngManage();
}
CNN_imageChanger.prototype.CNN_navChngBack = CNN_navChngBack;

function CNN_navChngManage() { //make http request
	var url = this.url;
	var id = 'cnnImgChngrNested';
	var totalImg = this.numSlides + 1;
	var currentImg = this.currentSlidePos + 1;
	
	if(this.currentSlidePos == this.numSlides && this.nxtLnkActive) {
		this.CNN_navDisableNextBtn();
	} else {
		if (!this.nxtLnkActive) {
			this.CNN_navEnableNextBtn();
		}
	}
	
	if (this.currentSlidePos == 0) {
		this.CNN_navDisablePrvsBtn();
	} else {
		if (!this.prvsLnkActive) {
			this.CNN_navEnablePrvsBtn();
		}	
	}
	
new Effect.Opacity(id,
{
	duration:.5,
	from:1.0,
	to:0,

	afterFinish: function() {
		new Ajax.Updater({success: id}, url,
		{
			onComplete:function() {
						$('cnnImgChngrLbl').innerHTML = currentImg + " of " + totalImg;
			},
			method:'get',
			evalScripts:true,
			asynchronous:true
		})	
	}
})

}
CNN_imageChanger.prototype.CNN_navChngManage = CNN_navChngManage;

function CNN_navEnableNextBtn() {
var enabledBtn = this.enabledNxtBtn;
this.nxtLnkNode = $('cnnImgChngrNxtLbl').getElementsByTagName('a')[0];

	$('cnnImgChngrNxtBtn').src = enabledBtn;
	this.nxtLnkNode.onmouseout = function() {CNN_changeImg('cnnImgChngrNxtBtn')};
	this.nxtLnkNode.onmouseover = function() {CNN_changeImg('cnnImgChngrNxtBtn',1)};
	this.nxtLnkNode.style.cursor = 'pointer';
	this.nxtLnkNode.onclick = function() { CNN_ArticleChanger.CNN_navChngFrwd(); return false;};
	this.nxtLnkActive = true;
}
CNN_imageChanger.prototype.CNN_navEnableNextBtn = CNN_navEnableNextBtn;


function CNN_navDisableNextBtn() {
var disabledBtn = this.disabledNxtBtn;
this.nxtLnkNode = $('cnnImgChngrNxtLbl').getElementsByTagName('a')[0];

	$('cnnImgChngrNxtBtn').src = disabledBtn;
	this.nxtLnkNode.onmouseout = function() {$('cnnImgChngrNxtBtn').src = disabledBtn};
	this.nxtLnkNode.onmouseover = function() {};
	this.nxtLnkNode.style.cursor = 'default';
	this.nxtLnkNode.onclick = function() { return false;};
	this.nxtLnkActive = false;
}
CNN_imageChanger.prototype.CNN_navDisableNextBtn = CNN_navDisableNextBtn;

function CNN_navEnablePrvsBtn() {
var enabledBtn = this.enabledPrvsBtn;
this.prvsLnkNode = $('cnnImgChngrPrvsLbl').getElementsByTagName('a')[0];

	$('cnnImgChngrPrvsBtn').src = enabledBtn;
	this.prvsLnkNode.onmouseout = function() {CNN_changeImg('cnnImgChngrPrvsBtn')};
	this.prvsLnkNode.onmouseover = function() {CNN_changeImg('cnnImgChngrPrvsBtn',1)};
	this.prvsLnkNode.style.cursor = 'pointer';
	this.prvsLnkNode.onclick = function() { CNN_ArticleChanger.CNN_navChngBack(); return false;};
	this.prvsLnkActive = true;
}
CNN_imageChanger.prototype.CNN_navEnablePrvsBtn = CNN_navEnablePrvsBtn;


function CNN_navDisablePrvsBtn() {
var disabledBtn = this.disabledPrvsBtn;
this.prvsLnkNode = $('cnnImgChngrPrvsLbl').getElementsByTagName('a')[0];

	$('cnnImgChngrPrvsBtn').src = disabledBtn;
	this.prvsLnkNode.onmouseout = function() {$('cnnImgChngrPrvsBtn').src = disabledBtn};
	this.prvsLnkNode.onmouseover = function() {};
	this.prvsLnkNode.style.cursor = 'default';
	this.prvsLnkNode.onclick = function() { return false;};
	this.prvsLnkActive = false;
}
CNN_imageChanger.prototype.CNN_navDisablePrvsBtn = CNN_navDisablePrvsBtn;

function CNN_loadImg(id) {
new Effect.Opacity(id,
				{
					duration:.5,
					from:0,
					to:1.0
				});
}
 



