/* cattco_2.js for mootools.noajax.js
 * Created: 20061115
 */

/* */

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/* test for unsupported browsers */
if (BrowserDetect.browser == 'Explorer') {
	if (BrowserDetect.version < 6) {
		document.write('<div id="browser_error"><p>You\'re using ' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' which is an unsupported web browser and you may have difficulties viewing this website!<br/>');
		document.write('Please download and install one of the following supported browsers:</p>');
		document.write('<p><a href="http://www.GetFirefox.com">Mozilla Firefox</a><br/>');
		document.write('<a href="http://www.Opera.com">Opera</a><br/>');
		document.write('<a href="http://www.microsoft.com/downloads/info.aspx?na=22&p=1&SrcDisplayLang=en&SrcCategoryId=6&SrcFamilyId=&u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d1e1550cb-5e5d-48f5-b02b-20b602228de6%26DisplayLang%3den">Internet Explorer 6</a> or');
		document.write('<a href="http://www.microsoft.com/downloads/info.aspx?na=22&p=4&SrcDisplayLang=en&SrcCategoryId=6&SrcFamilyId=&u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d9ae91ebe-3385-447c-8a30-081805b2f90b%26DisplayLang%3den">Internet Explorer 7 or greater</a>');
		document.write('</p><p>If you need assistance please contact your computer support personnel or the <strong>Webmaster@CattCo.org</strong></p></div>');
	}
}

function startUp() {
	newsAndEvents();
	startGallery();
	external_links();
	blink_event();
	//windowSize();
}

function windowSize() {
	//var tmpW = $('')
}

function newsAndEvents() {
	if ($('news_and_events') != false) {
		var tmpNewsEventsSize = $('news_and_events').getSize();
		//$('nav_sect').setHTML(tmpNewsEventsSize.size.x+" "+" "+tmpNewsEventsSize.size.y);
		if (tmpNewsEventsSize.size.x <= 589) {
			$$('#news_and_events .news').each(function(el) {
				if (!el.hasClass('full')) {
					el.addClass('full');
				}
			});
			$$('#news_and_events .events').each(function(el) {
				if (!el.hasClass('full')) {
					el.addClass('full');
				}
			});
		} else {
			$$('#news_and_events .news').each(function(el) {
				if (el.hasClass('full')) {
					// remove class
					el.removeClass('full');
				}
			});
			$$('#news_and_events .events').each(function(el) {
				if (el.hasClass('full')) {
					// remove class
					el.removeClass('full');
				}
			});
		}
	}
}
function startGallery() {
	if ($('map_slideshow') != false) {
		var myGallery = new gallery($('map_slideshow'), {
			timed: true,
			showArrows: false,
			showCarousel: false,
			imageSelector: 'img',
			slideInfoZoneOpacity: 0.9,
			textShowCarousel: 'Maps'
		});
	}
}
function external_links() {
	$$(document.links).each(function(a) {
		if (a.getProperty('rel') == 'external') {
			a.setProperty('target', '_blank');
			tmpTitle = a.getProperty('title');
			if (tmpTitle == null) {
				tmpTitle = a.innerHTML;
			}
			a.setProperty('title', tmpTitle + ' (opens in new window)');
		}
    });
    /*
    $$('a.ext').each(function(a) {
		a.addEvent("click", function() {
    	    var iRandom = Math.random();
    		window.open(this.href, 'CattCo.org: Economic Development Window ['+iRandom+']');
    	    return false;
    	});
    });
    */
}

function blink_event() {

  var list = $$('.blink');
  list.each(function(element) {
  
    var effect = element.effect('background-color', {duration:1400});
    var periodical;
    
    var fx = function() {
      effect.start('#eeeeee').chain(function(){
        effect.start('#ffff99');
        /*ccff66*/
      });
    }
    fx();
    periodical = fx.periodical(3000);
  });
}

window.addEvent('domready', startUp);
window.addEvent('resize', newsAndEvents);
//window.addEvent('resize', windowSize);