$(document).ready(function() {
    	$('#slider img').ready(function() {
		jQuery("#slider").anythingSlider({
			width : 918,
			height : 276,
			easing : 'easeInOutExpo',
			delay : 8000,
			animation : 1750
		});
	});
	schawkNewsTickerStarter(1,true);
	$("#homepage-left").touchwipe({
		     wipeLeft: function() { slideFront(1); },
		     wipeRight: function() {slideFront(-1); },
		     min_move_x: 20,
		     min_move_y: 20,
		     preventDefaultEvents: true
		});

	$("ul#slider").touchwipe({
			     wipeLeft: function() { $('div.anythingSlider span.forward').click(); },
			     wipeRight: function() { $('div.anythingSlider span.back').click(); },
			     min_move_x: 20,
			     min_move_y: 20,
			     preventDefaultEvents: true
		});

	$('div.frontArrow.left').click(function(){
		slideFront(1);
	});

	$('div.frontArrow.right').click(function(){
		slideFront(-1);
	});
	showHomepageRight(false);
  });

function schawkNewsTicker(activeNewsItem){
	//$('#schawkNewsTicker').fadeOut();
	var activeNewsItemStr=$('div.view-press-releases div div ul li.views-row-' + activeNewsItem).html();
	if(activeNewsItemStr != null){
		$('#schawkNewsTicker').fadeOut(1000,function(){
			$('#schawkNewsTicker').html(activeNewsItemStr);
			}).fadeIn(2000);
	}
	if(activeNewsItem==4){
		activeNewsItem=1;
	}
	else {
		activeNewsItem=activeNewsItem+1;
	}
	schawkNewsTickerStarter(activeNewsItem,false);
	return true;
}

function schawkNewsTickerStarter(activeNewsItem,isFirst){
	var theTimer=isFirst?1:9000;
	setTimeout('schawkNewsTicker('+activeNewsItem+')',theTimer);
	return true;
}

function slideFront(direction){
	var slideChildren,newSlideChildren,theIndex,theLength;
	slideChildren = $('div#homepage-left div.wrapper').children();
	theLength=slideChildren.length;
	newSlideChildren=new Array(theLength);
	for(var i=0;i<theLength;i++){
		theIndex=i+direction==theLength?0:i+direction;
		theIndex=theIndex<0?theLength-1:theIndex;
		newSlideChildren[i]=slideChildren[theIndex];
	}
	$('div#homepage-left div.wrapper').children().remove();
	$('div#homepage-left div.wrapper').append(newSlideChildren);
}

function takeMeTo(thisPlace){
	window.location=thisPlace;
}

function showHomepageRight(trueFalse){
	var mainP,showP,theLength,theLink,shortP;
	mainP=$('#aboutSchawk div.mainP').html();
	shortP=$('#aboutSchawk div.shortP').html();
	theLength=mainP.length;
	if(theLength<496){
		return;
	}
	if(trueFalse){
		var theHeight;
		theLink='&nbsp;<a href="javascript:showHomepageRight(false);">&lt;&lt; Collapse</a>';
		mainP=$('#aboutSchawk div.mainP').html() + theLink;
		theLength=mainP.length;
		theHeight=Math.round(theLength/7);
		$('#aboutSchawk div.showP').css('height',theHeight+'px');
		$('#aboutSchawk div.showP').html(mainP);
	}
	else {
		//var theNearestSpace,theIndex;
		//theLink='&nbsp;<a href="javascript:showHomepageRight(true);">Read More &gt;&gt;</a>';
		//theNearestSpace=mainP.substring(450,theLength).indexOf(' ');
		//theIndex=theNearestSpace==-1?467:450+theNearestSpace;
		//theIndex=theIndex>467?467:450+theNearestSpace;
		//showP=shortP+'...'+theLink;
		$('#aboutSchawk div.showP').css('height','48px');
		setTimeout('growAboutSchawk()',300);
	}
}

function growAboutSchawk(){
	//var theLink='&nbsp;<a href="javascript:showHomepageRight(true);">Read More &gt;&gt;</a>';
	var shortP=$('#aboutSchawk div.shortP').html();
	var showP=shortP;
	$('#aboutSchawk div.showP').html(showP);
}

