// JavaScript Document

function hideElement(elementId){
	if(document.getElementById(elementId)){
		document.getElementById(elementId).style.display = 'none';
	}
}

function showElement(elementId){
	if(document.getElementById(elementId)){
		document.getElementById(elementId).style.display = '';
	}
}


var tickerLeftPosition = 0;
var pauseTheTicker = false;

function pauseTicker() {
	pauseTheTicker = true;
}
function unPauseTicker() {
	pauseTheTicker = false;
}
function moveTicker(){
	if(!checkTicker()) return 0;
	if(pauseTheTicker==false){
		tickerLeftPosition = tickerLeftPosition-1;
		if(document.getElementById('tickerWindow'))
		{
			if(document.getElementById('tickerWindow').offsetWidth+tickerLeftPosition<0)
			{
				tickerLeftPosition = document.getElementById('tickerContainer').offsetWidth;
				showElement('tickerWindow');
			}
			document.getElementById('tickerWindow').style.left = tickerLeftPosition+'px';
		}
	}
}
setInterval("moveTicker()", 25);

function checkTicker() {
	try { 
		if(document.getElementById('tickerWindow')) return true;
	} catch (e) {}
	return false;
}
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height){
  if(popUpWin){
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function pop2(url){
	window.open(url,"Link","width=800,height=600,scrollbars,resizable,status,top=20,left=20");
}

var old_clicks = new Array;

function outgoing_links()
{
	var links = document.getElementsByTagName("a");
	var urlRe = new RegExp("http:\/\/((www\.)?)([a-zA-Z0-9\\_\\-\\.]*)\.([a-zA-Z]{1,5})/");
	for(var i=0;i<links.length;i++) 
    {
    	if (links[i].onclick == undefined)
		{
        	fullPath = links[i].href.toLowerCase();
			last4 = fullPath.substring(fullPath.length-4, fullPath.length);
            if (links[i].href.toLowerCase().indexOf("mailto:") > -1)
           	{
            	
           		links[i].onclick=function()
                {
                	href = this.href.toLowerCase();
                    emailLink = href.replace("mailto:","");
                    pageTracker._trackEvent('Mails', 'Click', emailLink.toLowerCase() );
                };
           	}
            else if(links[i].href.toLowerCase().indexOf("thisiscooperstown.com") == -1 && urlRe.test(links[i].href))
            {
            	links[i].onclick=function()
                {
                	href = this.href;
                    re = /https?:\/\/(www\.)?([^/]+)?/i;
                    href.match( re );
                    domainOnly =  RegExp.$2;
                    pageTracker._trackEvent('Outgoing links', 'Click', domainOnly.toLowerCase() );
                };
           	}
            else if( (last4 == ".pdf") )
           	{
            	links[i].onclick=function()
                {
                	href = this.href;
                    splhref = href.split('/');
                    fileOnly = splhref[splhref.length-1];
                    pageTracker._trackEvent('Downloads', 'PDF', fileOnly.toLowerCase() ); 
                };
             }
             else if( (last4==".doc") )
            {
                links[i].onclick=function()
                {
                    href = this.href;
                    splhref = href.split('/');
                    fileOnly = splhref[splhref.length-1];
                   
                    pageTracker._trackEvent('Downloads', 'DOC', fileOnly.toLowerCase() ); 
                };
             }
             
                 
		}
	}
}
