/* Version 1.00 last updated by DO6596 on 10-06-2008 at 05:04pm CST */


/* ROTATE MARQUEES */

/* WINDOWS ONLOAD */
Event.observe(window, 'load', function(){
	var bUnit = $("pageID").readAttribute("rel");
	checkReg();	
	if($("accordion")){
		loadAccordions();
	}
	initiateRotateHero('hero1');
	assignPopupHandler();		
	
	if(getCookie("uvp_env")){ setCookie("uvp_env_homeGreen","yes","365","/","") }	
	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))){ document.title = "AT&T" }	
	
	$$(".accPromo").each(function(element){
		element.show();
	});
	
	//window.onunload = killSession;
	
	$$(".topLeftTabs a").each(function(element){
		element.onclick = function(){
			var lnkPath = element.readAttribute("href");
			var temp = new Array;
			temp = lnkPath.split('=');
			var lnk = temp[1];
			if(lnk == "9213"){
				setCookie("DTAB", "Tab=Bus", "365", "/",".att.com");
			}
			if(lnk == "3308"){
				setCookie("DTAB", "Tab=Res", "365", "/",".att.com");
			}
		}
	});
	
	
	$$(".shopForLink a").each(function(element){
		element.onclick = function(){
			var lnkPath = element.readAttribute("href");
			var temp = new Array;
			temp = lnkPath.split('=');
			var lnk = temp[1];
			if(lnk == "9214"){
				setCookie("subDTAB","BUSINESS","365","/",".taiheinfo.net");
				window.location.replace("/gen/landing-pages?pid=9214");
				return false;
			}
			if(lnk == "11624"){
				setCookie("subDTAB","WHOLESALE","365","/",".taiheinfo.net");
				window.location.replace("/gen/general?pid=11624");
				return false;
			}
			if(lnk == "11625"){
				setCookie("subDTAB","GOVERNMENT","365","/",".taiheinfo.net");
				window.location.replace("/gen/general?pid=11625");
				return false;
			}			
		}
	});
});

function checkReg(){
	$$('sup').each(function(element){
		var newReg = escape(element.innerHTML);
		if(newReg == "%AE"){
			element.addClassName("reg");
		}
		if(navigator.userAgent.match(/Safari/i)){
			element.addClassName("supSafari");			
		}
	});
}


function initiateRotateHero(heroToShow) {
	
}

function setCookie( name, value, expires, path, domain, secure ){
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function getCookie(name) {
	var dc = document.cookie;
	var cname = name + "=";
	var clen = dc.length;
	var cbegin = 0;
	while (cbegin < clen) {
	var vbegin = cbegin + cname.length;
	if (dc.substring(cbegin, vbegin) == cname) {
		var vend = dc.indexOf (";", vbegin);
		if (vend == -1) vend = clen;
			return unescape(dc.substring(vbegin, vend));
		}
		cbegin = dc.indexOf(" ", cbegin) + 1;
		if (cbegin== 0) break;
	}
	return null;
}	

function loadAccordions() {
	if(Prototype.Browser.Opera){
		if($("accTable")){$("accTable").setStyle({fontSize:"10px", textAlign:"left"});}
	}	
	var topAccordion = new accordion('accordion', {
		classNames : {
			toggle : 'accToggler',
			toggleActive : 'toggleActive',
			content : 'accContent'
		},
		defaultSize : {
			width : 230
		},
		direction : 'vertical'
	});
	
	// Open first one
	topAccordion.activate($$('#accordion .accToggler')[0]);		
}

/*-----------------------------------------------------------------------------------------------*/
// accordion.js v2.0
//
// Copyright (c) 2007 stickmanlabs
// Author: Kevin P Miller | http://www.stickmanlabs.com
// 
// Accordion is freely distributable under the terms of an MIT-style license.
//
// I don't care what you think about the file size...
//   Be a pro: 
//	    http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
//     http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files
//

if (typeof Effect == 'undefined') 
	throw("accordion.js requires the script.aculo.us effects.js library!");

	var accordion = Class.create();
	accordion.prototype = {
		showAccordion : null, 
		currentAccordion : null, 
		duration : null, 
		effects : [], 
		animating : false,		
		initialize: function(container, options) {
			if (!$(container)) {
				throw(container+" doesn't exist!"); 
				return false;
			}		  
			this.options = Object.extend({
				resizeSpeed : 8,
				classNames : {
					toggle : 'accordion_toggle',
					toggleActive : 'accordion_toggle_active',
					content : 'accordion_content'
				},
				defaultSize : {
					height : null,
					width : null
				},
				direction : 'vertical',
				onEvent : 'mouseover'
			}, 
			options || {});
			this.duration = ((11-this.options.resizeSpeed)*0.15);
			var accordions = $$('#'+container+' .'+this.options.classNames.toggle);
			accordions.each(function(accordion) {
				Event.observe(accordion, 'mouseover', this.activate.bind(this, accordion), false);
				Event.observe(accordion, 'click', this.activate.bind(this, accordion), false);
				if (this.options.onEvent == 'click') {
					accordion.onclick = function() {
						return false;
					};
				}
				if (this.options.direction == 'horizontal') {
					var options = $H({
						width: '0px'
					});
				} 
				else {
					var options = $H({
						height: '0px'
					});
				}
				options.merge({display: 'none'});			
				this.currentAccordion = $(accordion.next(0)).setStyle(options);			
			}.bind(this));
		},
		//  Activate an accordion
		activate : function(accordion) {
			if (this.animating) {
				return false;
			}
			
			this.effects = [];
		
			this.currentAccordion = $(accordion.next(0));
			this.currentAccordion.setStyle({
				display: 'block'
			});		
			
			this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);
	
			if (this.options.direction == 'horizontal') {
				this.scaling = $H({
					scaleX: true,
					scaleY: false
				});
			} else {
				this.scaling = $H({
					scaleX: false,
					scaleY: true
				});			
			}
				
			if (this.currentAccordion == this.showAccordion) {
				//this.deactivate();
			} else {
				this._handleAccordion();
			}
		},
		
		// Deactivate an active accordion
		deactivate : function() {
			var options = $H({
				duration: this.duration,
				scaleContent: false,
				transition: Effect.Transitions.sinoidal,
				queue: {
					position: 'end', 
					scope: 'accordionAnimation'
				},
				scaleMode: { 
					originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
					originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
				},
				afterFinish: function() {
					this.showAccordion.setStyle({
						height: 'auto',
						display: 'none'
					});				
					this.showAccordion = null;
					this.animating = false;
				}.bind(this)
			});    
			options.merge(this.scaling);
	
			this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);    
			new Effect.Scale(this.showAccordion, 0, options);
		},
	
		// Handle the open/close actions of the accordion
		_handleAccordion : function() {
			//alert(this.currentAccordion.scrollHeight);
			var options = $H({
				sync: true,
				scaleFrom: 0,
				scaleContent: false,
				transition: Effect.Transitions.sinoidal,
				scaleMode: { 
					originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
					originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
				}
			});
			options.merge(this.scaling);
			
			this.effects.push(
				new Effect.Scale(this.currentAccordion, 100, options)
			);
	
			if (this.showAccordion) {
				this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
				
				options = $H({
					sync: true,
					scaleContent: false,
					transition: Effect.Transitions.sinoidal
				});
				options.merge(this.scaling);
				
				this.effects.push(
					new Effect.Scale(this.showAccordion, 0, options)
				);				
			}
			
			new Effect.Parallel(this.effects, {
				duration: this.duration, 
				queue: {
					position: 'end', 
					scope: 'accordionAnimation'
				},
				beforeStart: function() {
					this.animating = true;
				}.bind(this),
				afterFinish: function() {
					if (this.showAccordion) {
						this.showAccordion.setStyle({
							display: 'none'
						});				
					}
					$(this.currentAccordion).setStyle({
						height: 'auto'
					});
					this.showAccordion = this.currentAccordion;
					this.animating = false;
				}.bind(this)
			});
		}
	}
	var verticalAccordions = $$('.accordion_toggle'); 
	verticalAccordions.each(function(accordion) {     
		$(accordion.next(0)).setStyle({         
			height: '0px'
		});
	}); 
/*-----------------------------------------------------------------------------------------------*/


function assignPopupHandler() {
	$$('a.popup').each(function(element) {
		element.onclick = function() {
			return openPopup(this.href);
		}
	});
	
	$$('a.popupClose').each(function(element) {
		element.onclick = function() {
			return window.close();
		}
	});
}

function openPopup(url){
	window.open(url,'popup_window','height=600,width=800,resizable=yes,scrollbars=yes');
	return false;
}

function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}

function utm_on_mouse_over(on_selected_id){
	var _menuIds=new Array('s1','s2','s3','s4','s5');
	var _banners=new Array('hero1','hero2','hero3','hero4','hero5');
	for(var i=0;i<_menuIds.length;i++){
		var curr_el_id=_menuIds[i];
		var curr_el=document.getElementById(curr_el_id);
		if(curr_el_id==on_selected_id){
 			curr_el.className='shopForLink selected'; 
			MM_changeProp(_banners[i],'','display','block','DIV');
		}else{
			curr_el.className='shopForLink';
			MM_changeProp(_banners[i],'','display','none','DIV');
		}
	}
}