
	$(function(){	
		  


// MAIN IMAGE ROTATION SLIDESHOW FUNCTION

//hide text for images that aren't the first image. 
$('#mainRotation a img, #mainRotation a .mainImgText').hide();
$('#mainRotation a:first').addClass('current');
$('#mainRotation a.current img, #mainRotation a.current .mainImgText').fadeIn('slow');						   

	var whatsnewrotate = true;
	SS = {
		currentnum:0,
		showWrapper:'',
		showItems:'',
		sItems:'',
		showLength:0,
		controls:false,	
	 //setup slideshow - (main container,target tag,add numberlinks,place numberlinks rel to container (before, after, append, prepend))
		setupShow : function(wrpr,itms,plyr,plyrloc) {
			//main container of slideshow
			showWrapper = wrpr;
			//containers within main container that container img info/will be changed
			sItems = itms;
			showItems = showWrapper.children(itms);
			//length of show based on number of showItems above
			showLength = showItems.length;
		  
		  if (plyr && showLength >1) {
			  //write number links for controls if specified, add img alt tag for qtip tooltip
			var nums = '<div id="numberLinks">';
			for(i=0;i<showLength;i++) {
				i==0 ? nums += '<a href="" class="currentnum" alt="' +  $('#mainRotation a:eq(0)').attr('alt') + '">' + (i + 1) + '</a>' : nums += '<a href="" alt="' +  $('#mainRotation a:eq(' + i  + ')').attr('alt') + '">' + (i + 1) + '</a>';
				}
			nums += '<a href="" class="pausebtn">Pause</a></div>';
			//determine where numberLinks goes relative to the showWrapper
			if (plyrloc == "before") {
				showWrapper.before(nums)
			} else if (plyrloc == "after") {
				showWrapper.after(nums);
			} else if (plyrloc == "append") {
				showWrapper.append(nums);
			} else if (plyrloc == "prepend") {
				showWrapper.prepend(nums);
			}
			
			$('#numberLinks a').click(function() {
				if ($(this).attr('class') == 'pausebtn') {
					whatsnewrotate = false;
				//	clearInterval(showInterval);
					$(this).removeClass('pausebtn').addClass('playbtn').text('Play');
				} else if ($(this).attr('class') == 'playbtn') {
					whatsnewrotate = true;
					SS.fadeShow();
					$(this).removeClass('playbtn').addClass('pausebtn').text('Pause');
				} else {
					  
					whatsnewrotate = false;
					//clearInterval(showInterval);
					$('#numberLinks a.pausebtn').removeClass('pausebtn').addClass('playbtn').text('Play');
					
					var curnum = (parseInt($(this).siblings('.currentnum').text())) - 1;
					var curli = showWrapper.find(sItems + ':eq('+curnum+')');
				
					 var thisnum = (parseInt($(this).text())) - 1;
					 $(this).siblings('.currentnum').removeClass('currentnum').end().addClass('currentnum');
					 var thisli = showWrapper.find(sItems + ':eq(' + thisnum + ')');
					 
					//curli.removeClass('current').fadeOut('slow');
					 thisli.addClass('current').find('img,div').fadeIn('slow');
					 thisli.siblings().removeClass('current').find('img,div').hide();
				
				}
			
				return false;
			});		
			
			//set controls variable to true so fadeShow will change number links
			controls = true;
			}
		},
		fadeShow : function() {
			if (showLength >1) {
			//get the current image
                var currentItem = $('#mainImgs a.current');//('ul.slideshow_nothumbs li.current');
				
				//if current item is the last li, go back to the first
				if (showWrapper.find(sItems + ':eq(' + (showLength-1) + ')').attr('class')== "current") {
					
					currentItem.removeClass('current').find('img, div').fadeOut(1200);
					showWrapper.find(sItems + ':eq(0)').addClass('current').find('img,div').fadeIn(1200);
					if (controls) {
						$('#numberLinks').find('a.currentnum').removeClass('currentnum');
						$('#numberLinks').find('a:eq(0)').addClass('currentnum');
					}
				} else {
					currentItem.removeClass('current').find('img,div').fadeOut(1200);
					currentItem.next().addClass('current').find('img,div').fadeIn(1200);
					if (controls) {
						thisn = $('#numberLinks').find('a.currentnum');
						thisn.next().addClass('currentnum');
						thisn.removeClass('currentnum'); 
					}
						
				}
			}
		}
	};
		
	//('#mainImgs a img').hide();
	//$('#mainImgs a:eq(0) img').fadeIn();
	//setup slideshow - (main container,target tag,add numberlinks,place numberlinks rel to container (before, after, append, prepend))	
	SS.setupShow($('#mainImgs'),'a',true,'after');
	//START What's New slideshow rotation	
	//var showInterval = setInterval("SS.fadeShow()",12000);
	
var mainInterval = setInterval(rotateThings,6000);
function rotateThings() {

		if (whatsnewrotate) {
			SS.fadeShow();	
		}
	}

	
	 
	 
	 
/*---- MAIN MENU DROPDOWNS FOR IE6 ---*/
 if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
	$('#nav li').hover(function(){
		if ($(this).parent().attr('id') == 'nav') {
			$(this).addClass('currnav');
			$(this).find('a:eq(0)').css('color','#746548');
		}
	},function(){
		if ($(this).parent().attr('id') == 'nav') {
			$(this).removeClass('currnav');
			$(this).find('a:eq(0)').css('color','#fff');
		}
	});	
}


/*---- OPEN .EXTERNAL LINKS IN NEW WINDOW ---*/
$('.external').click( function() {
 if (!$(this).hasClass('movie1')) {							   
	window.open($(this).attr('href'));					   
	return false;
	}
});
							   
function openSizedExternal(width,height,resize) {
}
	


/*---------- WHAT'S NEW SLIDER ---------*/

$('#whatsNew').append('<a href="" class="leftArrow"><img src="index_images10/arrowleft.gif" alt="previous" width="24" height="24" /></a><a href="" class="rightArrow"><img src="index_images10/arrowright.gif" alt="next" width="24" height="24" /></a>	');

var maxLength = $('#whatsNew ul li').length;
var slideCounter = 1;
$('#whatsNew .leftArrow').click( function() {
	if (slideCounter != 1) {													  
		var position = $(this).parent().find('ul').position();
		$(this).parent().find('ul').animate({ left: position.left + 250 + "px"}, 600 );
		slideCounter--;
	} else if (slideCounter == 1) {	
		$(this).parent().find('ul').animate({ left: -((maxLength-1) * 250) + "px"}, 400 );
		slideCounter = maxLength;
	}
	return false;
});

$('#whatsNew .rightArrow').click( function() {
	if (slideCounter != maxLength) {									   
		var position = $(this).parent().find('ul').position();
		$(this).parent().find('ul').animate({ left: position.left - 250 + "px"}, 600 );
		slideCounter++;
	} else if (slideCounter == maxLength) {	
		$(this).parent().find('ul').animate({ left: "0px"}, 400 );
		slideCounter = 1;
	}
	return false;
});



/*---------- VIDEO SHOW/HIDE ---------*/

	var showmovie = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="480" height="280" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="http://mfile.akamai.com/17525/mov/colonialwil.download.akamai.com/17525/HanksPSA/TomHanksPSA_512k.mov"><param name="autoplay" value="true"><param name="controller" value="true"><param name="loop" value="false"><param name="bgcolor" value="#000000"><embed src="http://mfile.akamai.com/17525/mov/colonialwil.download.akamai.com/17525/HanksPSA/TomHanksPSA_512k.mov" width="480" height="280" bgcolor="#000000" autoplay="true" controller="true" loop="false" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>';

	
$('#aboutCW .movieThumb').click( function() {
if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
	$('#movieSpot').replaceWith(showmovie);
 } 
	$('#movieLayer').toggle();
 
	return false;
/*	if ($('#movieLayer').css('left') != '150px') {
		$('#movieLayer').css('left','150px');	
	} else {
		$('#movieLayer').css('left','-9999px');
	}*/
});

$('#movieLayer a').click ( function() {
	if ($(this).hasClass('movieClose')) {
		$('#movieLayer').hide();
		//$('#movieLayer').css('left','-9999px');
		return false; 
	} 
});





});	  
