// JavaScript Document
String.prototype.count = function(char){
    return this.split(char).length-1;
}

function startScroller(){
	var $clients = $('div.clients');
	var $clientscroller = $('#clientscroller');
	var totalWidth = 0;
	var left = $clientscroller.width();
	$clients.css('left',left+'px');
	for(var idx=0; idx < $('div.clients img').length; idx++){
		$('div.clients img:eq('+idx+')').css('margin-right','20px');
		totalWidth = totalWidth + $('div.clients img:eq('+idx+')').width() + 20;
	}
	$clients.css('width',totalWidth*2+'px');
	$clients.html($clients.html() + $clients.html());
	$(document).everyTime(10,function(){
		left = left - 1;
		$clients.css('left',left+'px');
		if (left <= 0 - totalWidth){
			left = 0;
			$clients.css('left',left+'px');
		}
	});
}
function evenHeights(elem1, elem2){
	if (elem1.height() > elem2.height()){
		elem2.css('height',elem1.height() + 'px');
	} else {
		elem1.css('height',elem2.height() + 'px');
	}
}
function setCurrentMenu(){
	var urlarray = new Array();
	var strQueryString = location.href.replace('#','');
	if (strQueryString.count('?') > 0){
		var strQueryString = strQueryString.split('?')[0];
	}	
	urlarray = strQueryString.split("/");
	var filename = urlarray[urlarray.length - 1];
	if (filename == ''){
		filename = 'index.asp';		
	}
	if ($(".newsreleasepage").length > 0){
		filename = 'news-releases.asp';
	}
	if ($(".eventspage").length > 0){
		filename = 'events.asp';
	}
	$('ul.sf-menu a[href="'+filename+'"]').each(function(index){
		$(this).parents('li').addClass("current");
	});
	$('ul#sidenav a[href="'+filename+'"]').each(function(index){
		$(this).parents('li').addClass("current");
	});
}
$(function(){
	$('#topnav').corner('top 5px');
	if ($('#accordion').length > 0){
		$('#accordion').msAccordion({autodelay:5});
	}
	$('div.cta').each(function(index){
		if ((index + 1) % 3 == 0){
			$(this).css("margin-right","0px");
		}
	});
	$('#newslist').splitUp(2,'<div class="newspage">').cycle({ 
		fx:      	'scrollUp', 
		delay:  	-1000,
		timeout:  	7000,
		sync:		true
	});
	$("a.morenews").click(function(){
		if ($('#newslist li.newitems').length > 3){
			$('#newslist').cycle('next');
		}
		return false;
	});
	//$('#quotes ul').cycle('fade');
	$('ul.sf-menu').superfish();
	$('div.columnstwo').columnize({
		width:280
	});
	$('ul#sitemap li:nth-child(5)').addClass('clearfix');
	$("#tickertape ul").liScroll(); 
	evenHeights($('#content-interior div.leftside'), $('#content-interior div.rightside'));
	startScroller();
	setCurrentMenu();
	$('div.silverheader a.sliderclicker').click(function(){
		if ($(this).siblings('div.blinds').hasClass("current")){
			$('div.silverheader div.blinds').removeClass("current");
			$(this).siblings('div.blinds').slideUp("normal");
		} else {
			$('div.silverheader div.blinds').removeClass("current");
			$(this).siblings('div.blinds').addClass("current");
			$('div.blinds').each(function(){
				if ($(this).hasClass("current")){
					$(this).slideDown("normal");
				} else {
					$(this).slideUp("normal");
				}
			});
		}
		return false;
	});
	/*
	$('#keywords ul li a').hover(
		function(){
			$(this).animate({
				fontSize:'+=4px'
			}, 100);
		},
		function(){
			$(this).animate({
				fontSize:'-=4px'
			}, 100);
		}
	);
	*/
});
