// Pine Cove
function PC_pageInit()
{
	// put any code here that needs to be ran on every page
	
	if ( navInit ) navInit();
	
	// set google analytics code if not already set
	if ( typeof(_uacct) === 'undefined' || _uacct == "" ) _uacct = "UA-442752-1";

	// run google analytics tracking
	if ( urchinTracker ) 
	{
		// check for custom GA page name
		if ( typeof(gaPageName) === 'undefined' || gaPageName == "" ) 
		{
			urchinTracker();
		}
		else if ( typeof(gaPageName) !== 'undefined' && gaPageName != "ignoreThisPage" )
		{
			urchinTracker(gaPageName);
		}
		// call e-commerce tracking if page name and utmtrans are set
		if ( document.getElementById('utmtrans') && __utmSetTrans ) {
			__utmSetTrans();	
		}

	}

	if ( MM_preloadImages ) MM_preloadImages(
		'/images/nav/nav_summercamps_over.gif'
		,'/images/nav/nav_conferences_over.gif'
		,'/images/nav/nav_retreats_over.gif'
		,'/images/nav/nav_outdoored_over.gif'
		,'/images/nav/nav_aboutus_over.gif'
		,'/images/nav/nav_stuff_over.gif'
		);

}

function openWindow(url, winName, winOptions)
{
	var winRef = window.open(url, winName, winOptions);
	winRef.focus();
	return winRef;
}

function openWindowByProfile(profileName, url)
{
	switch (profileName) {
		case "photo_gallery" :
			openWindow('http://www.pinecove.com/photo-gallery/','photoGallery','toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=660,height=530')
			break;

		case "donate_undes" : 
			openWindow('http://www.pinecove.com/commerce/development_client_undes.php','donate','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=no,width=465,height=550');
			break;

		case "donate_pref" : 
			openWindow('http://www.pinecove.com/commerce/development_client_pref.php','donate','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=no,width=417,height=600');
			break;

		case "donate_friends" : 
			openWindow('http://www.pinecove.com/commerce/development_client_friends.php','donate','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=no,width=465,height=550');
			break;

		case "activity" : 
			if ( url ) {
				openWindow(url,'activity','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=no,resizable=no,width=420,height=565');
			}
			break;
		
		case "activity_css" : 
			if ( url ) {
				openWindow(url,'activity','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=no,resizable=no,width=400,height=560');
			}
			break
		
		case "dates_pricing" : 
			if ( url ) {
				openWindow(url,'dates_pricing','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,height=645,width=420');
			}
			break;
		
		case "dates_pricing2" : 
			if ( url ) {
				openWindow(url,'dates_pricing2','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,height=645,width=479');
			}
			break;
		
		case "theme_night" : 
			if (url)
				openWindow(url,'theme_night','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,height=760,width=388');
			break;
			
		case "theme_night_w" : 
			if (url)
				openWindow(url,'theme_night','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,height=597,width=553');
			break;	
				
		case "shores_comp" : 
			if ( url ) {
				openWindow(url,'shores_comp','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=no,resizable=yes,height=670,width=462');
			}
			break;
		
		case "photo_gallery_indiv" : 
			if ( url ) {
				openWindow(url,'photo_gallery_indiv','toolbar=no,menubar=no,scrollbars=no,resizable=yes,width=640,height=530');
			}
			break;
		
		case "reg_section_default" : 
			if ( url ) {
				openWindow(url,'reg_popup','toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,height=640,width=400');
			}
			break;
		case "reg_section_print" : 
			if ( url ) {
				openWindow(url,'reg_popup','toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,height=600,width=500');
			}
			break;
	}
}

function resizeSelfByProfile(profileName)
{

	switch (profileName)
	{
		case "theme_night" : 
			// add 12 to width and 93 to height for resize to work
			self.resizeTo(400,853);
			break;

		case "theme_night_w" : 
			self.resizeTo(565,690);
			break;	
	}
}

function popupVideoByNum(videoNum)
{
	/*
	 * videoNum:string - num of video to open
	 */

	openWindow('/video/videoPopup.cfm?videoNum=' + videoNum,'video','height=445,width=462,scrollbars=no,resizable=yes,location=no');
}



function hideShowById(id)
{
	elem = document.getElementById(id);
	if( elem ) {
		elem.style.display = elem.style.display == 'block' ? 'none' : 'block';        
	}       
}




//----------------------------------------------------------------------------------------------
// LEGACY - not to be used for new development
//----------------------------------------------------------------------------------------------

// Macromedia Dreamweaver
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function injectSWF(profile, divID, swfPath)
{
	if ( swfobject && swfobject.embedSWF && swfobject.hasFlashPlayerVersion ) {
		if (swfobject.hasFlashPlayerVersion("7.0.0")) {
			switch ( profile ) {
				case "mainlg" :
					swfobject.embedSWF(swfPath, divID, "445", "370", "7.0.0");
					break;

				case "mainsg" :
					swfobject.embedSWF(swfPath, divID, "445", "185", "7.0.0");
					break;
				
				case "homepage_left" :
					swfobject.embedSWF(swfPath, divID, "422", "345", "7.0.0");
					break;

				case "homepage_right" :
					swfobject.embedSWF(swfPath, divID, "287", "345", "7.0.0");
					break;
					
				case "activ_popup" :
					swfobject.embedSWF(swfPath, divID, "400", "225", "7.0.0");
					break;
			}
		}

		else {
			document.getElementById(divID + "-alt").style.display = 'block';	
		}
	}

	else {
		document.getElementById(divID + "-alt").style.display = 'block';	
	}
}



//----------------------------------------------------------------------------------------------
// Setup global PC object
//----------------------------------------------------------------------------------------------

var PC = PC || {};
PC.namespace = function (ns_string) {
	var parts = ns_string.split('.')
		,parent = PC
		,i;

	// strip redundant leading global
	if (parts[0] === "PC") {
		parts = parts.slice(1);
	}

	for (i = 0; i < parts.length; i += 1) {
		// create a property if it doesn't exist
		if (typeof parent[parts[i]] === "undefined") {
			parent[parts[i]] = {};
		}
		parent = parent[parts[i]];
	}
	return parent;
};


if (window.jQuery) {
//----------------------------------------------------------------------------------------------
// PC.main - catch-all module
//----------------------------------------------------------------------------------------------
PC.namespace('PC.main');
PC.main = (function() {
	var my = {}; // public interface

	//console.log("PC.main initialized.");

	my.preloadImages = function() { //v3.0 from Macromedia Dreamweaver
		var d=document;
		if (d.images) {
			if (!d.MM_p) {
				d.MM_p=new Array();
			}
			var i
			  ,j=d.MM_p.length
			  ,a=arguments;
			for (i=0; i<a.length; i++) {
				if (a[i].indexOf("#")!=0) {
					d.MM_p[j]=new Image;
					d.MM_p[j++].src=a[i];
				}
			}
		}
	}


	return my;
})();

//----------------------------------------------------------------------------------------------
// PC.main.flashalt - Site Feature: Flash Alternative
//----------------------------------------------------------------------------------------------
PC.namespace('PC.main.flashalt');
PC.main.flashalt = (function() {
	var my = {}; // public interface

	// private methods
	function hasFlash() {
		if (typeof swfobject != 'undefined'
			&& typeof swfobject.hasFlashPlayerVersion != 'undefined'
			&& swfobject.hasFlashPlayerVersion("7.0.0")) {

			return true;
		}
		return false;
	}

	function showFlashAlternative() {
		if (!hasFlash()) {
			$(".hasflash").hide();
			$(".noflash").show();
		}
	}

	// public methods
	my.init = function(){
		if (window.swfobject) {
			showFlashAlternative();
		}
		else {
			$.getScript('/scripts/swfobject.js',showFlashAlternative);
		}
	};
	
	//console.log("PC.main.flashalt initialized.");

	return my;
})();

//----------------------------------------------------------------------------------------------
// PC.main.fader - Site Feature: DIV/Image Fader
//----------------------------------------------------------------------------------------------
PC.namespace('PC.main.fader');
PC.main.fader = (function() {
	var my = {}; // public interface

	// private properties
	// times are in milliseconds
	var faderDefaultRotateInterval = 4000;
	var faderTransitionInterval = 600;
	
	// private methods
	function getTransitionDuration(elem) {
		// elem: should be a reference to an element (li maybe) that has a class of durationX

		//parse duration
		if (elem.hasClass('duration1'))
			return 1000;

		else if (elem.hasClass('duration2'))
			return 2000;

		else if (elem.hasClass('duration3'))
			return 3000;

		else if (elem.hasClass('duration4'))
			return 4000;

		else if (elem.hasClass('duration5'))
			return 5000;

		else if (elem.hasClass('duration6'))
			return 6000;

		else if (elem.hasClass('duration7'))
			return 7000;

		else if (elem.hasClass('duration8'))
			return 8000;

		else if (elem.hasClass('duration9'))
			return 9000;

		else if (elem.hasClass('duration10'))
			return 10000;

		else
			return 0;
	}

	my.fade = function() {
		//Get the first image
		var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

		//Get next image, when it reaches the end, fade it back to the first image
		var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));

		//Set the fade in effect for the next image, the show class has higher z-index
		next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, faderTransitionInterval);

		//Hide the current image
		current.animate({opacity: 0.0}, faderTransitionInterval)
		.removeClass('show');

		// get duration for this list item
		var rotateDelay = getTransitionDuration(next);
		if (rotateDelay <= 0)
			rotateDelay = faderDefaultRotateInterval;

		// pseudo-recursively call fade()
		setTimeout('PC.main.fader.fade()', rotateDelay);
	}

	my.init = function() {
		//Set the opacity of all images (exect the first) to 0
		$('div#rotator ul li:not(:first)').css({opacity: 0.0});

		//Get the first image and display it (gets set to full opacity)
		$('div#rotator ul li:first').css({opacity: 1.0});

		//get duration for the first item in the list
		var rotateDelay = getTransitionDuration($('div#rotator ul li:first'));
		if (rotateDelay <= 0)
			rotateDelay = faderDefaultRotateInterval;

		//Call the fade function to run the slideshow (note: fade() will repeatedly call itself via setTimeout)
		setTimeout('PC.main.fader.fade()', rotateDelay);
	}

	return my;
})();

//----------------------------------------------------------------------------------------------
// PC.main.homead - Site Feature: Home Ad Rotator
//----------------------------------------------------------------------------------------------
/**
 *
 * Instructions: Give the large graphic an id of "homead_large_img" and the links surrounding the thumb
 * a class of "homead_link_small" and an id of "homead_linkN" (where N is usually 1-3).  Create a hidden
 * span below each homead_link whose HTML is the src of the related large graphic.
 *
 */
PC.namespace('PC.main.homead');
PC.main.homead = (function() {
	var my = {}; // public interface

	// private properties
	var homeAdMainSrc="";
	
	// private methods
	function rotateHomeAd(link) {
		var largeVerFileName = getLargeVerFileName(link.id);
		$('#homead_large_img').attr('src', largeVerFileName);
	}

	function resetHomeAd() {
		$('#homead_large_img').attr('src', homeAdMainSrc);
	}

	function getLargeVerFileName(linkID) {
		var seqNum = linkID.replace('homead_link', '');
		return $("#homead_large_img_src" + seqNum).html();
	}

	my.init = function() {
		// need to backup main home ad img src
		homeAdMainSrc = $('#homead_large_img').attr('src');

		// setup handlers
		var thumb = $('.homead_link_small');

		thumb.mouseover( function() {
			rotateHomeAd(this);
		});

		thumb.mouseout( function() {
			resetHomeAd()
		});

		// preload the large image of each thumb
		thumb.each( function() {
			var largeVerFileName = getLargeVerFileName(this.id);
			if (PC.main.preloadImages) {
				PC.main.preloadImages(largeVerFileName);
			}
		});

	}
	return my;

})();

//----------------------------------------------------------------------------------------------
// PC.main.expandableSections - Site Feature: Expandable Section
//----------------------------------------------------------------------------------------------
PC.namespace('PC.main.expandableSections');
PC.main.expandableSections = (function() {
	var my = {}; // public interface

	// private methods
	my.init = function() {
		// If an expandable-section doesn't have the expanded class, give it the collapse class.
		$('.expandable-section:not(.expanded)').addClass('collapsed');
	
		//Switch section from expanded to collapsed and vice versa when it's control is clicked.
		$('.es-control').click(function(){
			$(this).parent().toggleClass('expanded collapsed');
		});	
	}

	return my;

})();


//----------------------------------------------------------------------------------------------
// PC.main.thumbshow - Site Feature: Thumbshow
//----------------------------------------------------------------------------------------------
PC.namespace('PC.main.thumbshow');
PC.main.thumbshow = (function() {
	var my = {}; // public interface

	// private methods
	my.init = function() {
		$('.thumbshow-links a').click(function(){
			var thumbShowContent = $(this).find('.thumbshow-content').val();			
			$(this).parent().siblings('.thumbshow-slot').find('iframe').hide();
			$(this).parent().siblings('.thumbshow-slot').html(thumbShowContent).show();
		});
	}

	return my;

})();


//----------------------------------------------------------------------------------------------
// PC.main.donateWidget - Site Feature: Donate Widget
//----------------------------------------------------------------------------------------------
PC.namespace('PC.main.donateWidget');
PC.main.donateWidget = (function() {
	var my = {}; // public interface

	// private methods
	my.init = function() {
		$('#gift1_des').change(function() { //When the designation select input changes,
		  $('.givdetail').hide(); //hide all "givdetail" rows.
		  var gift1Des = $(this).val(); //Get the value of the select option.
		  $('.' + gift1Des).show(); //Show any givdetail row with a class that matches the select option's value.
		});
	}

	return my;

})();



} // end if window.jQuery

