

function MenuHover(id){
	var src=document.getElementById(id).src;
	if(src.substr(src.length-7,7)!="_on.gif"){
		src=src.substr(0,src.length-4)+'_on.gif';
		document.getElementById(id).src=src;
	}
	else{
		src=src.substr(0,src.length-7)+'.gif';
		document.getElementById(id).src=src;
	}
}

//rotate the gallery control upwards
function SlideUp(galleryName){
	galleryLength=Data(galleryName);
	
	//loop thro each thumnail img and edit the src to the new position
	var thumbs = document.getElementsByTagName("img");
	for (i=0;i<thumbs.length;i++)
	{
		if(thumbs[i].id.indexOf("thumb")>-1){						
			
			var address = decodeURI(thumbs[i].src)
			var thumbNo = address.substr(address.length-7,3);
						
			// decrement the thumbNo by 2, if goes below 000 then use size of gallery js array to give new position
			if(thumbNo-2<0){
				thumbNo = galleryLength-1;
			}
			else{
				thumbNo = thumbNo-2;
			}
			if (thumbNo==0){thumbNo=galleryLength};
			if (thumbNo<100){
				if (thumbNo<10){
					thumbNo='00'+thumbNo;
				}
				else{
					thumbNo='0'+thumbNo;
				}
			}
			
			//set the new src and onclick of the thumbnail
			var imgId = thumbs[i].id;
			var anchor = document.getElementById(imgId.substr(0,2)+imgId.substr(5));
			anchor.onclick=function (){onclickHandler(this);};
			thumbs[i].src=address.substr(0,address.length-7)+thumbNo+'.jpg';
		}
	}
}



//rotate the gallery control upwards
function SlideDown(galleryName){
	galleryLength=Data(galleryName);

	//loop thro each thumnail img and edit the src to the new position
	var thumbs = document.getElementsByTagName("img");
	for (i=0;i<thumbs.length;i++){
		if(thumbs[i].id.indexOf("thumb")>-1){
			
			var address = decodeURI(thumbs[i].src);
			var thumbNo = address.substr(address.length-7,3);
			
			// increment the thumbNo by 2, if goes above gellerylength then use 000 to give new position
			thumbNo = thumbNo-(-2);
			if (thumbNo==galleryLength-(-1)){
				thumbNo='1';
			}
			if (thumbNo==galleryLength-(-2)){
				thumbNo='2';
			}
			if (thumbNo<100){
				if (thumbNo<10){
					thumbNo='00'+thumbNo;
				}
				else{
					thumbNo='0'+thumbNo;
				}
			}
			
			//set the new onclick of the thumbnail		
			var imgId = thumbs[i].id;
			var anchor = document.getElementById(imgId.substr(0,2)+imgId.substr(5));
			anchor.onclick=function (){onclickHandler(this);};
			thumbs[i].src=address.substr(0,address.length-7)+thumbNo+'.jpg';
		}
	}
}

function onclickHandler(ctrl){
    var imgObj = document.getElementById(ctrl.id.replace('th','thumb'));
    var address = decodeURI(imgObj.src);
	var thumbNo = address.substr(address.length-7,3);

    galleryName=GetURLParam('g');
    SetImagePane(thumbNo,galleryName);PopulateGalleryCaption(thumbNo);
    
}

function SetImagePane(imageNo,galleryName){
	var image = document.getElementById('ImagePane');
	var imgAdd = decodeURI(image.src);
	var address="";
	if(imgAdd.indexOf('www.')>-1){
        address = imgAdd.substr(0,44)+galleryName+'/';
    }
    else{
        address = imgAdd.substr(0,40)+galleryName+'/';
    }	
	
	//set address different if on my local machine
	if(imgAdd.indexOf("localhost")>-1){
		address = imgAdd.substr(0,46)+galleryName+'/';
	}
	
	image.src=address+imageNo+'.jpg';
}

function Data(gallery){
	return eval(gallery).length;
}

function GetURLParam(param){
	var address=location.href;
	if(address.indexOf('?g')>-1){
		return address.substr(address.indexOf('?')+3).replace(/#/g,'');
	}
	else{
		return "CamFoot";
	}
}

function PopulateGalleryTitle(){
	var GalleryTitleLabel=document.getElementById('GalleryTitle');
	var GalleryTitle=document.getElementById(GetURLParam('g')).innerHTML;
	GalleryTitleLabel.innerHTML=GalleryTitle+' Gallery';
}

function PopulateGalleryCaption(thumbNo){
	var image = document.getElementById('ImagePane');
	var galleryName=GetURLParam('g');
	
	var imgAdd = decodeURI(image.src)
	var address = "";
	if(imgAdd.indexOf('www.')>-1){
	    address = imgAdd.substr(0,44)+galleryName+'/';
	}
	else{
	    address = imgAdd.substr(0,40)+galleryName+'/';
	}

	//set address different if on my local machine
	if(imgAdd.indexOf("localhost")>-1){
		address = imgAdd.substr(0,46)+galleryName+'/';
	}
	
	if (thumbNo==""){
		var thumbName = imgAdd.substr(address.length);
		thumbNo = thumbName.replace('.jpg','');
	}
	
	thumbNo = thumbNo-1;
	var galleryArray = eval(galleryName);
	var caption = galleryArray[thumbNo][1];
	document.getElementById('GalleryCaption').innerHTML = "<br>"+caption+"<br><br>";
}

function PopulateThumbnails(galleryName){
	var thumbs = document.getElementsByTagName("img");
	for (i=0;i<thumbs.length;i++){
		if(thumbs[i].id.indexOf("thumb")>-1){
			
			var imgAdd = decodeURI(thumbs[i].src);
			var address="";
			if(imgAdd.indexOf('www.')>-1){
                address = imgAdd.substr(0,37)+'/Thumbnails/'+galleryName+'/';
            }
            else{
                address = imgAdd.substr(0,33)+'/Thumbnails/'+galleryName+'/';
            }
			
			//set address different if on my local machine
			if(imgAdd.indexOf("localhost")>-1){
				address = imgAdd.substr(0,50)+galleryName+'/';
			}
			
			var thumbAddy = imgAdd
			var thumbNo = thumbAddy.substr(thumbAddy.length-7,3);			
			thumbs[i].src=address+thumbNo+'.jpg';		
			var imgId = thumbs[i].id;
			var anchor = document.getElementById(imgId.substr(0,2)+imgId.substr(5));
			anchor.onclick=function (){onclickHandler(this);};
			
		}
	}
}

function PopulateEvent(eventName){
	if(eventName!=""){
		document.getElementById('content').innerHTML=eval(eventName);
	}
	else{
		document.getElementById('content').innerHTML=CameroonNationalDayFestival07;
	}
}

function isIE(){
    return document.all;
}

function isNetscape(){
    return (document.getElementById && !document.all);
}


function Toggle(id){
	var section = id.substr(0,1);
	ClearAllToggles(section);
	var toggleSrc=document.getElementById(id).src;
	document.getElementById(id).src=toggleSrc.substr(0,toggleSrc.indexOf('Vote'))+'VoteOn.gif';
}

function ClearAllToggles(section){
	var toggles = document.getElementsByTagName("img");
	for (var x=0;x<toggles.length;x++){
		var toggleSrc = toggles[x].src;
		var toggleIndexOn = toggleSrc.indexOf('VoteOn');
		var toggleId = toggles[x].id;
		if(toggleIndexOn>-1){
			if(toggleId.substr(0,1)==section){
				toggles[x].src = toggleSrc.substr(0,toggleIndexOn) + 'VoteOff.gif';
			}
		}
	}
}


function CastVote(section){
	var toggles = document.getElementsByTagName("img");
	for (var x=0;x<toggles.length;x++){
		var toggleId = toggles[x].id;
		if (toggleId.substr(0,1)==section){
			var toggleSrc = toggles[x].src;
			var toggleIndexOn = toggleSrc.indexOf('VoteOn');
			if(toggleIndexOn>-1){
				var content = document.getElementById(section+"_"+toggleId.substr(1)).innerHTML;
				WriteToFile(content,section);
			}
		}
	}
}


function WriteToFile(content,section){
	if(section=='p')
	{
		var obj = document.getElementById('VoteWorld');
	}
	else
	{
		var obj = document.getElementById('VoteUK');
	}
	obj.value = content;
	Form1.submit();
}