var highlightNewsNav_YAH = "#7A7979";
var highlightNewsNav_OFF = "#333";
var highlightNewsNav_OVER = "#eee";
var bottomAccordion;
var runViolator = true;

/* ~~~~~~~~~~[ 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';
	}
}
/* ~~~~~~~~~~[ 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';
}
/* ~~~~~~~~~~[ 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'; 
}

$(document).ready(function() {
	var pageOn = baseURL();
	
	$("#accordion").accordion({
		autoHeight: false,
		collapsible: true,
		active: false			//closed on start up
	});
	
	if(window.runViolator == true && getCookie('violator_hide') != 'true'){
		violator();
	}	
	
	dontShowLink();
})
$(window).load(function () {
    loadRightBucketAd();
});

/* ~~~~~~~~~~[ Violator ]~~~~~~~~~~~ */

var violatorClosed = false;

$(window).load(function () {
	violatorDynamic();
});

function dontShowLink(){
	$('#violatorDontShow').hover(
		function () {
			$(this).css('background','#74c2e1');
		}, 
		function () {
			$(this).css('background','transparent');
		}
	);
	
	$('#violatorDontShow').click(function() {
		dontShowActivate();
	});
}
//deleteCookie('violator_hide');
function dontShowActivate(){
     setCookie('violator_hide','true');
     closeViolator();
}

function violatorDynamic(){
	$('#dynBanner').append('<iframe src="/html/dynamicbannerad2.html" width="960" height="135" frameborder="0" scrolling="no" allowtransparency="true"></iframe>');
}

function violator(){
	var divParent = document.getElementById('main');		
	var newdiv = document.createElement('div');
	var divIdName = 'violator';	
	var strHtml = '';
	strHtml += '<div id="violatorDontShow"><img src="/images/content/violoator_dontShow2.png" width="187" height="20" /></div>';
	strHtml += '<div id="dynBannerClick"><img src="/images/trans.gif" width="960" height="130" /></div><a href="http://emcomm.federalsignal.com"><div id="dynBanner"></div><img src="/images/content/violoator_and_ad_emcomm2.png" width="958" height="131" /></a>';
	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = strHtml;
	divParent.appendChild(newdiv);	
	setTimeout('violatorSlide()',2000);
	setTimeout('violatorSlide()',9000);
	
	$('#dynBannerClick').mousedown(function() {
	  window.location = "http://emcomm.federalsignal.com/"
	});		
	
}
function violatorSlide(){
	if(window.violatorClosed == false){
		$("#violator").slideToggle("slow");
	}	
}
function closeViolator(){
	violatorClosed = true;
	document.getElementById('violator').style.display = 'none';
}
/* ~~~~~~~~~~[ end: Violator ]~~~~~~~~~~~ */
function loadRightBucketAd(){
	var pageOn = baseURL();
	if(pageOn.indexOf('home') != -1 || pageOn == 'http://federalsignalpss.orbisdesign.net/' || pageOn == 'http://www.alertnotification.com/' || pageOn == 'http://alertnotification.com/' || pageOn == 'http://www.federalwarningsystems.com/' || pageOn == 'http://federalwarningsystems.com/' ){
		var htmlStr = '';
		//htmlStr += '<div id="rightBucketAd"><a href="http://emcomm.federalsignal.com/blog/introducing-emcomm" target="_blank"><img src="/images/content/subPanel_introducingEmcomm.png" width="309" height="209" /></a></div>';
		htmlStr += '<div id="rightBucketAd"><a href="/SmartMSGMicro_9451.aspx"><img src="/images/content/subPanel_smartMsg.png" width="309" height="209" /></a></div>';
		$("#locator").html(htmlStr);
		$("#locator").css("display","block");
	}	
}

/* ~~~~~~~~~~[ common ]~~~~~~~~~~~ */
function reDrawSifr(){
     sIFR.replace(sifrFont1, {
     selector: 'h2'
    ,css: [
    	'.sIFR-root { text-align: left; font-weight: bold; }'
    	,'a { text-decoration: none; }'
    	,'a:link { color: #000000; }'
    	,'a:hover { color: #CCCCCC; }'
	]
    ,
   wmode: 'transparent'   
   });
} 
function xmlhttpPostComplete(){

}
function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function deleteCookie(name) {
    setCookie(name,"",-1);
}
