var highlightNewsNav_YAH = "#7A7979";
var highlightNewsNav_OFF = "#333";
var highlightNewsNav_OVER = "#eee";
var bottomAccordion;
var runningxmlhttpPost = false;
var runEventsApp = true;
var slideShowHtml = "";

//Event.observe(window, 'load', loadAccordions, false);
	
function loadAccordions() {
	bottomAccordion = new accordion('vertical_container', {
		resizeSpeed : 9,
		classNames : {
		    toggle : 'accordion_toggle',
		    toggleActive : 'accordion_toggle_active',
		    content : 'accordion_content'
		},
		direction : 'vertical',
		onEvent : 'click'
	});
	//setTimeout(runFirst,1000);
}


function runAccordion(){
	if(document.getElementById('accordion')){
		$("#accordion").accordion({
			autoHeight: false,
			collapsible: true,
			active: false			//closed on start up
		});		
	}else{
		setTimeout('runAccordion()',10);
	}
}
runAccordion();

function runFirst(){
	bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
}
/* ~~~~~~~~~~[ Breaking news ]~~~~~~~~~~~ */
function runBreakingNews(showId){
	var newsItems = document.forms['breakingNewsForm'].numberOfItems.value;
	
	if(parseInt(newsItems) > 1){
		for(z=1;z<=newsItems;z=z+1){
			document.getElementById('newsItem_' + z).style.display = 'none';
			document.getElementById('newsNavLink_' + z).style.background = 'url(/images/interface/dotNav.png) no-repeat';
		}
	
		document.getElementById('newsItem_' + showId).style.display = 'block';
		/* ~~~~~~~[ newsNav ] ~~~~~~~~~ */
		document.getElementById('newsNavLink_' + showId).style.background = 'url(/images/interface/dotNav_YAH.png) no-repeat';
		
		globalShowId = showId;
		
		if(showId == newsItems){
			showId = 1
		}else{
			showId = showId + 1;
		}	
		
		t = setTimeout('runBreakingNews(' + showId + ')',4000);
	}
}
function gotoBreakingNews(showId){
	clearTimeout(t);
	runBreakingNews(showId);
}
function highlightNewsNav(obj,state){
	var currentShowId = window.globalShowId;
	var idOn = obj.id;
	idOn = idOn.substring(idOn.indexOf('_')+1);
	
	if(state == 'over'){
		obj.style.background = 'url(/images/interface/dotNav_YAH.png) no-repeat';
	}else if(idOn == currentShowId){
		obj.style.background = 'url(/images/interface/dotNav_YAH.png) no-repeat';
	}else{
		obj.style.background = 'url(/images/interface/dotNav.png) no-repeat';
	}
}

/* ~~~~~~~~~~[ twitterFeed ]~~~~~~~~~~~ */
function twitterFeed(rssId,twitterId){
	if(document.getElementById('twitterFeed') && window.runningxmlhttpPost == false){
		//runningxmlhttpPost = true;
		//xmlhttpPost('/O2Net/Applications/TransformDoc/default.aspx?XmlDoc=http://twitter.com/statuses/user_timeline/' + rssId + '&XsltDoc=/xsltTemplate/twitterFeed.xslt&XmlVars=twitterId|' + twitterId,'twitterFeed');
	}else{
		//setTimeout('twitterFeed(\'' + rssId + '\',\'' + twitterId + '\')',500);
	}	
}
/* ~~~~~~~~~~[ events ]~~~~~~~~~~~ */
function runEvents(pageConfig){
	/*
	if(runEventsApp == true){
		loadingMessage('/images/loading_3.gif',10);
		if(document.getElementById('httpReqResults') && window.runningxmlhttpPost == false){
			runningxmlhttpPost = true;
			xmlhttpPost('/O2Net/Applications/TransformDoc/default.aspx?XmlDoc=/xml/content/events.xml&XsltDoc=/xslt/eventsSub.xslt&XmlVars=pageConfig|' + pageConfig + ',version|home','httpReqResults');
		}else{
			setTimeout('runEvents(\'' + pageConfig + '\')',500);
		}
	}
	*/
	/*
	if(document.getElementById('events') && window.runningxmlhttpPost == false){
		//xmlhttpPost('/O2Net/Applications/TransformDoc/default.aspx?XmlDoc=http://twitter.com/statuses/user_timeline/23431733.rss&XsltDoc=/xslt/twitterFeed.xslt','events');
		$("#twitter").getTwitter({
			userName: "lillibridge",
			numTweets: 1,
			loaderText: "Loading tweets...",
			slideIn: false,
			showHeading: false,
			headingText: "Latest Tweets",
			showProfileLink: true
		});		
	}else{
		setTimeout('runEvents(\'' + pageConfig + '\')',1000);
	}	
	*/
}
/* ~~~~~~~~~~[ Careers ]~~~~~~~~~~~ */
function goGetUrl(formName,selectName){
	window.location.href = eval('document.' + formName + '.' + selectName).options[eval('document.' + formName + '.' + selectName).selectedIndex].value;
}
/* ~~~~~~~~~~[ Locator ]~~~~~~~~~~~ */
function explodeMapLocator(){
	document.getElementById('locatorExplodeMap').style.display = 'block';
	xmlhttpPost('/O2Net/Applications/TransformDoc/default.aspx?XmlDoc=/xml/content/events.xml&XsltDoc=/xslt/salesRepsUsImgMap.xslt','locatorExplodeMap');
}
function compressExplodedMap(){
		document.getElementById('locatorExplodeMap').style.display = 'none';
		//document.getElementById('mapThumb').style.display = 'block';
}
/* ~~~~~~~~~~[ About ]~~~~~~~~~~~ */
function loadAboutCopy(){
	if(document.getElementById('leftcontent')){
		document.getElementById('aboutText').innerHTML = document.getElementById('leftcontent').innerHTML;
		reDrawSifr();
	}else{
		setTimeout('loadAboutCopy()',200);
	}	
}
/* ~~~~~~~~~~[ Promo ]~~~~~~~~~~~ */
function promotion(totalPromos){
	if(getCookie('promotion') == null){
		SetGetCookie('promotion',1);
	}else{
		if(parseFloat(getCookie('promotion')) >= parseFloat(totalPromos)){
			SetGetCookie('promotion',1)
		}else{
			SetGetCookie('promotion',(parseFloat(getCookie('promotion'))+1))
		}
	}
	var promoShow = 'promo' + getCookie('promotion');
	document.getElementById(promoShow).style.display = 'block'; 
}
/* ~~~~~~~~~~[ twitterFeed ]~~~~~~~~~~~ */
function twitterFeedSifr(){
	if(document.getElementById('twitterFollowLink')){
		reDrawSifrFromHome();
	}else{
		setTimeout('twitterFeedSifr()',250);
	}
}
/* ~~~~~~~~~~[ common ]~~~~~~~~~~~ */
function xmlhttpPostComplete(){
	runningxmlhttpPost = false;
}
function reDrawSifrFromHome(){
	/* will not seem to run if we try to call reDrawSirf within sifr_config.js */
	var aColor = getStyle("twitterLink","color");
	var aColorHover = getStyle("twitterLinkHover","color");

	sIFR.replace(sifrFont2, {
     selector: 'h3'
     ,css: [
       '.sIFR-root { text-align: left; font-weight: normal; }'
    	,'a:link { color: ' + aColor + '; }'
    	,'a:hover { color: ' + aColorHover + '; }'	   
     ]
     ,
  	wmode: 'transparent'	  
   });	
	
	 sIFR.replace(sifrFont2, {
     selector: 'h4'
     ,css: [
       '.sIFR-root { text-align: left; font-weight: normal; }'
    	,'a:link { color: #024E5E; }'
    	,'a:hover { color: #024E5E; }'	   
     ]
     ,
  	wmode: 'transparent'	  
   });
}
function getStyle(el,styleProp)
{
	 /*
	  http://www.quirksmode.org/dom/getstyles.html
	  Pass styles in as style sheet declorations, IE wants javascript way
	 */ 
	 var x = document.getElementById(el);
	 if (x.currentStyle){
	  //ie
	  switch(styleProp)
	  {
	  case 'text-decoration':
	    styleProp = 'textDecoration';
	    break;    
	  default:
	  }
	  var y = x.currentStyle[styleProp];
	 }else if (window.getComputedStyle){
	  var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	 }
	 return y;
} 
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
  	}
	return "999";
}

function loadSlideShowSlide(){
	if(getQueryVariable("slideLoad") != "999"){
		if(getQueryVariable("slideLoad") == 'ad2'){
			//Specific to loading youtube based
			if(document.getElementById('flashcontent')){
				loadYouTubeVid('-kQXBjmO1Rw');
			}else{
				setTimeout('loadSlideShowSlide()',500);
			}
		}
		/*
		if(document.getElementById('flashcontent')){
			sspLoadContent(getQueryVariable("slideLoad"));
		}else{
			setTimeout('loadSlideShowSlide()',500);
		}	
		*/		
	}
}

loadSlideShowSlide();

function loadYouTubeVid(vidId){
	slideShowHtml = document.getElementById('slideShow').innerHTML;
	
	var htmlStr = '';
	
	//document.getElementById('newsHeadlines').style.top = '40px';
	//document.getElementById('events').style.top = '40px';
	//document.getElementById('promotion').style.top = '40px';
	//document.getElementById('locator').style.top = '40px';
	
	htmlStr += '<div id="vidCloseBar"><a href="javascript:void(0);" onClick="unloadYouTube();"><img width="640" height="31" src="/images/interface/vidClose.png" /></a></div>';
	htmlStr += '<div id="vidYouTube">';
	htmlStr += '<object width="640" height="505">';
	htmlStr += '<param class="flashVideo" name="movie" value="http://www.youtube.com/v/' + vidId + '&hl=en_US&fs=1&rel=0"></param>';
	htmlStr += '<param name="wmode" value="transparent" />';
	htmlStr += '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>';
	htmlStr += '<embed src="http://www.youtube.com/v/' + vidId + '&autoplay=1&hl=en_US&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505" wmode="transparent"></embed>';
	htmlStr += '</object>';	
	htmlStr += '</div>';
	document.getElementById('slideShow').innerHTML = htmlStr;
	document.getElementById('newsHeadlines').style.zIndex = -1;
	scroll(0,0);
}
function unloadYouTube(){
	document.getElementById('slideShow').innerHTML = window.slideShowHtml;
	document.getElementById('newsHeadlines').style.zIndex = 1;
	//document.getElementById('newsHeadlines').style.top = '20px';
	so.write("flashcontent");
}
