function toggle(div) 
{
	var elem = document.getElementById(div);
    if (elem.style.display=='') {elem.style.display='none'; return;}
    elem.style.display='';
}

function pitch_mouse_over(id, min, max)
{
	intro_animate_stop();
	pitch_switch(id, min, max);
}

function pitch_mouse_out()
{
	intro_animate_start();
}

function pitch_switch(id, min, max) 
{
	for (i=min;i<=max;i++) {
		if(document.getElementById('tabdiv' + i) != null)
			document.getElementById('tabdiv' + i).style.display = 'none';		
	}
	
	document.getElementById('tabdiv' + id).style.display = 'block';
	intro_current = id;
}

var intro_timer = 0;
var intro_current = 1;
var intro_last = 1;
var intro_min = 0;
var intro_max = 0;
function intro_animate_start()
{
	if(intro_timer) 
	{
		clearTimeout(intro_timer);
		intro_timer = 0;
	}
	
	intro_timer = setTimeout("intro_animate()", 3000);
}

function intro_animate_stop()
{
	if(intro_timer) 
	{
		clearTimeout(intro_timer);
		intro_timer = 0;
	}
}

function intro_animate()
{
	gblImageRotations = gblDeckSize * (gblRotations+1);
	intro_current++;
	for(i=intro_min; i<intro_max; i++)
	{
		if(intro_current >intro_max)
			intro_current = intro_min;
		
		if(document.getElementById('tabdiv'+intro_current))
		{
			//pitch_switch(intro_current, intro_min, intro_max);
			photoShufflerFade();
			//intro_animate_start();
			return;
		}
		intro_current++;
	}
}

var faderTime = 0;

var gblPauseSeconds = 3;
var gblFadeSeconds = .85;
var gblRotations = 1;

// End Customization section

var gblDeckSize;
var gblOpacity = 100;
var gblOnDeck = 0;
var gblStartImg;
var gblImageRotations;

function photoShufflerFade()
{
	//document.getElementById('pitch').style.background = 'url(' + document.getElementById('tabdivimg'+intro_last).src + ') -1px 0px';
	//document.getElementById('backimage').src = document.getElementById('tabdivimg'+intro_last).src;
	
	var theimg = document.getElementById('tabdiv'+intro_current);
	my_setOpacity(theimg, 0);
	pitch_switch(intro_current, intro_min, intro_max);
	
	// determine delta based on number of fade seconds
	// the slower the fade the more increments needed
	var fadeDelta = 100 / (30 * gblFadeSeconds);

	// fade top out to reveal bottom image
	if (gblOpacity < 2*fadeDelta ) 
	{
		gblOpacity = 100;
		// stop the rotation if we're done
		if (gblImageRotations < 1) return;
		//photoShufflerShuffle();
		// pause before next fade
		intro_last = intro_current;
		intro_animate_start();
	}
	else
	{
		gblOpacity -= fadeDelta;
		my_setOpacity(theimg,gblOpacity);
		setTimeout("photoShufflerFade()",30);  // 1/30th of a second
	}
}

function my_setOpacity(obj, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;
	opacity = 100 - opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

scrollStep=4

timerLeft=""
timerRight=""
timerTop=""
timerBottom=""

function toLeft(id){
  document.getElementById(id).scrollLeft=0
}

function scrollDivLeft(id){
  clearTimeout(timerRight)
  document.getElementById(id).scrollLeft+=scrollStep
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10)
}

function scrollDivRight(id){
  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft-=scrollStep
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10)
}

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollHeight
}

function toTop(id){
  document.getElementById(id).scrollTop=0
}

function scrollDivTop(id){
  clearTimeout(timerBottom)
  document.getElementById(id).scrollTop+=scrollStep
  timerBottom=setTimeout("scrollDivTop('"+id+"')",10)
}

function scrollDivBottom(id){
  clearTimeout(timerTop)
  document.getElementById(id).scrollTop-=scrollStep
  timerTop=setTimeout("scrollDivBottom('"+id+"')",10)
}

function toBottom(id){
  document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}

function stopMe(){
  clearTimeout(timerRight)
  clearTimeout(timerLeft)
  clearTimeout(timerTop)
  clearTimeout(timerBottom)
}

var gallery_action = false;
function gallery_move(id, cnt, dir, w, m)
{
	if(gallery_action)
		return;
		
	w = (w) ? w : 200;
	m = (m) ? m : 10;
	
	var curr = document.getElementById("gallery-"+id+"-holder").style.left;
	curr = parseFloat(curr);

	if(isNaN(curr))
		curr = 0;
	if(dir > 0)
	{
		if(curr >= 0)
			return;
	}
	else
	{
		if(curr + cnt * (w + m*2) - (300 / w) * (w + m*2) <= 0)
			return;
	}

	gallery_action = true;
	var offset = w+m;

	if(dir < 0)
		dir = "-";
	else
		dir = "+";
		
	$("#gallery-"+id+"-holder").animate(
		{left : dir+"="+offset+"px"},
		{queue:true, duration:100, complete: function() {gallery_action = false;}}
	);
}
