// JavaScript Document

// JavaScript Document

function initButtons() {
$(function() {
	// color any disabled buttons
	$("#disabled").css("opacity","0.3");
	
	// OPACITY OF BUTTON SET TO 0%
	$(".rollover").css("opacity","0");
	
	// ON MOUSE OVER
	$(".nav_btn").hover(function () {
	
	// SET OPACITY TO 100%
	$(this).find(":nth-child(2)").stop().animate({
	opacity: 0.6
	}, 300);
	},
	
	// ON MOUSE OUT
	function () {
	
		// SET OPACITY BACK TO 50%
		$(this).find(":nth-child(2)").stop().animate({
		opacity: 0
		}, 300);
	});
	
});
}

$(function() {
	initButtons();
});


function switchPage(menuform) {
	var baseurl = "/" ;
    selecteditem = menuform.toPage.selectedIndex ;
    newurl = menuform.toPage.options[ selecteditem ].value ;
    if (newurl.length != 0) {
      location.href = baseurl + newurl ;
    }
	
}

// tooltip
function initTooltips() {
$(function() {
	var tooltip = $('.tooltip');
	tooltip.css("opacity","0");
	$("a[rel]").hover(function() {
		document.getElementById('tooltipMid').innerHTML = this.rel;
		
		x = getOffset(this).left;
		x-= (document.getElementById('tooltip').offsetWidth);
		x-=5;
		y = getOffset(this).top;
		newX = x-10;
		endX = x-20;
		
		tooltip.css("top",y+'px');
		tooltip.css("left",x+'px');
		tooltip.stop().animate({
			opacity: 1.0,
			left: newX
		}, 300);
	   
	},
	
	// ON MOUSE OUT
	function () {
		// SET OPACITY BACK TO 50%
		tooltip.stop().animate({
			opacity: 0,
			left: endX
		}, 300, function(){
					
					tooltip.css("top",'-100%');
					tooltip.css("left",'-100%');
					
				});
	});
});
}

function getOffset( el ) {
    var _x = 0;
    var _y = 0;
    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.offsetParent;
    }
    return { top: _y, left: _x };
}

$(function() {
	initTooltips();
	//mouseInit();
});

var mouseX = 0;
var mouseY = 0;
function mouseInit() {
	//if (window.Event) {
		//document.captureEvents(Event.MOUSEMOVE);
	//}
	document.onmousemove = getCursorXY;
}

function getCursorXY(e) {
	mouseX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	mouseY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}

function boxOn(box,src,frame) {
	document.getElementById(box).style.display='block';
	document.getElementById('fade').style.display='block';
	document.getElementById(frame).setAttribute('src',src);
}
function boxOff(box) {
	document.getElementById(box).style.display='none';
	document.getElementById('fade').style.display='none';
}

function showHide(id) {
	if (document.getElementById(id).style.display='none') {
		document.getElementById(id).style.display='block';
	} else {
		document.getElementById(id).style.display='none';
	}
}

function show(id) {
	document.getElementById(id).style.display='block';
}

function hide(id) {
	document.getElementById(id).style.display='none';
}

$(document).ready(function(){
    $(".scroll").click(function(event){
        //prevent the default action for the click event
        event.preventDefault();
        //get the full url - like mysitecom/index.htm#home
        var full_url = this.href;
        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
        var parts = full_url.split("#");
        var trgt = parts[1];
        //get the top offset of the target anchor
        var target_offset = $("#"+trgt).offset();
        var target_top = target_offset.top;
        //goto that anchor by setting the body scroll top to anchor top
        $('html, body').animate({scrollTop:target_top}, 500);
    });
});

function confirmSubmit() {
	var agree=confirm("Are you sure you wish to continue?");
	if (agree)
		return true ;
	else
		return false ;
}

function goVid(vid) {
	document.getElementById('vid').innerHTML = '<object width="550" height="300"><param name="movie" value="http://www.youtube.com/v/'+vid+'?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+vid+'?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="550" height="300"></embed></object>';
}

var win= null;
function NewWindow(mypage,myname,w,h,scroll){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      //settings +='top='+wint+',';
      //settings +='left='+winl+',';
	  settings +='top=10,';
      settings +='left=10,';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function spawnJukebox() {
	NewWindow('/juke.php','Jeff_Bates_Jukebox','200','150','no');	
}

function theRotator() {
	//Set the opacity of all images to 0
	$('#banner ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('#banner ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',5000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('#banner ul li.show')?  $('#banner ul li.show') : $('#banner ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#banner ul li:first') :current.next()) : $('#banner ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 2000)
	.removeClass('show');
	
};

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});

