// foto width
var fotowidth=563;
// foto height
var fotoheight=317;
// choose to switch carousel on (true) of off (false)
var carousel=true;
// set pause before next item
var carspeed=7000;
// set pause for title layer before it goes back down
var titlepause=5000;
// choose how high the title layer should scroll up from the bottom of the the display area
var myendpoint=115;

var oid=0;
function showContent(id) {
	//window.open(myLinks[id])
}
var myThumbs=new Array();var vcontent;var vfoto;var vnxt;var vprv;var vtitle;var vcomp;var vtext;
var timer;var waiting;var strt=true;
var myDivs=new Array();var myThumbs=new Array();var myItems=new Array();var contentnr=0;
function getHomeContent() {
	if (myContent.length > 0) {
		vcontent = document.getElementById('vcontent');
		vfoto = document.getElementById('vfoto');
		vtitle = document.getElementById('vtitle');
		vcomp = document.getElementById('vcomposers');
		vtext = document.getElementById('vtext');
		// generate thumbnails
		var allitems=myContent.length;
		for(var i=0; i < allitems; i++) {
			// numbered blocks for counter
			var cntr=document.getElementById('vcounter');
			var newCounterBlock = document.createElement("DIV");
			newCounterBlock.innerHTML = i+1;	
			newCounterBlock.nr = i;
			newCounterBlock.onclick=function() { moveOver(this.nr); }
			newCounterBlock.id='cntr'+i;
			cntr.appendChild(newCounterBlock);			
		}
		vcontent.style.filter = 'alpha(opacity=0)';
		vcontent.style.MozOpacity = 0;
		vfoto.innerHTML='<img width="'+fotowidth+'" height="'+fotoheight+'" src="'+myContent[0].Foto+'" border="0" />';
		vtitle.innerHTML='<h2><a href="'+myContent[0].Url+'">'+myContent[0].Title+'</a></h2>';
		vcomp.innerHTML='<h3>'+myContent[0].Composers+'</h3>';
		vtext.innerHTML=myContent[0].Text;
		timer=setInterval("fadeIn("+alpha+");",10);
		moveinplace();
	}
}
function moveinplace() {	
	var i=myContent;
	showButtons();
	//setimgTitle();
	// deals with automatic scrolling
	if (carousel==true && strt==false) { waiting=setTimeout("moveOn()",1); }
	if (carousel==true && strt==true) { strt=false;waiting=setTimeout("moveOn()",carspeed); }
	if (carousel==true) { 
		document.getElementById('homeviewer').onmouseover=function() { carousel=false;clearTimeout(waiting);clearTimeout(firstup); }
		document.getElementById('homeviewer').onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); } 
		document.getElementById('vnxt').onmouseover=function() { carousel=false;clearTimeout(waiting);clearTimeout(firstup); }
		document.getElementById('vnxt').onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); }
		document.getElementById('vprv').onmouseover=function() { carousel=false;clearTimeout(waiting);clearTimeout(firstup); }
		document.getElementById('vprv').onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); }
	}
	// set counter to first
	moveTo(0);	
}
// deals with counter blocks
var btnclick=false;
function moveTo(id) {
	var allitems=myContent.length;
	for (i=0;i < allitems;i++) {
		document.getElementById('cntr'+i).style.color='#000000';
	}
	document.getElementById('cntr'+id).style.color='#cc0033';	
	oid=id;
}
function moveOver(id) {	
	btnclick=true;
	if (id>oid) { moveTo(id);if (oid>0) { oid=id-1; } else { oid=myContent.length-1; } moveOn(); }
	if (id<oid) { moveTo(id);if (oid<myContent.length-1) { oid=id+1; } else { oid=0; } moveBack(); }
}
// next button functionality
function moveOn() {		
	clearTimeout(waiting);
	clearTimeout(firstup);
	clearInterval(timer);
	clearInterval(titletimer);
	clearInterval(titletimer2);
	vcontent.style.filter = 'alpha(opacity=0)';
	vcontent.style.MozOpacity = 0;
	if (oid<myContent.length-1) { var nid=oid+1; } else { var nid=0; }
	vfoto.innerHTML='<img width="'+fotowidth+'" height="'+fotoheight+'" src="'+myContent[nid].Foto+'" border="0" />';
	vtitle.innerHTML='<h2><a href="'+myContent[nid].Url+'">'+myContent[nid].Title+'</a></h2>';
	vcomp.innerHTML='<h3>'+myContent[nid].Composers+'</h3>';
	vtext.innerHTML=myContent[nid].Text;
	if (btnclick==false) { 			
		if (oid<myContent.length-1) { moveTo(oid+1,oid); }
		else { oid=myContent.length-1; moveTo(0,oid); }
	} else { btnclick=false; }	
	timer=setInterval("fadeIn("+alpha+");",10);
	if (carousel==true) { waiting=setTimeout("moveOn()",carspeed); }
}
// previous button functionality
function moveBack() {		
	clearTimeout(waiting);
	clearTimeout(firstup);
	clearInterval(timer);
	clearInterval(titletimer);
	clearInterval(titletimer2);
	vcontent.style.filter = 'alpha(opacity=0)';
	vcontent.style.MozOpacity = 0;
	if (oid>0) { var nid=oid-1; } else { var nid=myContent.length-1; }
	vfoto.innerHTML='<img width="'+fotowidth+'" height="'+fotoheight+'" src="'+myContent[nid].Foto+'" border="0" />';
	vtitle.innerHTML='<h2><a href="'+myContent[nid].Url+'">'+myContent[nid].Title+'</a></h2>';
	vcomp.innerHTML='<h3>'+myContent[nid].Composers+'</h3>';
	vtext.innerHTML=myContent[nid].Text;
	if (btnclick==false) { 
		if (oid>0) { moveTo(oid-1,oid); }
		else { oid=0;	moveTo(myContent.length-1,oid); }
	} else { btnclick=false; }
	timer=setInterval("fadeIn("+alpha+");",10);
}
var alpha=0;
function fadeIn() {
	if (alpha<100) {
		vcontent.style.filter = 'alpha(opacity='+alpha+')';
		vcontent.style.MozOpacity = alpha/101;
		//alpha++;
		alpha=alpha+5;
	} else { 
		clearInterval(timer);
		vcontent.style.filter = 'alpha(opacity=100)';
		vcontent.style.MozOpacity = 1;
		alpha=0;
		setimgTitle();
	}
}
// start title layer functionality
var curTop;var titletimer;var titletimer2;var firstup;var endpoint;var titleLayer;
// semi transparent title layer for fotos
function setimgTitle() {	
	clearTimeout(firstup);
	if (document.getElementById('vtitlelayer')) { titleLayer=document.getElementById('vtitlelayer'); }
	endpoint=myendpoint;
	vcontent.onmouseover=function() { showImgTitle(); }
	vcontent.onmouseout=function() { hideImgTitle(); }
	//showImgTitle();	
	//firstup=setTimeout("hideImgTitle()",titlepause);

}
function showImgTitle() { clearInterval(titletimer2);titletimer=setInterval("comeUp();",5); }
function comeUp() {		
	if (titleLayer) {
		curTop=titleLayer.style.marginTop;curTop=curTop.replace("px","");
		if (curTop>-endpoint) { curTop=curTop-5;titleLayer.style.marginTop=curTop+"px";} 
		else { clearInterval(titletimer);titleLayer.style.marginTop=-endpoint+"px";curTop=-endpoint; }
	}
}
function hideImgTitle() { clearInterval(titletimer);titletimer2=setInterval("comeDown();",5); }
function comeDown() {		
	if (titleLayer) {
		if (curTop<-30) { curTop=curTop+5;titleLayer.style.marginTop=curTop+"px";} 
		else { clearInterval(titletimer2);titleLayer.style.marginTop=-30+"px"; }
	}
}
// show buttons functionality
function showButtons() {
	var allitems=myContent.length;
	if (allitems>0) { 
		if (document.getElementById('vnxt')) { 
			document.getElementById('vnxt').style.cursor='pointer'; 
		}
		if (document.getElementById('vprv')) { 
			document.getElementById('vprv').style.cursor='pointer'; 
		}
	}
}

$(document).ready(function() {
 
    getHomeContent();          

});

// Tabs on home page
$(document).ready(function() {
    $(".tabs li").hoverClass("myhover");
    $(".tabs li").click(function() {
        $(".tabs li").removeClass("active");
        $("#" + this.id).addClass("active");
        $(".tabcontent").removeClass("active");
        $("#" + this.id + "content").addClass("active");
    });
});
