// == METHODS FOR VIDEO PLAYER ===========================

function playVid(urlName){
ytplayer2 = document.getElementById("myytplayer");
ytplayer2.loadVideoById(urlName);
}//end playVid funtion

jsIndex = 1
iScroll = 0;

function nextVid() {
if(jsIndex >= (iValue -2) ){

}else {
jsIndex ++ ;
iScroll = iScroll - 68;
var objElem = document.getElementById("scrollArea");
objElem.style.top = (iScroll) + "px";
}
}


function previousVid() {
if(jsIndex <= 1){

}else{
jsIndex -- ;
iScroll = iScroll + 68;
var objElem = document.getElementById("scrollArea");
objElem.style.top = (iScroll) + "px";
}
}


// == FIELD VALIDATION ===================================

function validate_for(type, string)
{
	// cc check is generic.  use full `isValidCreditCard` function for more control.
	
	var re;
	if(type=='url') { re = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/; }
	else if(type=='email') { re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/ }
	else if(type=='phone') { re = /^\(\d{3}\) ?\d{3}( |-)?\d{4}|^\d{3}( |-)?\d{3}( |-)?\d{4}/ }
	else if(type=='zip') { re = /^((\d{5}-\d{4})|(\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d))$/ }
	else if(type=='money') { re = /^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.\d{1,2}?)$/ }
	else if(type=='cc') { re = /^((4\d{3})|(5[1-5]\d{2}))(-?|\040?)(\d{4}(-?|\040?)){3}|^(3[4,7]\d{2})(-?|\040?)\d{6}(-?|\040?)\d{5}/ }
	return (re.test(string));
}

// == INCLUDE DEBUG CSS ===================================
if (window.location.href.indexOf('debug')>0)
{
	document.write('<link rel="stylesheet" type="text/css" media="screen" href="/css/debug.css" />');
}

// == COOKIE METHODS (thx to PPK @ Quirksmode.org) ========
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
// ========================================================

$(document).ready(function(){
	if($('body#home')[0])
	{
		// we're on the homepage. do some stuff
		
		// ... like embed the youtube flash
		var params = {};
		var atts = { id: "myytplayer" };
		params.allowscriptaccess    = 'always';
		params.wmode   = 'window';
		params.allowFullScreen = 'true';
		swfobject.embedSWF("http://www.youtube.com/v/wJltcT7DH7g&hl=en&enablejsapi=1&rel=0&HD=1&fs=1&showinfo=1","ytapiplayer", "640", "385", "8", null, null, params, atts);		
	}
	
	$('dl dd.mail a').click(function(){
		window.open("/mailing-list.php", "mailing", "location=0,status=0,scrollbars=0,width=400,height=460");
		return false;
	});
	
	$('#book button').click(function(){
		window.location.href='mailto:erik@pleasefeedtheanimals.com?subject=Lemonade Essay';
	});
});
