
// Retrieve the rendered height of an element
function getObjectHeight(obj) {
    var elem = $(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

// COMMISSIONERs PAGE -------------
var last = '';
function showcomm(ID){
	if (last != ''){
		$('cc'+last).style.display = 'none';
		$('name'+last).style.color = '#707052';
		$('title'+last).style.color = '#707052';
	}
	$('cc'+ID).style.display = 'block';
	$('name'+ID).style.color = '#371A53';
	$('title'+ID).style.color = '#371A53';
 	last = ID;
}


// ORDER FORM

function clearblank(field,value){
	if (field.value == value){
		field.value = '';
		field.style.color = '#555';
	}
}

function verifyOrderForm(leform){
	validemail = validateEmail(leform.email.value);
	if (leform.name.value == '' || leform.name.value  == 'Enter Name'){
		alert('Please enter your name.')
		leform.name.focus();
		return false;
	} else if (leform.email.value  == '' || leform.email.value  == 'Email'){
		alert('Please enter your email address');
		leform.email.focus();
		return false;
	} else if (!validemail) {
		alert('The email address you have entered is not valid');
		leform.email.focus();
		return false;
	} else {
		return true; // good to go!
	}
}


function validateEmail(email) {
	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".")
	if (AtPos == -1 || StopPos == -1) {
		return false;
	} else if (StopPos < AtPos) {
		return false;
	} else if (StopPos - AtPos == 1) {
		return false;
	} else if (AtPos == 0) {
		return false;
	}  else if (StopPos == (email.length -1)) {
		return false;
	} else {
		return true; // good to go!
	}
}




// NAVIGATION PAGE -------------

var lastnav = '';

function overSubNav(subnav,tabnum,atag){
	openSubNav(subnav);
	atag.childNodes[2].style.display = 'block';
	atag.childNodes[1].style.display = 'none';
}

function outSubNav(subnav,tabnum,atag){
	closeSubNav(subnav);
	atag.childNodes[1].style.display = 'block';
	atag.childNodes[2].style.display = 'none';
}

function openSubNav(id){
	$(id).closeit = false;
	if ($(id).style.display=='none' && ! $(id).moving){
		$(id).moving = true;
		if (lastnav != ''){
			$(lastnav).moving = false;
			$(lastnav).style.display='none';
			$(lastnav).style.height='400px';
		}
		lastnav = id;
		if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent)){
		Effect.BlindDown(id,{duration:0.6, transition:Effect.Transitions.EaseFromTo, afterFinish:function(){
			$(id).moving = false;
		}});
		} else { // IE 6, no nav animation
			$(id).style.display = 'block';
			$(id).moving = false;
		}
	}
}
function closeSubNav(id){
	$(id).closeit = true;
	window.setTimeout("AcloseSubNav('"+id+"')",10);
}

function AcloseSubNav(id){
	if ($(id).moving){
		window.setTimeout("AcloseSubNav('"+id+"')",10);
	} else if($(id).closeit){
		/*
		$(id).moving = true;
		Effect.BlindUp(id,{duration:0.6, transition:Effect.Transitions.EaseFromTo, afterFinish:function(){
			$(id).moving = false;
			$(id).style.display='none';
			$(id).style.height='400px';
		}});
		*/
		$(id).moving = false;
		$(id).style.display='none';
		$(id).style.height='400px';
	}
}

function gotoit(page){
	location.href = page;
/*
	images = $$('img.img');
	if(images.length > 0){
		images.each(function(image) {
		 	new Effect.Shrink(image, {direction:'center', duration:0.3});
		});
	}
	fadepage(page);
	*/
}

function fadepage(page){
	new Effect.Fade('content',{duration:0.3, afterFinish: function(){
		change(page);
	}});
}

function change(page){
	if (page.indexOf('?') == -1){
		url = page+'?ajax=1';
	} else {
		url = page+'&ajax=1';
	}
	new Ajax.Updater('content', url, {asynchronous:true, evalScripts:true});
	window.setTimeout("inn()",500);
}

function inn(){
	new	Effect.Appear('content',{duration:0.3});
}

function popit(){
	images = $$('img.img');
	if(images.length > 0){
		images.each(function(image) {
		 		new Effect.Grow(image, {duration:0.5});
		});
	} 
}

function reservechute(){
	if (!gone){
		gotime();
	}
}

function gotime(){
	gone = true;
	new Effect.Grow('mainmenu', {direction:'left', duration:1, afterFinish: gotime2 });
}

function gotime2(){
	new Effect.BlindDown('contentbg',{duration:0.5, afterFinish: gotime3});
}
function gotime3(){
	// $('dribble').style.display = 'block';
	// $('game').style.visibility = 'hidden';
	$('foot_menu').style.display = 'block';
	new Effect.Grow('piece1', {direction:'top-right', duration:0.5});
	new Effect.Grow('piece2', {direction:'top-right', duration:0.5, afterFinish: gotime4});
}
function gotime4(){
	new Effect.Grow('clip', {direction:'top-right', duration:0.3, afterFinish: gotime5});
}
function gotime5(){
	$('foot_menu').style.display = 'block';
	new Effect.Grow('eatyourberries', {direction:'left', duration:1, transition:Effect.Transitions.Bounce });
}

/********** OVERFLOW SCROLLING ************/


function checkflow(ID){
	if($('verso'+ID+'h')){
		if(getObjectHeight('verso'+ID+'mask') > 0 && getObjectHeight('verso'+ID+'h') > 0){
			$('verso'+ID+'mask').style.height = getObjectHeight('verso'+ID+'mask') - getObjectHeight('verso'+ID+'h') + 'px';
		}
	}
	if( getObjectHeight('hd'+ID) > getObjectHeight('verso'+ID+'mask')) {
		$('arwd'+ID).style.display = 'block';
		if (parseInt($('hd'+ID).style.top) < 0){ // check if we need the up arrow
			$('arwu'+ID).style.display = 'block';
		} else {
			$('arwu'+ID).style.display = 'none';
		}
	} else {
		$('arwd'+ID).style.display = 'none';
		$('arwu'+ID).style.display = 'none';
	}
}

function overflow(ID){
	$('arwd'+ID).style.display = 'block';
}


function scrollme(ID,dir,what){
	scroller = $('hd'+ID);
	box = $('verso'+ID);
	if (dir == 'd'){
		moveamt =  -24;
	} else {
		moveamt = 24;
	}
	if (what == 'start'){
		scroller.moveit = true;
		scrolling(scroller,moveamt,box,ID);
	} else {
		scroller.moveit = false;
	}
}

function scrolling(scroller,moveamt,box,ID){
	new Effect.Move (scroller,{duration:0.1, x: 0, y: moveamt, mode: 'relative', afterFinish: function(){
		if (scroller.moveit){
			scrolling(scroller,moveamt,box,ID);
		}
	}});
	current = parseInt(scroller.style.top);
	boxh = parseInt(box.style.height)-40;
	scrollerh = getObjectHeight(scroller);
	if ((scrollerh + current + moveamt) < boxh){ // check if arrows should still show
		$('arwd'+ID).style.display = 'none';
		scroller.moveit = false;
	} else {
		$('arwd'+ID).style.display = 'block';
	}
	if ((current + moveamt) < 0){ // check if arrows should still show
		$('arwu'+ID).style.display = 'block';
	} else {
		$('arwu'+ID).style.display = 'none';
		scroller.moveit = false;
	}
}


function togg(id){
	if ($(id).style.display == 'block'){
		$(id).style.display = 'none';
	} else { 
		$(id).style.display = 'block';
	}
}


/********** MOUSE OVER  EFFECTS ************/


var mm = false;

function growit(id){
	if (mm == false){
		mm = true;
		new Effect.Scale(id,110,{scaleX: true, scaleY: true, scaleFromCenter:true, duration:0.15, afterFinish:function(){
			new Effect.Scale(id,90.909090990, {scaleX:true, scaleY:true, scaleFromCenter:true, duration:0.15});
		}});
	}
	window.setTimeout("mm=false",500);
}

function stretchit(id){
	if (mm == false){
		mm = true;
		new Effect.Scale(id,110,{scaleX: true, scaleY: false, scaleFromCenter:true, duration:0.15, afterFinish:function(){
			new Effect.Scale(id,90.909090990, {scaleX:true, scaleY:false, scaleFromCenter:true, duration:0.15});
			new Effect.Scale(id,110,{scaleX: false, scaleY: true, scaleFromCenter:true, duration:0.15, afterFinish:function(){
				new Effect.Scale(id,90.909090990, {scaleX:false, scaleY:true, scaleFromCenter:true, duration:0.15});
		}});
		}});
	}
	window.setTimeout("mm=false",500);
}



/***************************************************/


function showeit(who){
	new Ajax.Updater($(who), 'common/ajax/email_action.cfm?who='+who, {asynchronous:true, evalScripts:true});
}



var gone = false;
window.setTimeout("reservechute();",1500); // changed to 1.5 sec instead of 9