/*
Swap image and add onmouseover and onmouseout event
*/

function addMenuEvent(id){
	var mainmenu = document.getElementById(id);
	var li = mainmenu.getElementsByTagName('li');
	for(var i=0; i<li.length; i++){
		if(li[i].className.indexOf('selected') == -1){
			li[i].onmouseover = function(){
				this.className +=  ' over';
			}

			li[i].onmouseout = function(){
				this.className = this.className.replace("over", "");
			}
		}
	}
}

function img_hover_swap(imgobj, new_img){
	var temp = new Image();
	var image = new Image();
	image.src = new_img;
	temp.src = imgobj.src;

	imgobj.src = image.src;

	imgobj.onmouseout = function (){
		imgobj.src = temp.src;
	}
}

function addGalleryEvent(id, swap_id){
	var gallery = document.getElementById(id);
	var anchor_ary = gallery.getElementsByTagName('a');
	var swappable_img = document.getElementById(swap_id).getElementsByTagName('img')[0];
	for(var i=0; i<anchor_ary.length; i++){
		anchor_ary[i].onclick = function(){
			var img_ary = this.getElementsByTagName('img');
			if(img_ary[0]){
				swapImg(swappable_img,this.href);
			}
			return false;
		}
	}
}

function swapImg(img_to_swap,img_loc){
	var img = new Image();
	img.src = img_loc;
	img_to_swap.src = img.src;
}

function addVideoGalleryEvent(id, text_id){
	var gallery = document.getElementById(id);
	var text = document.getElementById(text_id);
	var anchor_ary = gallery.getElementsByTagName('a');
	for(var i=0; i<anchor_ary.length; i++){
		anchor_ary[i].onclick = function(){
			video_player.playVideo(this.getAttribute('href'));
			text.innerHTML = this.getElementsByTagName('img')[0].getAttribute('alt');
			return false;
		}
	}
}