/************************************************************
	Custom Mootools Extensions
************************************************************/
Element.implement({
	getPadding: function (selector) {
		var me,L=0,R=0,T=0,B=0,LR=0,TB=0,Total=0;
		switch (selector) {
			case undefined: me = this; break;
			case "parent": me = this.getParent(); break;
			default: try { 
				if($chk(this.getParent(selector))) { 
					me = this.getParent(selector);
				} else { throw new Error("getPadding(" + selector + ") failed. Parent element was not found."); }
			} catch (error) { Console.error("Error",error); }
		}
		L += parseInt(me.getStyle("paddingLeft").match(/\d+/)[0]);
		R += parseInt(me.getStyle("paddingRight").match(/\d+/)[0]);
		LR += (L + R);
		T += parseInt(me.getStyle("paddingTop").match(/\d+/)[0]);
		B += parseInt(me.getStyle("paddingBottom").match(/\d+/)[0]);
		TB += (T + B);
		Total += (LR + TB);
		return {top:T,left:L,bottom:B,right:R,horizontal:LR,vertical:TB,total:Total};
	},
	getBorder: function (selector) {
		var me,L=0,R=0,T=0,B=0,LR=0,TB=0,Total=0;
		switch (selector) {
			case undefined: me = this; break;
			case "parent": me = this.getParent(); break;
			default: try { 
				if($chk(this.getParent(selector))) { 
					me = this.getParent(selector);
				} else { throw new Error("getBorder(" + selector + ") failed. Parent element was not found."); }
			} catch (error) { Console.error("Error",error); }
		}
		L += parseInt(me.getStyle("borderLeft").match(/\d+/)[0]);
		R += parseInt(me.getStyle("borderRight").match(/\d+/)[0]);
		LR += (L + R);
		T += parseInt(me.getStyle("borderTop").match(/\d+/)[0]);
		B += parseInt(me.getStyle("borderBottom").match(/\d+/)[0]);
		TB += (T + B);
		Total += (LR + TB);
		return {top:T,left:L,bottom:B,right:R,horizontal:LR,vertical:TB,total:Total};
	},
    getColWidth: function (selector) {
        var containerWidth = this.getStyle("width").toInt();
        var containerPadding = this.getPadding().horizontal;
        try {
            var columns = $$(selector);
            if (columns.length < 1) {
                throw new Error("getColWidth(" + selector + ") failed. Number of columns found = " + columns.length + ".");
            }
        } catch (error) {
            Console.error("Error", error);
            return;
        }
        var numCols = columns.length;
		var columnPadding = columns[0].getPadding().horizontal + columns[0].getBorder().horizontal;
        if (!columnPadding) { columnPadding = 0; } 
		if (!containerPadding) { containerPadding = 0; }
        var finalColumnWidth = ((containerWidth - containerPadding) - (columnPadding * numCols)) / numCols;
        var leftOverPixels = Math.round(finalColumnWidth % Math.round(finalColumnWidth) * numCols);
		return {width: Math.round(finalColumnWidth), padding: columnPadding, parentPadding: containerPadding, remainder:leftOverPixels };
    },
    addLiveEvent: function (selector, event, func) {
        this.addEvent(event, function (e) {
            var target = $(e.target);
            if (/\s/.test(selector)) {
                $$(selector).each(function (el) {
                    try {
                        if (target.match(el)) {
							func.apply(target, [e]);
                        }
                    } catch (e) {}
				});
			}
            else {
                if (target.match(selector)) {
					func.apply(target, [e]);
                }
            }
        }.bindWithEvent(this, selector, func));
    },
    addLiveEvents: function (selector, events) {
        for (var type in events) {
			this.addLiveEvent(selector, type, events[type]);
        }
		return this;
    }
});

/************************************************************
	Global Variables set during Browser Detection
************************************************************/
//Utitily
var isIE = false; var isIE6 = false; var isIE7 = false; var isIE8 = false; var ieVersion = 0;
var isFF = false; var FFVersion = 0;
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	isIE = true;
	ieVersion = new Number(RegExp.$1); // capture x.x portion and store as a number
	if (ieVersion>=8 && ieVersion<9) { isIE8 = true; }
	else if (ieVersion>=7 && ieVersion<8) { isIE7 = true; }
	else if (ieVersion>=6 && ieVersion<7) { isIE6 = true; }
}
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
	isFF = true;
	FFVersion = new Number(RegExp.$1); // capture x.x portion and store as a number
}

/************************************************************
	Adds functions to a list that fire on the window.onload event
************************************************************/
function addLoadEvent(func) { //Utitily
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/************************************************************
	Similar functionality exists in the mootools library.
************************************************************/
function getElementsByClass(searchClass,node,tag) { //Utitily
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function expand(divIdClosed, divIdExpanded) { //Utility
	document.getElementById(divIdExpanded).style.display = 'block';
	document.getElementById(divIdClosed).style.display = 'none';
}

function collapse(divIdClosed, divIdExpanded) { //Utility
	document.getElementById(divIdExpanded).style.display = 'none';
	document.getElementById(divIdClosed).style.display = 'block';
}

/*******************************************************************************
	parseURL:
	Function parses URL and returns object of params and values
	example:
	http://mydomain.com/mypath/myfile.jsp?size=large&color=blue
	var get=parseURL();
	get.size will return 'large', get.color will return 'blue'
*******************************************************************************/
function parseURL(){ //Utility
	url=location.href;
	url=url.substr(url.indexOf('?')+1);
	params=url.split('&');
	obj=[];
	for(i in params){
		if(typeof(params[i])=='string'){
			param=params[i].split('=');
			obj[param[0]]=param[1];
		}
	}
	return obj;
}

/*******************************************************************************
Scroller: 
Controller for scrolling slide show
*******************************************************************************/
var browserHasFlash = true;
function checkForFlash() { //Utility
	var playerVersion = swfobject.getFlashPlayerVersion();
	if(!(playerVersion.major + playerVersion.minor  + playerVersion.release)){
		browserHasFlash = false;
	}
}
//swfobject.addDomLoadEvent(checkForFlash);

/*******************************************************************************
centerOnPage: 
func will center passed in object on page
*******************************************************************************/
function centerOnPage(obj) { //Utility
	var t = (window.getSize().y - $(obj).getSize().y)/2;
	var l = (window.getSize().x - $(obj).getSize().x)/2;
	t = t<10 ? 10 : t;
	l = l<10 ? 10 : l;
	$(obj).setStyles({
		left:l,
		top:t
	});
}

/*******************************************************************************
Accessibility Class: Used to return the focus to the appropriate item after an AJAX rewrites DOM.
*******************************************************************************/
var setFocus = { //Utiltiy
	/* selector: [String] */
	self:function(selector) {
		try {
			$(selector).focus();
		} catch(e) {
			$$(selector)[0].focus();
		}
	},
	parent:function(selector, parentSelector) {
		if(parentSelector) {
			try {
				$(selector).getParents(parentSelector)[0].focus();
			} catch(e) {
				$$(selector)[0].getParents(parentSelector)[0].focus();
			}
		}
		else {
			try {
				$(selector).getParent().focus();
			} catch(e) {
				$$(selector)[0].getParent().focus();
			}
		}
	}
}

/*******************************************************************************
Global Logging Class: Uses Firefox Console. Only works in Firefox. Doesn't cause errors in other browsers.
*******************************************************************************/
var Console = { //Utility
	counter:0,
	isError:false,
	tab:'',
	isProd:function(){ return window.location.host.test('verizonwireless.com'); },
	log:function(varName, text, clearMe) {
		/*
			varName [String] = label of what you're logging (optional)
			text [String,Number,Boolean,Array or Object] = Value you'd like logged (can be first or second paramter)
			clearMe [Boolean] = do you want to clear the console prior to logging (optional)
		*/
		if(!this.isProd() && isFF) {
			if(clearMe){ try{console.clear();}catch(e){} }
			switch (text) {
				case undefined: text = varName; varName = "Log"; break;
				default: //do nothing
			}
			/*var text = (typeof text == 'undefined') ? varName : text;
			var varName = (typeof text == 'undefined') ? 'Variable' : varName;*/
			return this.check(varName,text);
		} else {
			return false;
		}
	},
	error:function(varName, text, clearMe) {
		this.isError = true;
		this.log(varName, text, clearMe);
		this.isError = false;
	},
	check:function(name, value) {
		try {
			switch(true) {
				case (value instanceof Array):		this.output(name, value); this.tabber(true); this.aLoop(name, value); this.tabber(false); break;
				case (value instanceof String):		
				case (value instanceof Date):		
				case (value instanceof Number):		
				case (value instanceof Boolean):	
				case (value instanceof Function):	this.output(name, value); break;
				case (value instanceof Object):		this.output(name, value); this.tabber(true); this.oLoop(name, value); this.tabber(false); break;
				default:							this.output(name, value);
			}
			return true;
		} catch(e) {
			return false;
		}
	},
	aLoop:function(aName, array){
		this.counter++;
		this.output('[Array]',String(aName));
		this.output('Length of ['+String(aName)+']',Number(array.length));
		for (j=0; j < array.length; j++) {
			this.check(j,array[j]);
		}
	},
	oLoop:function(oName, object){
		this.counter++;
		for (i in object) {
			this.check(i,object[i]);
		}
	},
	tabber:function(addTabs) {
		if(this.counter < 1) { return; }
		if(addTabs) {
			this.tab += '   ';
		} else {
			if (this.tab.length && this.tab.length >= 3) {
				this.tab = this.tab.substring(0,this.tab.length-3);
			} else {
				this.tab = '';
			}
		}
	},
	output:function(left,right) {
		right = (typeof right == null || typeof right == 'undefined') ? null : right;
		right = (typeof right == 'string') ? right.clean() : right;
		if(this.isError) {
			console.log(this.tab+'%c'+left + ': ' + right,'color:red;'); //DO NOT DELETE
		} else {
			console.log(this.tab+left + ': ' + right); //DO NOT DELETE
		}
	}
};

/************************************************************
	In IE6, takes PNG images and converts them to a span with that image as a background with a css filter
************************************************************/
function png_init() { //UI
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
	   for(var i=0; i<document.images.length; i++) {
		  var img = document.images[i];
		  var imgName = img.src.toUpperCase();
			if (!(/\bpng\b/.test(img.className)) && !(/\bpngOmit\b/.test(img.className)) && (imgName.substring(imgName.length-3, imgName.length) == "PNG")) {
			 var imgID = (img.id) ? "id='" + img.id + "' " : "";
			 var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			 var imgStyle = "display:inline-block" + img.style.cssText;
			 if (img.align == "left") { imgStyle = "float:left;" + imgStyle; }
			 if (img.align == "right") { imgStyle = "float:right;" + imgStyle; }
			 if (img.parentElement.href) { imgStyle = "cursor:hand;" + imgStyle; }
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle;
		 	 strNewHTML += " style=\"" + "width:" + $(img).getSize().x + "px; height:" + $(img).getSize().y + "px;" + imgStyle + ";";
			 strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader";
			 strNewHTML += "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
			 img.outerHTML = strNewHTML;
			 i = i-1;
		  }
	   }
	}
}
var tooltips_Init = function() { png_init(); }; //keeping the old naming for other teams.

/* --------------------------------------------------------------- 
//popup code
------------------------------------------------------------------- */
//set target to new window using XHTML 1.0 strict compatible attribute
function popupLinks() { //UI
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "popup")
		anchor.target = "_blank";
	}
}
addLoadEvent(popupLinks);

//set popup window options 
function popUp(strURL,strType,strHeight,strWidth) { //UI
	var strOptions="";
	if (strType=="flashPopup") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="popup") strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fullScreen") strOptions="scrollbars,location,directories,status,menubar,toolbar,resizable";
	window.open(strURL, 'newWin', strOptions);
}

/* --------------------------------------------------------------- 
//Buttons code
------------------------------------------------------------------- */
function setButtons() { //UI
	var buttons = document.getElementsByTagName('button');
	var buttonsLen = buttons.length;
	if (isIE) {
		for(var i=0; i<buttonsLen; i++) {
			if ((buttons[i].className == 'red') || (buttons[i].className == 'gray')) {
				buttons[i].style.width = (buttons[i].getElementsByTagName('span').item(0).offsetWidth+12 ) + 'px';
			}
			else {
				try{ //fix for object not found
				buttons[i].style.width = (buttons[i].getElementsByTagName('span').item(0).offsetWidth) + 'px';
			}
				catch(e){}
			}
		}
	}
	var inputs = document.getElementsByTagName('input');
	var inputsLen = inputs.length;
	for(i=0; i<inputsLen; i++) {
		if((inputs[i].type=='button') || (inputs[i].type=='submit') || (inputs[i].type=='reset')) {
			inputs[i].value=inputs[i].value.toUpperCase();
			var nspace=0;
			var l=inputs[i].value.length;
			var str=inputs[i].value;
			for(var j=0;j<l;j++) {
				if (str.charAt(j)==' ') {
					nspace++;
				}
			}
			if(window.webkit!=true) {
				inputs[i].style.width = ((inputs[i].value.length*0.73 )- (nspace* 0.31))+'em';
				inputs[i].style.width=(inputs[i].offsetWidth+12)+ 'px';
			}
		}
	}
}

/* --------------------------------------------------------------- 
	Global vars and functions to support scrolling of buttons
	on subnav button bar when there are more buttons than there
	is space for
------------------------------------------------------------------- */
var buttonListFirstList = true;
var buttonListNum = 1;
var buttonListUl;
var buttonListLi;
var buttonListCookie;
var buttonListId;
function scrollButtons(){ //UI
	if(buttonListFirstList){
		$('view_more').getFirst().className = "arrow_left";
		if(buttonListUl.getSize().y > 32){
			buttonListLi[buttonListNum].setStyle('display', 'none');
			buttonListNum++;
			setTimeout('scrollButtons()',100);
        }else{
			buttonListNum--;
			buttonListFirstList=false;
			buttonListCookie = Cookie.write(buttonListId, 0);
		}
	}else{
		$('view_more').getFirst().className = "arrow_right";
		if(buttonListLi[buttonListNum].getStyle('display') == 'none'){
			buttonListLi[buttonListNum].setStyle('display', 'block');
			buttonListNum--;
			setTimeout('scrollButtons()',100);
          	}else{
			buttonListFirstList=true;
			buttonListCookie = Cookie.write(buttonListId, 1);
			buttonListNum++;
		}
	}
}

/************************************************************
	scrollButtonsInit:
************************************************************/
function scrollButtonsInit(){ //UI
	buttonListUl = $('button_list');
	buttonListLi = $('button_list').getChildren('li');
	buttonListId = $('button_list').getParent().id;
	$('view_more').getFirst().className = "arrow_right";
	$('view_more').addEvent('click', scrollButtons);
	buttonListCookie = Cookie.read(buttonListId);
	if(buttonListCookie==0){
		buttonListFirstList = true;
    	scrollButtons();
    }else{
    	for(i=0;i<buttonListLi.length;i++){
			if(i==0){
				baseline = buttonListLi[i].getPosition().y;
			}
	          	if(buttonListLi[i].getPosition().y > baseline && buttonListLi[i].getFirst().className == 'active'){
				scrollButtons();
				break;
			}
		}
    }
}

/*******************************************************************************
	dropShade:
	Controller for pop-in divs that expand to display temporary info to user.
*******************************************************************************/
var dropShade={ //UI
	init:function(){
		$(document.body).getElements('a.launchDropShade').addEvent('click', function(){
			dropShade.drop(this);
		});
	},
	drop:function(base){
		var inc = 10;
		var dropShadeDiv = $('dropShadeDiv');
		if (!dropShadeDiv) {
			dropShadeDiv = document.createElement('div');
			dropShadeDiv.setAttribute('id', 'dropShadeDiv');
			dropShadeDiv.innerHTML='<div id="expando"><div id="top-left"></div><div id="top-right"></div><div id="dropShadeContent"></div></div><div class="relative"><div id="bot-left"></div><div id="bot-right"></div></div>';
			document.body.appendChild(dropShadeDiv);
			
			var tv = $('dropShade').innerHTML;
			$('dropShadeContent').innerHTML=tv;
			$('dropShade').innerHTML='';
			dropShadeDiv.style.width=$('dropShade').getStyle('width');
			$('dropShadeContent').style.width=$('dropShade').getStyle('width').toInt()-29+'px';
		}
		if(base){
			dropShadeDiv.style.top=base.getPosition().y+'px';
			dropShadeDiv.style.left=base.getPosition().x+'px';
			dropShadeDiv.style.display='block';
			$('expando').style.height=0;
		}
		if($('expando').getSize().y < $('dropShadeContent').getSize().y - inc){
			$('expando').style.height=$('expando').getSize().y + inc + "px";
			$('top-right').style.height=$('expando').getSize().y+2+'px';
			if($(dropShadeDiv).getCoordinates().bottom > (window.getScroll().y+window.getSize().y))
				$(dropShadeDiv).style.top=$(dropShadeDiv).getPosition().y- inc +'px';
			setTimeout('dropShade.drop()',1);
		}else{
			$('expando').style.height=$('dropShadeContent').getSize().y + "px";
			$('top-right').style.height=$('expando').getSize().y+2+'px';
		}
	},
	reset:function(){
		$('dropShadeDiv').style.display='none';
	}
}
window.addEvent('domready', function () {
	dropShade.init();
});


/*******************************************************************************
	overlay:
	Controller for overlay pages that load referenced url in iFrame that is 
	fixed in position on a grayed-out background.
*******************************************************************************/
var overlay={ //UI
	loadingURL:'/no_content/loading.html',
	tries:0,
	cover:null,
	color:'#000',
	coverOpacity:.75,
	noCoverOpacity:.25,
	opacity:0,
	zIndex:10000,
	windowW:0,
	windowH:0,
	marginY:100,
	initialFrameSize:{'x':220,'y':53},
	currentFrameSize:{'x':0,'y':0},
	finalFrameSize:{'x':0,'y':0},
	maxFrameSize:{'x':1100,'y':800},
	minFrameSize:{'x':500,'y':200},
	containerSize:{'x':0,'y':0},
	bodySize:{'x':0,'y':0},
	containerBodyDif:0,
	inFrame:true,
	frameSizePassed:false,
	href:'',
	winResizing: false,
	polling: null,
	failsafe: null,
	failsafeTimeout: 5000,
	persistedEvent: null,
	coverBackground: true,
	
	init:function(){
		// create and inject overlay background cover div
		this.cover = new Element('DIV', {
			styles:{
				position:'absolute',
				top:0,
				left:0,
				'background-color':this.color,
				opacity:this.coverOpacity,
				'filter':"alpha(opacity="+(this.coverOpacity*100)+")",
				'z-index':this.zIndex,
				display:'none',
				width:'100%',
				height:'100%',
				overflow:'hidden'
			}
		});
		this.cover.inject(document.body,'bottom');
		
		// create and inject overlay iframe
		this.frame = new Element('iframe', {
			'id':'overlayFrame',
			//'name':'myFrame',
			'frameborder':0,
			'scrolling':'no',
			'allowTransparency':true,
			'src':this.loadingURL,
			styles:{
				position:'fixed',
				'z-index':this.zIndex+1,
				//background:'transparent',
				display:'none',
				width:this.initialFrameSize.x+'px',
				//height:this.frameSide/4+'px'
				height:this.initialFrameSize.y+'px'
			}
		});
		
		
		// add events to launch links on parent page
		$(document.body).getElements('a.launchOverlay').addEvents({
			'mousedown': function(event){
				if(!event.rightClick) {
					overlay.launch(this.href);
				}
				return false;
			},
			'keypress': function(event){
				if(event.key == 'space')
					location.href=overlay.processHREF(this.href);
			}
		});
		// add events to launch no cover links on parent page
		$(document.body).getElements('a.launchOverlayNoCover').addEvents({
			'mousedown': function(event){
				overlay.launch(this.href,'noCover');
				return false;
			},
			'keypress': function(event){
				if(event.key == 'space')
					location.href=overlay.processHREF(this.href);
			}
		});
	},
	processHREF:function(href){
		return href;
	},
	launch:function(href,noCover){
		if(noCover)
			this.coverBackground = false;
		else
			this.coverBackground = true;
		/******************************************************************
		THIS SHOULD BE DONE IN INIT!!!!
		it was causing resend confirm popup in FF so I moved here
		seems to work but not where it should be
		******************************************************************/
		this.frame.inject(document.body,'bottom');
		
		
		// set up initial frame size and position then show frame
		this.href=this.processHREF(href);
		y1 = $(document.body).getScrollSize().y;
		y2 = 0;//window.getScroll().y;
		this.windowW = window.getSize().x;
		this.windowH = window.getSize().y;
		this.cover.style.height=y1+'px';
		if(this.coverBackground){
			this.cover.setStyles({
				opacity:this.coverOpacity,
				'filter':"alpha(opacity="+(this.coverOpacity*100)+")"
			});
		}else{
			this.cover.setStyles({
				opacity:this.noCoverOpacity,
				'filter':"alpha(opacity="+(this.noCoverOpacity*100)+")"
			});
		}
		this.cover.style.display='block';
		this.frame.src=this.href;
		this.frame.style.width = this.initialFrameSize.x+'px';
		this.frame.style.height = this.initialFrameSize.y+'px';
		this.frame.style.left=(this.windowW-this.initialFrameSize.x)/2+'px';
		this.frame.style.top=this.marginY+'px';
		this.frame.style.display='block';
		this.frameSizePassed = false;
		this.failsafe = setTimeout('overlay.failed()', overlay.failsafeTimeout);
		this.currentFrameSize.x = this.initialFrameSize.x;
		this.currentFrameSize.y = this.initialFrameSize.y;
	},
	failed: function(){
		clearTimeout(overlay.failsafe);
		overlay.failsafe = null;
		if(!overlay.frameSizePassed){
			//alert("We're sorry but there seems to have been a problem loading this page.\n\nClick 'OK' to close this message and try again.");
			//this.closeIt();
		}
	},
	close:function(){
		parent.overlay.closeIt();
	},
	closeIt:function(){
		this.frame.style.width = this.initialFrameSize.x+'px';
		this.frame.style.height = this.initialFrameSize.y+'px';
		this.cover.style.display='none';
		this.frame.style.display='none';
		this.frame.src = this.loadingURL;
		this.opacity=0;
		this.frameSize={'x':0,'y':0};
		clearInterval(this.polling);
		this.polling = null;
	},
	showIt: function(){
		if(isIE){
			inc = 1000;
		}else{
			inc = 10;
		}
		delay = 10;
		gox = goy = 1;
		
		// expand width by increment
		if(this.currentFrameSize.x < this.finalFrameSize.x-inc){
			this.currentFrameSize.x += inc;
		}else{
			this.currentFrameSize.x = this.finalFrameSize.x;
			gox = 0;
		}
		// expand height by increment
		if(this.currentFrameSize.y < this.finalFrameSize.y-inc){
			this.currentFrameSize.y += inc/1.5;
		}else{
			this.currentFrameSize.y = this.finalFrameSize.y;
			goy = 0;
		}
		
		// set height, width, and left styles
		this.frame.style.height= this.currentFrameSize.y+'px';
		this.frame.style.width= this.currentFrameSize.x+'px';
		this.frame.style.left= (window.getSize().x-overlay.currentFrameSize.x)/2+'px';
		
		
		if(gox+goy){
		// we haven't reached final size, call again
			setTimeout('overlay.showIt()',delay);
		}else{
		// reached final size, begin polling for window size change
			if(this.finalFrameSize.y - this.containerBodyDif < this.bodySize.y){
				this.frame.contentWindow.document.getElementById('overlayBody').style.overflowY= 'scroll';
			}else{
				this.frame.contentWindow.document.getElementById('overlayBody').style.overflowY= 'auto';
			}
			this.polling = setInterval('overlay.poller()',100);
		}

	},
	sizeIt: function(){
		clearInterval(this.polling);
		this.polling = null;
		
		// set final frame dimensions
		this.finalFrameSize.y = this.containerSize.y;
		this.finalFrameSize.x = this.containerSize.x;
		
		// if frame size exceeds max, use max instead
		if(this.finalFrameSize.x > this.maxFrameSize.x)
			this.finalFrameSize.x = this.maxFrameSize.x;
		if(this.finalFrameSize.y > this.maxFrameSize.y)
			this.finalFrameSize.y = this.maxFrameSize.y;
		// if frame size is less than min, use min instead
		if(this.finalFrameSize.x < this.minFrameSize.x)
			this.finalFrameSize.x = this.minFrameSize.x;
		if(this.finalFrameSize.y < this.minFrameSize.y)
			this.finalFrameSize.y = this.minFrameSize.y;
		
		// if frame is tall, reduce y margins
		marginY = this.marginY;
		if(window.getSize().y < this.containerSize.y+marginY*2){
			marginY /= 2;
			if(window.getSize().y < this.containerSize.y+marginY*2){
				marginY /= 2;
			}
			if(this.finalFrameSize.y > window.getSize().y - marginY*2)
				this.finalFrameSize.y = window.getSize().y - marginY*2;
		}			
		this.frame.style.top= marginY+'px';
		
		// determine overlay body height and scrolling
		newBodyH = this.finalFrameSize.y - this.containerBodyDif-20;
		this.frame.contentWindow.document.body.addClass('grayBack');
		if(newBodyH < this.bodySize.y ){
			this.frame.contentWindow.document.getElementById('overlayBody').style.height= newBodyH+'px';
		}else{
			this.frame.contentWindow.document.getElementById('overlayBody').style.height= this.bodySize.y+'px';
		}
		
		/* MOVED THIS TO SHOWIT
		if(this.finalFrameSize.y - this.containerBodyDif < this.bodySize.y){
			this.frame.contentWindow.document.getElementById('overlayBody').style.overflowY= 'scroll';
		}else{
			this.frame.contentWindow.document.getElementById('overlayBody').style.overflowY= 'auto';
		}
		*/
		
		// call func to expand iframe to final size
		this.showIt();
	},
	
	passFrameSize:function(){
		
		$('overlayContainer').style.background='none';
		$(document.body).style.background='none';
		if(parent.frames.length){
		//we are in an iframe
			// try to defeat the failed method
			clearTimeout(parent.overlay.failsafe);
			parent.overlay.failsafe = null;
			parent.overlay.frameSizePassed = true;
			parent.overlay.href=location.href
			overlay.inFrame = true;
			$('overlayContainer').style.marginTop=0;
			parent.overlay.containerSize.x=$('overlayBody').getSize().x;
			parent.overlay.containerSize.y=$('overlayContainer').getSize().y;
			parent.overlay.bodySize=$('overlayBody').getSize();
			parent.overlay.containerBodyDif= parent.overlay.containerSize.y-parent.overlay.bodySize.y;
			parent.overlay.sizeIt();
		}else{
		// we are on our own page for accessiblity
			overlay.inFrame = false;
			$$('a')[0].style.display='none';
			$('overlayContainer').style.width = $('overlayBody').getSize().x+'px';
		}
	},
	
	poller:function(){
		if(this.windowW+this.windowH != window.getSize().x+window.getSize().y){
			this.winResizing = true;
			this.windowH = window.getSize().y;
			this.windowW = window.getSize().x
		}else if(this.winResizing == true){
			this.winResizing = false;
			this.sizeIt();
		}
	},
	
	persistEvent: function (e) {
		e = e || window.event;
		this.persistedEvent = (new Event(e)).stop();
	},
	
	specialLaunch: function (e, launcher, url, element) {
		var element = element || null;
		var event;
		if ($chk(overlay.persistedEvent)) {
			event = overlay.persistedEvent;
		} else {
			event = e || window.event;
			event = new Event(event);
		}
		var launcher = $(launcher);
		url = url ||
			launcher.href || this.parseClass(launcher.getProperty("class"));
		//header = header || launcher.title;
		var posx = event.page.x;
		var posy = event.page.y;
		var altPosx = posx-window.getScroll().x;
		var altPosy = posy-window.getScroll().y;
		var l = launcher.getCoordinates().left;
		var r = launcher.getCoordinates().right;
		var t = launcher.getCoordinates().top;
		var b = launcher.getCoordinates().bottom;
		this.persistedEvent = false;
		if ((posx >= l && posx <= r && posy >= t && posy <= b) || (altPosx >= l && altPosx <= r && altPosy >= t && altPosy <= b)) {
			var u = element === null ? url : element;
			this.launch(u);
			return false;
		} else {
			window.location = url;
			return true;
		}
	}
};
window.addEvent('domready', function () {
	overlay.init();
});	
	
/*******************************************************************************
	viewBy:
	Controller for view by icons for pages that have view by options like 
	devices and accessories.
*******************************************************************************/
var viewBy = { //UI
	view: null,
	init:function(){
		$$('#viewBy a').addEvents({
			'mouseover': function(e){
				$('changeView').innerHTML = this.getProperty('rel');
			},
			'mouseout': function(e){
				$('changeView').innerHTML='View By';
			},
			'click': function(e){
				if(!this.hasClass('Selected')) {
					this.getSiblings().removeClass('Selected');
					this.addClass('Selected');
					this.view = this.getProperty('rel').toLowerCase();
					changeView(this.getProperty('rel').toLowerCase());
				}
			},
			'focus': function(e){
				$('changeView').innerHTML = this.getProperty('rel');
			},
			'blur': function(e){ 
				$('changeView').innerHTML='View By';
			}
		});
		if (this.view) {
			$$('#viewBy a.' + this.view).fireEvent('click');
		}
	},
	highlight:function(view) {
		view = view.toLowerCase();
		$$('#viewBy a').removeClass('Selected');
		$('viewBy').getElement('.'+view).addClass('Selected');
	}
};

/*******************************************************************************
	FilterMenu:
	Controller for drop-down (select) menus used for filtering on devices and 
	other areas that need a fancy select menu
*******************************************************************************/
var filterMenu = { //UI
	counter:0, //Counts the times the filterMenu has been initialized
	to:null, //Timeout for hiding dropdowns on Mouse Out
	ms:50, //Default milliseconds for the above Timeout
	menus:'', //all filterMenu elements on page
	dropDowns:'', //all dropdown elements on page
	actDiv:'', //active dropDown element
	menuLists:'', //all filterMenuList elements on page
	activeHead:null, //active filterMenuHead element
	subhead:null, //Selection DIV element
	moreOnly:true,
	originalLetterSpacing:0,
	letterSpacingExceptions:[['mobile broadband capable'],[-0.2]],
	//The first nested array holds the text value to test against, the second holds the letter spacing to assign it. Order is important.
	clearAll:function(){
		submitDWRClearAll('');
	},
	clear:function(el){
		var thisFilter = el.getParent('.filterMenuList');
		thisFilter.getElements('.filterMenuList a').removeClass('checkMark').addClass('checkBox');
		try {
			thisFilter.getElement('.joe').innerHTML = 'All';
			thisFilter.getElement('.joe').getNext('a').setStyle('display','none');
		} catch(e){}
	},
	more:function(el, type, name){ //Called to show More Features or Less Features
		var newType = (type.toLowerCase() == 'more') ? 'Less' : 'More';
		var removeMe = (type.toLowerCase() == 'more') ? 'displayNone' : 'displayBlock';
		var addMe = (type.toLowerCase() == 'more') ? 'displayBlock' : 'displayNone';
		if(type.toLowerCase() == 'more' && filterMenu.moreOnly) {
			el.set('text','');
			el.setProperty("onclick","return false;");
		} else {
			el.set('text',newType + ' ' + name);
			el.setProperty("onclick","filterMenu.more(this,'" + newType + "','Features')");
		}
		$$("."+type).each(function(item){
			item.removeClass(type);
			item.addClass(newType);
			myPar = item.getParent();
			myPar.removeClass(removeMe);
			myPar.addClass(addMe);
		});
	},
	show:function(ddMenu, showMe) {
		if (!showMe) {
			ddMenu.setStyle('display','block');
		}
		else {
			ddMenu.setStyle('display','none');
		}
	},
	adjustFocus: function(linkID) {
		//This code resets the focus object
		var focusLink = $(linkID);
		focusLink.getParent('.dropDown').setStyle('display','block');
		focusLink.focus();
	},
	updateFullMenu:function(myObject) {
		filterMenu.resetMenu(myObject.disArray);
		filterMenu.updateMenuHeader(myObject.filtersArray);
		filterMenu.updateContractCompare(myObject.results, myObject.hideContract, myObject.hideCompare);
		filterMenu.updateRows(myObject.itemArray, myObject.divName, myObject.content);
	},
	resetMenu:function(aDisabled) {
		//Reset all the classes on each list item
		$$('.filterMenu').each(function(thisFilter){
			thisFilter.getElements('.filterMenuList a').removeClass('disabled');
		});
		//Add disabled to those passed in the disabled array
		for (j = 0; j < aDisabled.length; j++) {
			$(aDisabled[j]).addClass('disabled');
		}
	},
	updateMenuHeader:function(aFilters) { //Used in response to AJAX calls that supply the subheads in an object
		//Update the subhead and disable any menus as required
		for (l=0; l < aFilters.length; l++) {
			var thisMenu = $(aFilters[l].name + 'menu');
			if($chk(thisMenu)) {
				filterMenu.activeHead = thisMenu.getElement('.filterMenuHead');
				filterMenu.subhead = (aFilters[l].subhead.length > 0) ? aFilters[l].subhead : 'All';
				filterMenu.subhead = filterMenu.subhead.trim();
				if(filterMenu.subhead.length > 21) {
					filterMenu.subhead = filterMenu.subhead.substring(0,18);
					filterMenu.subhead = filterMenu.subhead.substring(0, filterMenu.subhead.lastIndexOf(' ')) + '...';
				}
				filterMenu.activeHead.getLast('span').set('text',filterMenu.subhead);
				if(aFilters[l].disabled) {
					filterMenu.activeHead.addClass('filterDisabled');
				}
			}
		}
	},
	updateContractCompare:function (results, hideContract, hideCompare) {
		//Update the number of results shown
		$$('.filterResults').each(function(h3) {
			var text = h3.get('text').substring(h3.get('text').indexOf(' '));
			h3.set('text', results + ' ' + text);
		});
		//Show or Hide the Contract Term Filter Menu
		var contract = $('CONTRACTmenu');
		if(hideContract) {
			contract.setStyle('display','none');
			contract.getPrevious('.filterMenuSide').getChildren('span').setStyle('display','inline');
		}
		else {
			contract.setStyle('display','block');
			contract.getPrevious('.filterMenuSide').getChildren('span').setStyle('display','none');
		}
		//Show or Hide the Compare Boxes
		var display = hideCompare ? 'none' : 'block';
		$('primaryCompare').setStyle('display',display);
		$('secondaryCompare').setStyle('display',display);
	},
	updateRows:function(aRows, divName, content){
		if(aRows.length > 0) { //If a list of phones to show has been sent...
			var rowContainer = $(divName).getElement('form');
			rowContainer.getChildren('div').setStyle('display','none'); //...hide all the phone rows...
			for (i = 0; i < aRows.length; i++) {
				rowContainer.getElement('#phoneItem_'+ aRows[i]).setStyle('display','block');//...and show all the ones in the list.
			}
		}
		else { //Otherwise, replace the HTML of the the rowContainer.
			$(divName).innerHTML = content;
		}
	},
	setSubheads:function(thisFilter,subheadContainer){
		var firstLink;
		var checkedLink; 
		var	checked;
		if (thisFilter.hasClass('multi')) {
			firstLink = thisFilter.getElement('.joe').innerHTML;
			checkedLink = thisFilter.getElement('.colOne').getElements('a.checkMark'); 
			checked = checkedLink.length;
			switch (checked) {
				case 0: 
					filterMenu.subhead = 'All';
					thisFilter.getElement('.joe').innerHTML = 'All';
					thisFilter.getElement('.joe').getNext('a').setStyle('display','none');
					break;
				case 1: 
					filterMenu.subhead = checkedLink[0].get('text');
					filterMenu.updateJoe(thisFilter.getElement('.joe'),checked + ' Selected','inline');
					break;
				default: 
					filterMenu.subhead = checked + " Selected";
					filterMenu.updateJoe(thisFilter.getElement('.joe'),checked + ' Selected','inline');
			}
		} else {
			firstLink = thisFilter.getElement('a');
			checkedLink = thisFilter.getElements('.checkMark');
			checked = checkedLink ? checkedLink.length : 0;
			if(checked > 0) {
				filterMenu.subhead = checkedLink[0].get('text');
			}
			else if (firstLink) {
				firstLinkText = firstLink.get('text');
				filterMenu.subhead = firstLinkText;
				if (firstLinkText.toLowerCase() == 'all') {
					firstLink.addClass('checkMark');
				}
			} else {
				filterMenu.subhead = 'All';
			}
		}
		filterMenu.subhead = filterMenu.subhead.trim();
		if(filterMenu.subhead.length > 21) {
			filterMenu.subhead = filterMenu.subhead.substring(0,18);
			filterMenu.subhead = filterMenu.subhead.substring(0, filterMenu.subhead.lastIndexOf(' ')) + '...';
		}
		subheadContainer.set('text',filterMenu.subhead.trim());
		if(isIE) {
			subheadContainer.setStyle('height',15);
		}
	},
	updateJoe:function(joe,html,display){
		try {
			joe.innerHTML = html;
			joe.getNext('a').setStyle('display',display);
		} catch(e){}
	},
	checkExceptions:function(anchorElement,over) {
		for(i=0;i<filterMenu.letterSpacingExceptions[0].length;i++) {
			var anchorText = anchorElement.get('text');
			anchorText = anchorText.clean().toLowerCase();
			if(anchorText.test(filterMenu.letterSpacingExceptions[0][i])) {
				if(over) {
					filterMenu.originalLetterSpacing = anchorElement.getStyle("letterSpacing");
					anchorElement.setStyle("letterSpacing",filterMenu.letterSpacingExceptions[1][i]+"px");
				} else {
					anchorElement.setStyle("letterSpacing",filterMenu.originalLetterSpacing);
				}
			}
		}
	},
	init:function() {
		if(isIE) {
			this.ms = 150;
		}
		filterMenu.dropDowns = $$('.dropDown');
		filterMenu.dropDowns.setStyles({'display':'block','visibility':'hidden'});
		$$('.filterMenuList').each(function(element,index) {
			filterMenu.actDiv = element.getParent('.dropDown');
			filterMenu.activeHead = element.getParent('.filterMenu').getElement('a.filterMenuHead');
			filterMenu.menuLists = element.getElements('a');
			// create html for shadow divs
			left = new Element('div');left.className = 'lft';
			right = new Element('div');right.className = 'rght';
			tops = new Element('div',{'html':'<div></div><span></span>'});tops.className = 'top';
			bottom = new Element('div',{'html':'<div></div><span></span>'});bottom.className = 'bottom';
			middle = new Element('div');middle.className = 'middle';
			// inject html for shadow divs
			middle.wraps(element);
			left.inject(middle,'top');
			right.inject(middle,'bottom');
			tops.inject(filterMenu.actDiv,'top');
			bottom.inject(filterMenu.actDiv,'bottom');
			// set zIndex of parent divs to prevent underlap
			if(element.getElements("a:not('.disabled')").length < 1) {
				filterMenu.activeHead.addClass('filterDisabled');
			}
			filterMenu.activeHead.getParent().setStyle('zIndex',100-index);
			filterMenu.activeHead.getFirst('span').set('class','top');
			//Any filterMenu with a class 'go' or a class 'defaultSub' has a default subhead set that isn't one of the selections.
			//Therefore, we skip the step where the subhead is automatically set on initiation as the first dropdown element.
			if(!element.getParent('.filterMenu').hasClass('go') && !element.getParent('.filterMenu').hasClass('defaultSub')) {
				filterMenu.setSubheads(element, filterMenu.activeHead.getLast('span'));
			} else if (element.getParent('.filterMenu').hasClass('defaultSub') && filterMenu.counter > 0) {
				filterMenu.setSubheads(element, filterMenu.activeHead.getLast('span'));
			}
			//If we're in the Features list...
			if(/Features/.test(filterMenu.activeHead.get('text'))) {
				//...wrap a div around each anchor tag
				filterMenu.menuLists.each(function(el) {						   
					if(el.hasClass('moreButton')) {return;}
						/*This has to be done in javascript for now because JSTL is outputting spacing, which is causing problems with class detection*/
						el.setProperty('class',el.getProperty('class').clean());
						/*This has to be done in javascript for now because JSTL is outputting spacing, which is causing problems with class detection*/
					var wrapDiv = new Element('div');
					if(el.hasClass('More')) {
						wrapDiv.className = 'displayNone';
					}
					wrapDiv.wraps(el);
				});
				//...and adjust features list position because it's wider than one column
				var newWidth = (element.offsetWidth + 45)*5;
				var newLeft = newWidth - 280;
				filterMenu.actDiv.setStyles({
					'left':-newLeft
				});
				filterMenu.actDiv.getParent().setStyles({
					'zIndex':100
				});
				//set BOTH the widths filterMenu.actDiv AND element to fix ie6 gridview issue with features dropdown
				if(isIE && ieVersion<=6) {
					filterMenu.actDiv.setStyle('width',newWidth+45);
					element.setStyle('width',newWidth+45);
				}
			} else {
				//for all the rest, add only enough width to accomodate bold text
				var newWidth = element.offsetWidth + 45;
			}				
			// set widths one way works in FF one way works in IE :(
			if(isIE){
				filterMenu.actDiv.setStyle('width',newWidth+45);
			}else{
				element.setStyle('width',newWidth);
			}
		});
		//Switch the method of hiding the dropdowns after their widths have been determined
		filterMenu.dropDowns.setStyles({'display':'none','visibility':'visible'});
		filterMenu.setupEventHandlers();
		if(this.counter > 0 && $chk($('clearAll'))) {
			setFocus.self('clearAll');
		}
		this.counter++;
	},
	setupEventHandlers:function(){
		//BEGIN EVENT HANDLERS AND LISTENERS
		//Attach the Event handling for hiding and showing the dropdowns and to process the Ajax when a filter is selected
		//Attach Event handling for the anchor rollovers to work with mouse and keyboard
		filterMenu.dropDowns.addEvents({
			'mouseleave': function() {
				if(isIE) { 
					filterMenu.to = setTimeout(function() {filterMenu.show(filterMenu.actDiv, true);}, filterMenu.ms); 
				} else {
					filterMenu.show(filterMenu.actDiv, true);
				}
			},
			'blur': function() {
				filterMenu.show(filterMenu.actDiv, true);
			}
		});
		$$("a.filterMenuHead").addEvents({
			'mouseenter': function() {
				if(isIE) { clearTimeout(filterMenu.to); }
				if(this.hasClass('filterDisabled')) { return; }
				$$('.dropDown').setStyle('display','none');
				filterMenu.actDiv = this.getNext('.dropDown');
				filterMenu.show(filterMenu.actDiv);
			},
			'focus': function() {
				if(this.hasClass('filterDisabled')) { return; }
				clearTimeout(filterMenu.to);
				$$('.dropDown').setStyle('display','none');
				filterMenu.actDiv = this.getNext('.dropDown');
				filterMenu.show(filterMenu.actDiv);
			}
		});
		$$(".filterMenuList a.disabled").addEvent('focus', function() {
			clearTimeout(filterMenu.to);
			if(this.getNext("a:not('.disabled')")) {
				this.getNext("a:not('.disabled')").focus();
			} else if (this.getParent('div').getParents('.colOne').length > 0) {
				if (this.getParent().getNext("div a:not('.disabled')")) {
					this.getParent().getNext("div a:not('.disabled')").getElement("a").focus();
				} else {
					var nexts = this.getParent().getAllNext("div a:not('.moreButton')");
					node = (nexts.length > 0) ? nexts.length-1 : 0;
					try { nexts[node].getElement("a").focus(); } catch(e) {}
				}
			} else {
				var nexts = this.getAllNext("a");
				nexts[nexts.length-1].focus();
			}
		});
		$$(".filterMenuList a.moreButton").addEvents({
			'mouseover': function() {
				if(isIE) { clearTimeout(filterMenu.to); }
			},
			'focus': function() {
				clearTimeout(filterMenu.to);
			},
			'blur': function() {
				filterMenu.to = setTimeout(function() {filterMenu.show(filterMenu.actDiv, true);}, filterMenu.ms);
			}
		});
		$$(".filterMenuList a").addEvents({
			'mouseover': function() {
				if(this.hasClass('moreButton')) {return;}
				if(isIE) { clearTimeout(filterMenu.to); }
				this.addClass('highlight');
				filterMenu.checkExceptions(this,true);
			},
			'mouseout': function() {
				if(this.hasClass('moreButton')) {return;}
				this.removeClass('highlight');
				filterMenu.checkExceptions(this,false);
			},
			'focus': function() {
				if(this.hasClass('moreButton')) {return;}
				clearTimeout(filterMenu.to);
				this.addClass('highlight');
			},
			'blur': function() {
				if(this.hasClass('moreButton')) {return;}
				this.removeClass('highlight');
				filterMenu.to = setTimeout(function() {filterMenu.show(filterMenu.actDiv, true);}, filterMenu.ms);
			},
			'click': function() { //works from mouse click or 'enter' using keyboard after focus
				if(this.hasClass('disabled') || this.hasClass('noClick') || this.hasClass('moreButton')){return;}
				if(this.hasClass('checkMark') && this.getParent('.filterMenu').hasClass('noDeselect')){return;}
				//set the default values to pass to the DWR
				var myId = this.get('id');
				var addMe = 'remove';
				var thisFilter = this.getParent('.filterMenuList');
				if(thisFilter.hasClass('multi')){  //If you can select more than one filter from this menu
					if(this.hasClass('checkMark')) {
						this.removeClass('checkMark');
						this.addClass('checkBox');
					}else{
						this.removeClass('checkBox');
						this.addClass('checkMark');
						addMe = 'add';
					}
					//Hide or Show the Clear option on multi list dropdowns
					var checked = thisFilter.getElements('a.checkMark').length;
					if (checked > 0) {
						filterMenu.updateJoe(thisFilter.getElement('.joe'),checked + ' Selected','inline');
					}
					else {
						filterMenu.updateJoe(thisFilter.getElement('.joe'),'All','none');
					}
				}else{ //If you can select only one filter from this menu
					if(this.hasClass('checkMark')){
						this.removeClass('checkMark');								
					}else{
						this.getSiblings('a').removeClass('checkMark');
						this.addClass('checkMark');
						addMe = 'add';
					}
				}
				//The filterMenus with a go button and a class 'go' do not submitDWR, they simply update the subheads. All the rest submitDWR
				if(this.getParent('.filterMenu').hasClass('go') || this.getParent('.filterMenu').hasClass('defaultSub')) { 
					filterMenu.setSubheads(thisFilter, this.getParent('.filterMenu').getElement('.filterMenuHead').getLast('span'));
				}
				filterMenu.show(this.getParent('.dropDown'), true);
				submitDWR(myId,addMe);
			} //End Click function
		});
		//END EVENT HANDLERS AND LISTENERS
	} //Closes init:
}; //Closes var filterMenu
	
window.addEvent('domready',function() {if(typeof(waitForFilterInit)=='undefined' || !waitForFilterInit) filterMenu.init() });
	
/*******************************************************************************
	Scroller: 
	Controller for scrolling slide show
*******************************************************************************/
var Scroller = new Class({ //UI
	me:null,
	initialize: function(containerDiv,instance,jump){
		me = this;
		this.slideIncrement = 10;
		this.containerDiv = $(containerDiv);
		this.infoDiv = this.containerDiv.getElement('.infoDiv')
		this.slides = this.containerDiv.getElement('.slideDiv').getChildren('div');
		this.divWidth = this.containerDiv.getElement('.slideDiv').getParent().getSize().x;
		this.slideDiv = this.containerDiv.getElement('div.slideDiv');
		this.slideDiv.setStyle('left',0);
		this.slideWidth = this.slides[0].getSize().x;
		this.visibleSlides = parseInt(this.divWidth/this.slideWidth);
		this.length = this.slides.length;
		this.center = parseInt(this.visibleSlides/2);
		this.index = this.center;
		this.prev = this.containerDiv.getElement('div.prev');
		this.prev.addEvents({
			'mouseover': function(){
				this.addClass('prevHover');
			},
			'mouseout': function(){
				this.removeClass('prevHover');
			},
			'click': function(){
				me.scroll(-1,instance);
			}
		});
		
		this.next = this.containerDiv.getElement('div.next');
		this.next.addEvents({
			'mouseover': function(){
				this.addClass('nextHover');
			},
			'mouseout': function(){
				this.removeClass('nextHover');
			},
			'click': function(){
				me.scroll(1,instance);
			}
		});
		
		this.selectorDiv = this.containerDiv.getElement('div.selectorDiv');

		for(i=0;i<this.length;i++){
			selector  = new Element('div', {
				html: '&#160;',
				events:{
					'mouseover': function(){
						this.addClass('hover');
					},
					'mouseout': function(){
						this.removeClass('hover');
					},
					'click': function(){
						me.show(this.index,instance);
					}
				}
			}); 
			selector.index = i;
			selector.inject(this.selectorDiv);
		}
		this.selectors = this.selectorDiv.getElements('div');
		w = ((parseInt(this.selectors[0].getStyle('margin-left')) * 2) + this.selectors[0].getSize().x ) * this.length;
		this.selectorDiv.setStyle('width', w);
		
		// eliminate controls if all items are visible
		if(this.length <= this.visibleSlides){
			this.prev.style.display = 'none';
			this.next.style.display = 'none';
			this.selectorDiv.style.display = 'none';
		}else{
			this.selectors[this.center].addClass('selected');
			this.slides[this.center].addClass('selected');
			
		}
	},
	show: function(n,instance){
		me = eval(instance);
		me.index = n;
		for(i=0;i<me.length;i++){
			if(i==n){
				me.selectors[i].addClass('selected');
				me.slides[i].addClass('selected');
			}else{
				me.selectors[i].removeClass('selected');
			me.slides[i].removeClass('selected');
			}
		}
		me.newLeft = (n*me.slideWidth*-1)+me.slideWidth*me.center;
		if(me.jump){
			me.jump();
		}else{
			me.slide();
		}
		
	},
	scroll: function(n,instance){
		me = eval(instance);
		n = n + me.index;
		if(n >= me.length){
			n = 0;
		}else if(n<0){
			n = me.length-1;
		}
		me.show(n,instance);
	},
	slide: function(){
		oldLeft = parseInt(this.slideDiv.style.left);
		diff = oldLeft - this.newLeft;
		if(diff<0){
			diff *= -1 ;
			mult = -1;
		}else{
			mult = 1;
		}
		if(diff < this.slideIncrement){
			this.slideDiv.setStyle('left',this.newLeft);
		}else{
			mult = oldLeft > this.newLeft ? -1 : 1;
			inc = diff/5;
			nextLeft = parseInt(oldLeft+inc*mult);
			this.slideDiv.setStyle('left',nextLeft);
			setTimeout('me.slide()',5);
		}
	},
	jump: function(){
		this.slideDiv.setStyle('left', this.newLeft);
		/*
		oldLeft = parseInt(this.slideDiv.style.left);
		diff = oldLeft - this.newLeft;
		if(diff<0){
			diff *= -1 ;
			mult = -1;
		}else{
			mult = 1;
		}
		if(diff < this.slideIncrement){
			this.slideDiv.setStyle('left',this.newLeft);
		}else{
			mult = oldLeft > this.newLeft ? -1 : 1;
			inc = diff/5;
			nextLeft = parseInt(oldLeft+inc*mult);
			this.slideDiv.setStyle('left',nextLeft);
			setTimeout('me.slide()',5);
		}
		*/
	}
});

/*******************************************************************************
AJAX Event Handlers
*******************************************************************************/
function ajaxOnRequest() { //UI
	var disabledImageZone = $('disabledImageZone');
	if (!disabledImageZone) {
	  disabledImageZone = document.createElement('div');
	  disabledImageZone.setAttribute('id', 'disabledImageZone');
	  disabledImageZone.style.position = "absolute";
	  disabledImageZone.style.zIndex = "100000";
	  disabledImageZone.style.width = "100%";
	  disabledImageZone.style.left = "0px";
	  disabledImageZone.style.height = window.getCoordinates().height + "px";
	  disabledImageZone.style.top = window.getScroll().y + "px";
	  var imageZone = document.createElement('img');
	  imageZone.setAttribute('id','imageZone');
	  imageZone.setAttribute('src',"/images_b2c/shared/elements/loading_animation.gif");
	  disabledImageZone.appendChild(imageZone);
	  document.body.appendChild(disabledImageZone);
	  imageZone.style.position = 'absolute';
	  //imageZone.style.left = (window.getSize().x / 2) - ($('imageZone').getSize().x / 2) + 'px';
	  //imageZone.style.top = (window.getSize().y / 2) - ($('imageZone').getSize().y / 2) + 'px';
	  centerOnPage('imageZone');
	}
	else {
	  disabledImageZone.style.height = window.getCoordinates().height + "px";
	  disabledImageZone.style.top = window.getScroll().y + "px";
	  disabledImageZone.style.visibility = 'visible';
	}
 }
 
function ajaxOnComplete(response) {  
	$('disabledImageZone').style.visibility = 'hidden'; 
}


