// JavaScript Document

function showEmbedCode() {
	document.getElementById('videoCode').style.display = (document.getElementById('videoCode').style.display=='none') ? 'block' : 'none';
}

navTabs = new Array('photos','takeAction','support');
function showTab(tabId) {
	for (t=0;t<navTabs.length;t++) {
		navTab = document.getElementById('navTab_'+navTabs[t]);
		navImg = document.getElementById('navImg_'+navTabs[t]);
		navImg.className = (navTabs[t]==tabId) ? 'selected' : 'imageSwap';
		navTab.style.display = (navTabs[t]==tabId) ? 'block' : 'none';
		navImg.src = (navTabs[t]==tabId) ? navImg.src.replace('1.','2.') : navImg.src.replace('2.','1.');
	}
	fadeIn('pageContent');
}

function initDefaultTab() {
	defaultTab = navTabs[0];
	if (location.href.indexOf('#')!=-1) defaultTab = location.href.substr(location.href.indexOf('#')+1);
	if (!navTabs.in_array(defaultTab)) defaultTab = navTabs[0];
	showTab(defaultTab);
}
Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

loadMeUp += "initDefaultTab();";

fadeInStepInt = 20;

photoNum = 15;
selectedPhoto = 0;
function postPictureToFacebook() {
	window.open("http://www.facebook.com/share.php?u=http://www.animalsaustralia.org/investigations/broiler-chicken-investigation/?photo="+selectedPhoto,'fbPhotoWin','height=350,width=760,status=yes,resizable=yes,scrollbars=yes');
}

function showPhoto(p) {
	if (p < 0) p = photoNum-1;
	if (p >= photoNum) p = 0;
	selectedPhoto = p;
	for(i=0;i<photoNum;i++) {
		photoTitleEl = document.getElementById('photoTitle_'+i);
		photoDescEl = document.getElementById('photoDesc_'+i);
		photoThumbEl = document.getElementById('photoThumb_'+i);
		newClassName = (i==p) ? 'selected' : '';
		photoTitleEl.className = newClassName;
		photoDescEl.className = newClassName;
		photoThumbEl.className = newClassName;
	}
	// update photo
	photoEl = document.getElementById('featurePhoto');
	photoEl.src = "/images/space.gif";
	photoEl.src = document.getElementById('photoThumb_'+selectedPhoto).src.replace('&x=62&y=62','&o=photo-edge-mask.png');
	// setTimeout("photoEl.src = document.getElementById('photoThumb_'+selectedPhoto).src.replace('&x=62&y=62','&o=photo-edge-mask.png');",10);
	photoEl.title = document.getElementById('photoThumb_'+selectedPhoto).alt;
	
	// show position
	photoNavEl = document.getElementById('photoInt');
	photoNavEl.innerHTML = (p+1)+' of '+photoNum;
}

function nextPhoto() {
	showPhoto(selectedPhoto+1);
}
function prevPhoto() {
	showPhoto(selectedPhoto-1);
}
function enlargePhoto() {
	photoUrl = document.getElementById('featurePhoto').src.replace("&o=photo-edge-mask.png",'');
	photoUrl = photoUrl.replace("/resources/resample.php?i=",'');
	window.open(photoUrl);
}

// preload the photo frame first
newImage("/investigations/broiler-chicken-investigation/images/photoframe.gif");
newImage("/investigations/broiler-chicken-investigation/images/chickens-dark.jpg");
newImage("/investigations/broiler-chicken-investigation/images/broiler-chickens.jpg");
newImage("(/investigations/broiler-chicken-investigation/images/nav-bg.jpg");





happyPhotoNum = 4;
selectedHappyPhoto = 1;
function showHappyPhoto(hp) {
	if (hp < 1) hp = happyPhotoNum;
	if (hp > happyPhotoNum) hp = 1;
	selectedHappyPhoto = hp;
	for(i=1;i<=happyPhotoNum;i++) {
		photoEl = document.getElementById('happyPic'+i);
		photoDescEl = document.getElementById('happyCaption'+i);
		newClassName = (i==hp) ? 'selected' : '';
		photoEl.className = newClassName;
		photoDescEl.className = newClassName;
	}
}
function nextHappyPhoto() {
	showHappyPhoto(selectedHappyPhoto+1);
}
function prevHappyPhoto() {
	showHappyPhoto(selectedHappyPhoto-1);
}

function checkPledge() {
	p = document.pledgeForm.pledge;
	pledgeValue = '';
	for(i=0;i<p.length;i++) {
		if (p[i].checked) {
			pledgeValue = p[i].value;
			break;
		}
	}
	document.getElementById('pledgeOtherText').style.display = (pledgeValue=='Other') ? 'none' : 'inline';
	document.getElementById('pledgeOtherValue').style.display = (pledgeValue=='Other') ? 'inline' : 'none';
	if (pledgeValue=='Other') {
		pledgeValue = document.pledgeForm.pledgeOtherValue.value;
		if (pledgeValue != (1*(pledgeValue))) {
			pledgeValue = 10;
		}
		if (pledgeValue < 10) {
			alert("Please enter a value of $10 or more.");
			pledgeValue = 10;
		}
		document.pledgeForm.pledgeOtherValue.value = pledgeValue;
	}
}

function submitPledge() {
	p = document.pledgeForm.pledge;
	pledgeValue = '';
	for(i=0;i<p.length;i++) {
		if (p[i].checked) {
			pledgeValue = p[i].value;
			break;
		}
	}
	if (pledgeValue=='Other') {
		pledgeValue = document.pledgeForm.pledgeOtherValue.value;
	}
	window.location = "/support/monthly_giving.php?donation_value="+pledgeValue;
}





					 
