// JavaScript Document

var imgRoll = {
	
	// Image Roll Unit Definitions
	imagePacks : {
		'web_design643x291' : [ 
			{ src : 'images/provenpixel_portfolio.jpg', tip : 'ProvenPixel.com' , url : 'http://www.provenpixel.com' }, 
			{ src : 'images/theshoppingbrowser_portfolio.jpg', tip : 'TheShoppingBrowser.co.uk' , url : 'http://www.theshoppingbrowser.co.uk' }, 
			{ src : 'images/citeeze_sk.jpg', tip: 'Citeeze.com', url : 'http://www.citeeze.com'},
			{ src : 'images/VirtualAisle_portfolio.jpg', tip : 'VirtualAisle.com' , url : 'http://www.virtualaisle.com' },
			{ src : 'images/vibers_sk.jpg', tip : 'Vibers.to' , url : 'http://www.vibers.to' }
		],
		'web_design291x243' : [
			{ src : 'images/wd_350_citeeze4.jpg', tip : 'Citeeze.com' , url : 'http://www.citeeze.com' }, 
			{ src : 'images/wd_350_citeeze5.jpg', tip : 'Citeeze.com' , url : 'http://www.citeeze.com' }, 
			{ src : 'images/wd_350_vibers4.jpg', tip : 'Vibers.to' , url : 'http://www.vibers.to' }, 
			{ src : 'images/wd_350_vibers5.jpg', tip : 'Vibers.to' , url : 'http://www.vibers.to' }, 
			{ src : 'images/wd_350_vibers6.jpg', tip : 'Vibers.to' , url : 'http://www.vibers.to' }, 
			{ src : 'images/wd_350_vibers7.jpg', tip : 'Vibers.to' , url : 'http://www.vibers.to' },
			{ src : 'images/Citeeze_350_portfolio.jpg', tip : 'Citeeze.com' , url : 'http://www.citeeze.com' },
			{ src : 'images/Carnivalbanner_portfolio.jpg', tip : 'Carnival' , url : '' }, 
			{ src : 'images/CheapTickets_portfolio.jpg', tip : 'CheapTickets.com' , url : '' }
		],
		'web_design639x79' : [ 
			{ src : 'images/wd_728_vibers1.jpg', tip : 'Vibers.to' , url : 'http://www.vibers.to' }, 
			{ src : 'images/wd_728_vibers2.jpg', tip : 'Vibers.to' , url : 'http://www.vibers.to' }, 
			{ src : 'images/wd_728_vibers3.jpg', tip : 'Vibers.to' , url : 'http://www.vibers.to' }, 
			{ src : 'images/wd_728_citeeze1.jpg', tip : 'Citeeze.com' , url : 'http://www.citeeze.com' }, 
			{ src : 'images/wd_728_citeeze2.jpg', tip : 'Citeeze.com' , url : 'http://www.citeeze.com' }, 
			{ src : 'images/wd_728_citeeze3.jpg', tip : 'Citeeze.com' , url : 'http://www.citeeze.com' }, 
			{ src : 'images/Citeeze_728_portfolio.jpg', tip : 'Citeeze.com' , url : 'http://www.citeeze.com' }, 
			{ src : 'images/Carnival_banner_728_portfolio.jpg', tip : 'Carnival' , url : '' }, 
			{ src : 'images/CheapTickets_728_portfolio.jpg', tip : 'CheapTickets.com' , url : '' }
		]
	},
	
	rollCurrIndex : {},
	
	centerArrow : function (blockId, arrow){
		block = document.getElementById(blockId);
		arrow.style.top = ((block.offsetHeight - arrow.height) / 2) + 'px';
	},
		
	// Object Centering Function
	centerImage : function (blockId, arrowId, imageId){
		// !!!! Function implementation not yet completed !!!
		block = document.getElementById(blockId);
		image = document.getElementById(imageId);
		image.style.left = (block.offsetWidth - image.width) / 2;
		image.style.top = (block.offsetHeight - image.height) / 2;
	},

	// Swap Image Function
	// Hide Arrows if at the top end of the Image Roll - or keep both fulltime and scroll from last to first.	
	imgRollSwap : function(imgId, unitId, scrollDirection){
		var img = document.getElementById(imgId);
		var index;
		if (!this.rollCurrIndex[unitId]){
			index = 0;
		}
		else {
			index = this.rollCurrIndex[unitId];
		}
				
		if (scrollDirection == 'ahead') index += 1;
		else index -= 1;
				
		if (index >= this.imagePacks[unitId].length) index = 0
		if (index < 0) index = this.imagePacks[unitId].length - 1;
		this.rollCurrIndex[unitId] = index;
		img.src = this.imagePacks[unitId][index].src;
		img.setAttribute(title, this.imagePacks[unitId][index].tip);
		
	},
	populateImgLink : function (aElementId, unitId){
		var aTag = document.getElementById(aElementId);

		var index;
		if (!this.rollCurrIndex[unitId]){
			index = 0;
		}
		else {
			index = this.rollCurrIndex[unitId];
		}

		if (!this.imagePacks[unitId][index].tip) return;
		aTag.href = this.imagePacks[unitId][index].url;
		aTag.title = this.imagePacks[unitId][index].tip;
		aTag.target = 'blank';
	},
	populateTextLink : function (aElementId, unitId){
		try {
			var aTag = document.getElementById(aElementId);
		}
		catch(e) {
			return;	
		}
		var index;
		if (!this.rollCurrIndex[unitId]){
			index = 0;
		}
		else {
			index = this.rollCurrIndex[unitId];
		}

		if (!this.imagePacks[unitId][index].tip) return;
		aTag.innerHTML = this.imagePacks[unitId][index].tip;
		aTag.title = this.imagePacks[unitId][index].tip;
		aTag.href = this.imagePacks[unitId][index].url;
		aTag.target = 'blank';
	}

}

