///////////////////////////////////////////////////////////////////////////////
//
// Image Rotate
// Written by Matt Chestnut, adapted for IBC website by Heidi Will
//

function startUp() {

	// home
	if ($('#home').length > 0) { 
	
			//  <------------------- this changes the link
			 
			var imageSrc = new Array();    //  <----------------- array of image filenames. NOTE: to change very first one, must define bannerImg in left_menu tile on index.jsp
			imageSrc[1] = 'evangelistic_meetings_2012.jpg';
			imageSrc[2] = '2012cdays_big.jpg';
			imageSrc[3] = '2012theater.jpg';
			imageSrc[4] = 'ibc_banner_3.jpg';
			imageSrc[5] = 'ibc_banner_4.jpg';
			imageSrc[6] = 'ibc_banner_5.jpg';
			imageSrc[7] = 'ibc_banner_6.jpg';
									
			var href = new Array();    //  <--------------------- array of urls. NOTE: to change very first one, must change on left_menu.jsp
			href[1] = 'http://www.tricityministries.org/tcbc/news/2012/20120205_evang_mtg.jsp';
			href[2] = '/ibc/events/cdays/index.jsp';
			href[3] = '/ibc/events/theater/index.jsp';
			href[4] = '/ibc/whyibc/tll_think.jsp';
			href[5] = '/ibc/whyibc/tll_live.jsp';
			href[6] = '/ibc/whyibc/tll_lead.jsp';
			href[7] = '/ibc/whyibc/index.jsp';
						                 
			var target = new Array();    //  <------------------- array of targets for the urls. NOTE: to change very first one, must change on left_menu.jsp
			target[1] = 'EvangelisticMeetings';
			target[2] = '_self';
			target[3] = '_self';
			target[4] = '_self';		
			target[5] = '_self';		
			target[6] = '_self';		
			target[7] = '_self';		
								
			$('#imgRotate').before('<img src="/ibc/_images/banners/ibc_banner_1.jpg" id="img-back" />');
			$('#img-back').css('position', 'absolute');
			$('#img-back').css('top', $('#imgRotate').offset().top);
			$('#img-back').css('z-index', '-1');
			img = 0;
			src = '';
			
			function fade_in(){
				$('#imgRotate').attr('src', src);
				$('#anchor').attr('href', href[img]);  //  <----- this changes the link
				$('#anchor').attr('target', target[img]);  // <-- this changes the target
				$('#imgRotate').animate({
					opacity: 1
				}, 700, function(){ // delay between switch
					img_preload();
				});
			}
			
			function fade_out(){
				$('#imgRotate').delay(2000).animate({ // duration in milliseconds
					opacity: 0
				}, 700, function(){ // delay between switch
					fade_in();
				});
			}
			
			function img_preload(){
				preload = new Image();
				preload.onLoad = fade_out();
				img++;
				if (img > 7) // change to number of images in rotation
					img = 1;
				src = '/ibc/_images/banners/' + imageSrc[img]; // path/imageSrc of current image 
				$(preload).attr('src', src);
			}
			
			img_preload(); 
		
	}
}

///////////////////////////////////////////////////////////////////////////////
//
// Email
//

// Opens e-mail window for Tri-City
// NOTE:  Assumes valid email address
function openDefaultEmailWindow( /* String */ email ) {
	openEmailWindow("", email);
}

// Opens e-mail window for 'pageTitle' (i.e. TCBC, Re:vive, etc.)
// Assumes valid email address
function openEmailWindow( /* String */ pageTitle,
						  						/* String */ email     ) {

	var winLeft = (screen.width - 600) / 2;
	var winTop  = (screen.height - 450) / 2 - 50;

	if (winLeft < 0) {
		winLeft = 0;
	}
	if (winTop < 0) {
		winTop = 0;
	}

	popUpWindow = window.open( '/ibc/email/emailform.jsp?sendToAddress='+email+'&pageTitle='+pageTitle,
			'email'+parseInt(Math.random()*100),
			'toolbar=0,location=0,scrollbars=0,resizable=1,status=1,width='+ 600 +',height=' + 450 + ',top=' + winTop + ',left=' + winLeft );
}

///////////////////////////////////////////////////////////////////////////////
//
// Calendar
//

function openCalendarWindow( /* String */ id ) {

	var winLeft = (screen.width - 600) / 2;
	var winTop  = (screen.height - 350) / 2 - 50;

	if (winLeft < 0) {
		winLeft = 0;
	}
	if (winTop < 0) {
		winTop = 0;
	}

	popUpWindow = window.open( '/tcbc/calendar/displayevent.jsp?id=' + id,
			'event' + parseInt(Math.random()*100),
			'toolbar=0,location=0,scrollbars=1,resizable=1,status=1,width='+ 600 +',height=' + 350 + ',top=' + winTop + ',left=' + winLeft );
}

///////////////////////////////////////////////////////////////////////////////
//
// Youth Conference Registration
//

function openYCRegistrationWindow() {

	popUpWindow = window.open( 'http://www.tricityministries.org/tbcforms/youthregistration/newYouth.action',
			'YCreg' + parseInt(Math.random()*100),
			'toolbar=0,location=0,scrollbars=1,resizable=1,status=1,width='+ 750 +',height=' + 800  );
}


///////////////////////////////////////////////////////////////////////////////
//
// College Comparison Tool
//

function openCollegeComparisonToolWindow() {

	popUpWindow = window.open( '/ibc/resources/tools/college_comparison_tool.jsp',
			'CollegeComparisonTool' + parseInt(Math.random()*100),
			'menubar=1,toolbar=0,location=0,scrollbars=1,resizable=1,status=1,width='+ 750 +',height=' + 800  );
}

///////////////////////////////////////////////////////////////////////////////
//
// College Comparison Tool - Philosophy
//

function openCollegeComparisonToolWindowPhilosophy() {

	popUpWindow = window.open( '/ibc/resources/tools/college_comparison_tool.jsp#philosophy',
			'CollegeComparisonTool' + parseInt(Math.random()*100),
			'menubar=1,toolbar=0,location=0,scrollbars=1,resizable=1,status=1,width='+ 750 +',height=' + 800  );
}


///////////////////////////////////////////////////////////////////////////////
//
// College Comparison Tool - Ministry
//

function openCollegeComparisonToolWindowMinistry() {

	popUpWindow = window.open( '/ibc/resources/tools/college_comparison_tool.jsp#ministry',
			'CollegeComparisonTool' + parseInt(Math.random()*100),
			'menubar=1,toolbar=0,location=0,scrollbars=1,resizable=1,status=1,width='+ 750 +',height=' + 800  );
}


///////////////////////////////////////////////////////////////////////////////
//
// College Comparison Tool - Academic
//

function openCollegeComparisonToolWindowAcademic() {

	popUpWindow = window.open( '/ibc/resources/tools/college_comparison_tool.jsp#academic',
			'CollegeComparisonTool' + parseInt(Math.random()*100),
			'menubar=1,toolbar=0,location=0,scrollbars=1,resizable=1,status=1,width='+ 750 +',height=' + 800  );
}


///////////////////////////////////////////////////////////////////////////////
//
// College Comparison Tool - Student Life
//

function openCollegeComparisonToolWindowStudentLife() {

	popUpWindow = window.open( '/ibc/resources/tools/college_comparison_tool.jsp#studentLife',
			'CollegeComparisonTool' + parseInt(Math.random()*100),
			'menubar=1,toolbar=0,location=0,scrollbars=1,resizable=1,status=1,width='+ 750 +',height=' + 800  );
}


///////////////////////////////////////////////////////////////////////////////
//
// College Comparison Tool - Financial
//

function openCollegeComparisonToolWindowFinancial() {

	popUpWindow = window.open( '/ibc/resources/tools/college_comparison_tool.jsp#financial',
			'CollegeComparisonTool' + parseInt(Math.random()*100),
			'menubar=1,toolbar=0,location=0,scrollbars=1,resizable=1,status=1,width='+ 750 +',height=' + 800  );
}


