function openWindow(URL,width,height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 50,top = 50');");
	return false;
}
function trim(a) {
	a = a.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
}
function swapPIC(elem, source) {
	elem.src = source;return false;
}
function isEmail(str) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	if (str.indexOf(at)==-1){return false;}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
	if (str.indexOf(at,(lat+1))!=-1){return false;}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
	if (str.indexOf(dot,(lat+2))==-1){return false;}
	if (str.indexOf(" ")!=-1){return false;}
	return true;
}
function isInteger(nr){
	var patt=/(^\d+$)/;
	if(!patt.test(nr)){return false;}
	return true;
}
function initializeGoogleMaps() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"))
		map.setCenter(new GLatLng(38.20365531807151, -92.900390625), 4);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
	}
}

function showAddressGoogleMaps(address) {
	if (geocoder) {
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
				} else {
					var marker = new GMarker(point);
					map.addOverlay(marker);
				}
			}
			);
	}
}

function getGoogleCenter(address, zoom) {
	if (geocoder) {
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
				} else {
					map.setCenter(point, zoom);
				}
			}
			);
	}
}

function showMap(address) {
	$(document).ready(function() {
		initializeGoogleMaps();
		showAddressGoogleMaps(address);
		getGoogleCenter(address, 14);
	});
}

function cncSlideshow(base, group, selector, timeGap) {
    if (($(base).length > 0) && ($(group).children(selector).length > 1)) {
        $(base).data('flag', 0);
        setInterval("cascadeFadeInOut('" + base + "', '" + group + "', '" + selector + "')", timeGap);
    }
}

// See: http://jonraasch.com/blog/a-simple-jquery-slideshow
function cascadeFadeInOut(base, group, selector) {
    var numChildren = $(base).children(group).length;
    var selected = $(base).children(group).eq(parseInt($(base).data('flag')) % numChildren);
    $(base).data('flag', parseInt($(base).data('flag')) + 1);

    var $active = selected.children(selector + '.active');
    if ( $active.length == 0 ) $active = selected.children(selector + ':last');
    var $next =  $active.next().length ? $active.next() : selected.children(selector + ':first');
    $active.addClass('last-active');
    $next.css({
        opacity: 0.0
    })
    .addClass('active')
    .animate({
        opacity: 1.0
    }, 1000, function() {
        $active.removeClass('active last-active');
    });
}

$(document).ready(function(){
    cncSlideshow('#media', '.slides', '.oneslide', 5000);
    cncSlideshow('#media-text', '.slides', '.oneslide', 5000);
    cncSlideshow('#media-logos', '.slides', '.oneslide', 5000);
});

