var resetCal;
var myDiv;

var errFunc = function(t) {
    alert('Error ' + t.status + ' -- ' + t.statusText);
}

var handlerFunc = function(t) {
	$('scrollable2').innerHTML = t.responseText;
	new Effect.Appear('scrollable2', {duration:0.5});
	new Effect.Opacity('snake', {to:0, duration:0.5});
	setTimeout("loadscroller()", 1000);
}

function makeRequest(url, wait, myimage, folder, namer, lurl) {
	if (url.indexOf('?') >0) {
		url = url + '&embed=1';
	} else {
		url = url + '?embed=1';
	}
	if (!wait) {
		wait = 0;
	}
	
	if (myimage) {
		setTimeout("new Effect.Opacity('cal', {to:0, duration:0.25});", wait);
		setTimeout("new Effect.Opacity('photoimage', {to:0, duration:0.25});", wait);
		setTimeout("new Effect.Opacity('bottom_leftimage', {to:0, duration:0.25});", wait);
		setTimeout("$('photoimage').src='/media/gui/null.gif';", wait+300);	
		setTimeout("$('bottom_leftimage').src='/media/gui/null.gif';", wait+300);	
		setTimeout("$('photoimage').src='/media/"+folder+"/top"+myimage+"';", wait+310);	
		setTimeout("$('bottom_leftimage').src='/media/"+folder+"/bot"+myimage+"';", wait+310);
	}
	
	setTimeout("new Effect.Opacity('snake', {to:1, duration:0.25});", wait);
	setTimeout("new Effect.Opacity('scrollable2', {to:0, duration:0.25});", wait);
	setTimeout("new Effect.Opacity('wrap3', {to:0.1, duration:0});", wait);
	setTimeout("$('scrollable2').scrollTop=0;", 240+wait);
	setTimeout("new Ajax.Request('"+url+"', {method:'get', postBody:'', onSuccess:handlerFunc, onFailure:errFunc});", 250+wait);
	setTimeout("loadscroller()", 250+wait);
	
	if (namer) {
		$('namer').innerHTML = namer;
	}
	if (lurl) {
		var thisLURL = "&nbsp;&nbsp;&nbsp;<a href='"+lurl+"' target='_blank'><img src='/media/icons/linkedin.gif' width='16' height='16' border'0'></a>";
		$('namer').innerHTML = $('namer').innerHTML + thisLURL;
	}
}

function makeMenuRequest(url, wait, myimage, folder, namer) {
	if (url.indexOf('?') >0) {
		url = url + '&embed=1';
	} else {
		url = url + '?embed=1';
	}
	if (!wait) {
		wait = 0;
	}
	
	setTimeout("new Effect.Opacity('photoimage', {to:0, duration:0.25});", wait);
	setTimeout("new Effect.Opacity('bottom_leftimage', {to:0, duration:0.25});", wait);
	setTimeout("$('photoimage').src='/media/gui/null.gif';", wait+300);	
	setTimeout("$('bottom_leftimage').src='/media/gui/null.gif';", wait+300);	
	
	setTimeout("new Effect.Opacity('snake', {to:1, duration:0.25});", wait);
	setTimeout("new Effect.Opacity('scrollable2', {to:0, duration:0.25});", wait);
	setTimeout("new Effect.Opacity('wrap3', {to:0.1, duration:0});", wait);
	setTimeout("$('scrollable2').scrollTop=0;", 240+wait);
	setTimeout("new Ajax.Request('"+url+"', {method:'get', postBody:'', onSuccess:handlerFunc, onFailure:errFunc});", 250+wait);
	setTimeout("new Ajax.Request('/services/menuqimp.htm', {method:'get', postBody:'', onSuccess:handlerMenuFunc, onFailure:errFunc});", 500+wait);
	setTimeout("loadscroller()", 250+wait);
	
	if (namer) {
		$('namer').innerHTML = namer;
	}
}

function makeSubMenuRequest(url, wait, myimage, folder, namer) {
	if (url.indexOf('?') >0) {
		url = url + '&embed=1';
	} else {
		url = url + '?embed=1';
	}
	if (!wait) {
		wait = 0;
	}
	
	setTimeout("new Effect.Opacity('snake', {to:1, duration:0.25});", wait);
	setTimeout("new Effect.Opacity('scrollable2', {to:0, duration:0.25});", wait);
	setTimeout("new Effect.Opacity('wrap3', {to:0.1, duration:0});", wait);
	setTimeout("$('scrollable2').scrollTop=0;", 240+wait);
	setTimeout("new Ajax.Request('"+url+"', {method:'get', postBody:'', onSuccess:handlerFunc, onFailure:errFunc});", 250+wait);
	setTimeout("loadscroller()", 250+wait);
	
	if (namer) {
		$('namer').innerHTML = namer;
	}
}

var handlerMenuFunc = function(t) {
	$('cal').innerHTML = t.responseText;
	setTimeout("new Effect.Appear('cal', {duration:0.25});", 100);
}

function makeCalRequest(url, wait) {	
	if (url.indexOf('?') >0) {
		url = url + '&embed=1';
	} else {
		url = url + '?embed=1';
	}
	if (!wait) {
		wait = 0;
	}
	setTimeout("new Effect.Opacity('snake', {to:1, duration:0.25});", wait);
	setTimeout("new Effect.Opacity('cal', {to:0, duration:0.25});", wait);
	setTimeout("new Ajax.Request('"+url+"', {method:'get', postBody:'', onSuccess:handlerCalFunc, onFailure:errFunc});", 250+wait);
}

var handlerCalFunc = function(t) {
	$('cal').innerHTML = t.responseText;
	setTimeout("new Effect.Appear('cal', {duration:0.5});", 100);
	setTimeout("new Effect.Opacity('snake', {to:0, duration:0.5});", 200);
}

function makePostRequest() {	
	new Effect.Opacity('snake', {to:1, duration:0.25});
	new Effect.Opacity('scrollable2', {to:0, duration:0.25});
	new Effect.Opacity('wrap3', {to:0, duration:0.25});
	$('scrollable2').scrollTop=0;
	
	myPostBody = "UNAME=" + document.frmComment.UNAME.value;
	myPostBody = myPostBody + "&saveComment=1";
	myPostBody = myPostBody + "&name=" + document.frmComment.name.value;
	myPostBody = myPostBody + "&COMMENT_TEXT=" + document.frmComment.COMMENT_TEXT.value;
	setTimeout("new Ajax.Request('"+document.frmComment.returnlink.value+"', {method:'post', postBody:'"+myPostBody+"', onSuccess:handlerFunc, onFailure:errFunc});", 250);
	setTimeout("loadscroller()", 250);
}

function loadscroller(){
	
	//show by default
	$('wrap3').show();
					
	var slider3 = new Control.Slider('handle3', 'track3', {
		axis: 'vertical',
		onSlide: function(v) { scrollVertical(v, $('scrollable2'), slider3);  },
		onChange: function(v) { scrollVertical(v, $('scrollable2'), slider3); }
	});
	
	// scroll the element vertically based on its width and the slider maximum value
	function scrollVertical(value, element, slider) {
		element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));
	}
			
	// disable vertical scrolling if text doesn't overflow the div
	if ($('scrollable2').scrollHeight <= $('scrollable2').offsetHeight) {
		slider3.setDisabled();
		$('wrap3').hide();
	}
			
	// THESE MUST BE HERE IN ORDER FOR FADES TO WORK
	// USE OPACITY INSTEAD OF FADE/APPEAR FOR IE AND SAFARI
	// DO NOT CHANGE THE ORDER
	new Effect.Opacity('wrap3', {from:1, to:1, duration:0});
	new Effect.Opacity('handle3', {from:1, to:1, duration:0});
	new Effect.Opacity('track3-top', {from:1, to:1, duration:0});
}

var creditson=0;

function credits() {
	if (creditson==0) {
		new Effect.Appear('previewblocker', {to:0.0});
		new Effect.Center('previewblocker');
		setTimeout("new Effect.MoveBy('previewblocker', -50, 0, {duration:0});		new Effect.MoveBy('previewblocker', 50, 0);		new Effect.Appear('previewblocker', {to:0.95});", 100);
	creditson=1;
	}
}

function closecredits() {
	new Effect.MoveBy('previewblocker', -50, 0);
	new Effect.Fade('previewblocker');
	creditson=0;
}

Event.observe(window,'resize', function(){
	new Effect.Center('previewblocker');
});