// JavaScript Document

function gallery_image_select (container_id, selected_id) {
	container = document.getElementById(container_id);

if(container) {
		media = container.getElementsByTagName('img');
		old_item = '';
		new_item = '';
		for(ctr = 0; ctr < media.length; ctr++) {
			if(media[ctr].id == selected_id) {
				new_item = media[ctr].id;
			} else if(media[ctr].style.display != 'none') {
				old_item = media[ctr].id;
			}
		}

		if(old_item) Effect.Puff(old_item);
		if(new_item) Effect.Appear(new_item);
	}
}

function gallery_display_next (container_id, jump_count) {
	jump_count = parseInt(jump_count);
	container = document.getElementById(container_id);
	if(container) {
		media = container.getElementsByTagName('img');
		for(ctr = 0; ctr < media.length; ctr++) {
			if(media[ctr].style.display != 'none') {
				if((ctr+jump_count >= 0) && (media[ctr+jump_count]) && (media[ctr+jump_count] != 'undefined')) {
					gallery_image_select (container_id, media[ctr+jump_count].id)
				} else if((ctr+jump_count - media.length >= 0) && media[ctr+jump_count - media.length] && media[ctr+jump_count - media.length] != 'undefined') {
					gallery_image_select (container_id, media[ctr+jump_count - media.length].id)
				} else if((ctr+jump_count + media.length >= 0) && media[ctr+jump_count + media.length] && media[ctr+jump_count + media.length] != 'undefined') {
					gallery_image_select (container_id, media[ctr+jump_count + media.length].id)
				}
				break;
			}
		}
	}
}

function getHeight(container_id) {
	
	d = document.getElementById(container_id);
	if(d) {
		if(d.offsetHeight){ 
			 divHeight=d.offsetHeight; 					
		} 
		else if(d.style.pixelHeight){ 
			 divHeight=d.style.pixelHeight;					 
		} 
	}
	return divHeight;
}

function gallery_selection_move (container_id, direction) {
	// move types: 0 - horizontal, 1 - vertical
	// direction: 0 - left/up, 1 - right/down
	
	container = document.getElementById(container_id);
	direction = parseInt(direction);
	
	if(container) {
		scroll_speed = getHeight(container_id);
		
		if(direction == 0 && container.scrollTop - scroll_speed < 0) {
			scroll_speed = container.scrollTop;
		} else if(direction == 1 && container.scrollTop + scroll_speed > container.scrollHeight) {
			scroll_speed = container.scrollHeight - container.scrollTop;
		}
		
		if(direction) {
			container.scrollTop = container.scrollTop + scroll_speed;
		} else {
			container.scrollTop = container.scrollTop - scroll_speed;
		}
	}
}


// media player scripts

 function getFlashMovieObject(movieObject) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieObject] : document[movieObject];
 }
 
 function playMovie(movieObject, movieName) {
  var flashMovie=getFlashMovieObject(movieObject);
  flashMovie.playMovie(movieName);
  
 }

