// JavaScript Document

var currentlyOpen = 0;
var currentShow = '#bio';
var wantToOpen, showDiv, currentShow;
var player = null;
var currentSong;
var whichRev;

/*// AJAX INIT STUFF -- START
var xmlhttp=null;

try
{
	xmlhttp = new XMLHttpRequest();
}
catch (error)
{
	try
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (error)
	{
		xmlhttp = null;
	}
}
//  END*/

function showSection(){
	if(window.location.hash != '' && window.location.hash != '#home'){ //alert($(".section").index(window.location.hash))
		if(window.location.hash == '#next6' || window.location.hash == '#previous8') window.location.hash = '#music';
		
		wantToOpen = $(".section").index($(window.location.hash).parent().get(0));
		$(".section:eq(" + wantToOpen + ")").animate({width:"+=470"}, 'medium', function(){
			$(window.location.hash).fadeIn('slow');
		});
		currentShow = window.location.hash;
		currentlyOpen = wantToOpen;
		
		$('div.home-reviews span').hide();
	}else{
		$('div.home-reviews span').show();
	}
	$(".navLink").click( function(){ //alert(currentlyOpen);
		wantToOpen = $(".navLink").index(this);
		showDiv = $(this).attr("href"); //alert(currentShow);
		$(currentShow).hide();
		$(".section:eq(" + currentlyOpen + ")").animate({
			width:'80px'
		}, 'medium', function(){
			$(".section:eq(" + wantToOpen + ")").animate({width:"+=470"}, 'medium', function(){
				$(showDiv).fadeIn('slow');
			});
			currentShow = showDiv;
			currentlyOpen = wantToOpen;
			});
		
		$('div.home-reviews span').hide();
	});
}

function backToHome(){
	$(currentShow).hide();
	$(".section:eq(" + currentlyOpen + ")").animate({ width:'80px' }, 'medium');
	currentlyOpen = 0;
	currentShow = '#bio';
	
	$('div.home-reviews span').show();
}

function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
}

function playSong(file){
	if(file != currentSong){
		var musicFile = '/music/' + file + '.mp3'; //alert(musicFile);
		player.sendEvent('LOAD', musicFile);
		currentSong = file;
		player.sendEvent('PLAY');
	}
	player.sendEvent('PLAY');
}

function next6(){
	$("#set1").fadeOut('slow', function(){
		$("#set2").fadeIn('slow');
	});
}

function previous8(){
	$("#set2").fadeOut('slow', function(){
		$("#set1").fadeIn('slow');
	});
}

function rotate(){
	if(whichRev){
		$("div.home-reviews > span").fadeOut(900);
		whichRev = false;
	}else{
		$("div.home-reviews > span").fadeIn(900);
		whichRev = true;
	}
}

function homeReviews(){
	whichRev = true;
	//setInterval('rotate()', 5000);
}

/*function sendContactForm(){
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var comments = document.getElementById('coments').value;
	xmlhttp.open("GET", "ajaxHandler.php?action=sendForm&name=" + name + "&email=" + email + "&comments=" + comments + "&time=" + new  Date().getTime());
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			chart143 = xmlhttp.responseText; //alert(photoElementsString);
		}
	}
	xmlhttp.send(null);
}*/

// starting the script on page load
$(document).ready(function(){
	showSection();
	homeReviews();
	$('.photoGallery a').lightBox();

});
