var cursub = null;
var delayto = null;
var opc = 0;
//document.getElementById('main').innerHTML = 'x';
function menuimage(Obj,sel) {
	//document.getElementById('main').innerHTML += 'menuimage('+Obj.id+');\n<br/>';
	//alert(Obj+'\n'+Obj.id+'\n'+Obj.src);
	var ext = '';
	if (sel > 0) { var ext = '.selected'; }
	if (Obj.src.indexOf('hover') > -1) { Obj.src = 'images/menu.'+Obj.id +ext +'.gif'; }
	else { /*alert('Hover...');*/ Obj.src='images/menu.'+Obj.id+'.hover.gif'; }
}
function menuimage2(Obj,s) {
	//document.getElementById('main').innerHTML += 'menuimage2('+Obj+','+s+');\n ['+Obj.id+']<br/>';
	if (s == 0) { /*alert('Regular...');*/ Obj.style.backgroundImage = 'url(images/background-menu.li.gif)'; }
	if (s == 10) { /*alert('Regular...1sy');*/ Obj.style.backgroundImage = 'url(images/background-menu.li.gif)'; }
	if (s == 1) { /*alert('images/menu.'+Obj.id+'selected.gif');*/ Obj.style.backgroundImage = 'url(images/menu.selected2.gif)'; }
	if (s == 11) { /*alert('1st images/menu.'+Obj.id+'selected.gif');*/ Obj.style.backgroundImage = 'url(images/menu.selected2f.gif)'; }
	if (s == 2) { /*alert('Hover...'); */ Obj.style.backgroundImage='url(images/background-menu.li.hover.png)'; }
	if (s == 12) { /*alert('Hover... 1st'); */ Obj.style.backgroundImage='url(images/background-menu.li.hover.png)'; }
}
function showSub(Objid,subid,s) {
	Obj = document.getElementById(Objid);
	//document.getElementById('main').innerHTML += 'showSub('+Objid+','+subid+');\n<br/>';
	if (typeof s == 'undefined') { menuimage2(Obj,2); }
	else { menuimage2(Obj,s); }
	subObj = document.getElementById(subid);
	if (cursub != null) {
		curObj = document.getElementById(cursub);
		curObj.style.display = 'none';
	}
	cursub = subid;
	subObj.style.display = 'block';
}
function hideSub(Objid,subid,s) {
	Obj = document.getElementById(Objid);
	if (typeof s == 'undefined') { s = 0; }
	//document.getElementById('main').innerHTML += 'hideSub('+Obj+','+subid+','+s+'); '+Obj.id +' / '+subid+' / '+cursub +'\n<br/>';
	if (subid != null) {
		menuimage2(Obj,s);
		subObj = document.getElementById(subid);
		subObj.style.display = 'none';
		subid = null;
	}
}

function hideSubDelay(Objid,subid,s) {
	Obj = document.getElementById(Objid);
	//document.getElementById('main').innerHTML += 'hideSubDelay('+Obj+','+subid+','+s+');\n ['+Obj.id +']<br/>';
	if (cursub != null) {
		//document.getElementById('main').innerHTML += '...cursub not null<br/>\n';
		if (cursub != subid) {
			//document.getElementById('main').innerHTML += '...cursub != subid [' +cursub +'/'+subid+']<br/>\n';
			hideSub(Obj.id,cursub,s);
		}
		delayto = setTimeout("hideSub('"+ Obj .id+"','"+ cursub+"',"+s+")", 150);
		//document.getElementById('main').innerHTML += '...executed timeout<br/>\n';
		//cursub = null;
	}
}
function killDelay() {
	//document.getElementById('main').innerHTML += 'killDelay();\n<br/>';
	//if (cursub != null) {
		 clearTimeout(delayto);
	//}
}

function fadein(Obj) {
	changeAlpha(Obj.id);
	fadein = setInterval("changeAlpha('"+ Obj.id+"')",5);
}

function changeAlpha(id) {
	opc++;
    var object = document.getElementById(id).style;
    object.opacity = (opc / 100);
    object.MozOpacity = (opc/ 100);
    object.KhtmlOpacity = (opc / 100);
    object.filter = "alpha(opacity=" + opc + ")";
	if (opc == 100) { clearInterval(fadein); }
} 


function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gallery .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 200);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, 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}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '40px'},200 );
	
	//Display the content
	$('#gallery .content').html(caption);
		
}


