/******************************************************************************
 * scroller.js - Code to scroll linked graphics.
 * Copyright (C) 2006, by QOOP, Inc.
 * All Rights Reserved
 ******************************************************************************/
 
/* This function should be called by a page's body onload attribute to start the scrolling region.
 *
 * direction = "horizontal" or "vertical"
 * refresh = number of milliseconds between each scroll action when in standard "play" mode
 * vspacing = extra space to place between graphics vertically
 * hspacing = extra space to place between graphics horizontally
 */

function start_scroller(direction, refresh, vspacing, hspacing,data,linkdata)
	{
		
		var imgDetails=new Array();
		imgDetails=data.split("#");
		linkDetails=linkdata.split("#");
		top.scroller = new Image_Scroller(direction, refresh, vspacing, hspacing);
	for (var i=0;i<imgDetails.length-1;i++)
	{
		//alert(imgDetails[i]);
	top.scroller.add_image('upload/'+imgDetails[i]+'', linkDetails[i], 180, 90, 'odolyss Add');
	}
	
	/* Create the scroller object:
	 */
	
	
	/* Add logos to the object:
	 */
	/*top.scroller.add_image('images/port.jpg', 'ourworks.html', 172, 99, 'About My Baby');
	top.scroller.add_image('images/port1.jpg', 'ourworks.html', 172, 99,'About My Baby');
	top.scroller.add_image('images/port2.jpg', 'ourworks.html', 172, 99,'About My Baby');
	top.scroller.add_image('images/port3.jpg', 'ourworks.html', 172, 99,'About My Baby');
	top.scroller.add_image('images/port4.jpg', 'ourworks.html', 172, 99, 'About My Baby');
	top.scroller.add_image('images/port5.jpg', 'ourworks.html', 172, 99, 'About My Baby');
	top.scroller.add_image('images/port6.jpg', 'ourworks.html', 172, 99,'About My Baby');
	top.scroller.add_image('images/port7.jpg', 'ourworks.html', 172, 99, 'About My Baby');
	top.scroller.add_image('images/port1.jpg', 'ourworks.html', 172, 99, 'About My Baby');
	top.scroller.add_image('images/port2.jpg', 'ourworks.html', 172, 99, 'About My Baby');*/
	
	
	/* Set up the screen:
	 */
	top.scroller.draw_images();
	
	/* Set things in motion:
	 */
	animate_scroller();
	}

/* This function animates the scrollbar; it is called repeatedly on a timer:
 */	
function animate_scroller()
	{
	if (top.scroller)
		top.scroller.animate_scroller();
	}

/* This function pauses the scrollbar on mouseover:
 */	
function stop_scrolling()
	{
	if (top.scroller)
		top.scroller.stop_scrolling();
	}

/* This function resumes the scrollbar on mouseout:
 */	
function start_scrolling()
	{
		
	if (top.scroller)
		top.scroller.start_scrolling();
	}

/* Class constructor:
 */	
function Image_Scroller(direction, refresh, vspacing, hspacing)
	{
	/* Store parameters:
	 */
	this.scroll_style = direction;
	this.refresh = refresh;
	this.vspacing = vspacing;
	this.hspacing = hspacing;
	
	/* Set up information on images:
	 */
	this.image_array = new Array();
	this.image_count = 0;
	this.total_width = 0;
	this.total_height = 0;
	
	/* Start in play mode by default:
	 */
	this.vcr_play();
	}
	
/* The following functions support VCR-style controls for the scrolling region:
 */
Image_Scroller.prototype.vcr_play = function()
	{
	this.set_move_increment(+1);
	this.vcr_mode = "play";
	this.start_scrolling();
	}
	
Image_Scroller.prototype.vcr_reverse = function()
	{
	this.set_move_increment(1);
	this.vcr_mode = "reverse";
	this.start_scrolling();
	}
	
Image_Scroller.prototype.vcr_fast_play = function()
	{
	this.set_move_increment(-3);
	this.vcr_mode = "fast_play";
	this.start_scrolling();
	}
	
Image_Scroller.prototype.vcr_fast_reverse = function()
	{
	this.set_move_increment(+3);
	this.vcr_mode = "fast_reverse";
	this.start_scrolling();
	}
	
Image_Scroller.prototype.vcr_stop = function()
	{
	this.stop_scrolling();
	this.vcr_mode = "stop";
	}

/* This controls the number of pixels we move the images on each redraw (set negative to reverse direction):
 */		
Image_Scroller.prototype.set_move_increment = function(x)
	{
	this.move_increment = x;
	}

/* This starts scrolling up on mouseout or when VCR buttons are pressed.  Note that it does not restart if
 * the last button pressed was "stop":
 */	
Image_Scroller.prototype.start_scrolling = function()
	{
	if (this.vcr_mode != "stop")
		this.scroll_on = true;
	}

/* This pauses scrolling:
 */	
Image_Scroller.prototype.stop_scrolling = function()
	{
	this.scroll_on = false;
	}

/* This adds image information to the object:
 */	
Image_Scroller.prototype.add_image = function(image_url, link_url, img_width, img_height, alt_text)
	{
	this.image_array[this.image_count] = new Image_Data(image_url, link_url, img_width, img_height, alt_text);
	this.image_count++;
	}

/* This sets up	the initial screen that we will animate.  Always call this before starting scrolling up!
 */
Image_Scroller.prototype.draw_images = function()
	{
	this.total_width = 0;
	this.total_height = 0;
	
	for (var x = 0; x < this.image_count; x++)
		{
		    document.body.innerHTML += "<span name='span_" + x + "' id='span_" + x + 
			"'><a target='_blank'  href='" + 
			this.image_array[x].get_link_url() + "'><img  name='img_" + x + 
			"' id='img_" + x + "'  class=borderRD src='" + this.image_array[x].get_image_url() + "' border='0' width='" + 
			this.image_array[x].get_width() + "' height='" + this.image_array[x].get_height() + "' alt='" +
			this.image_array[x].get_alt_text() + "'  style='border: solid 1px #949494;'  ></a></span>";
		var problem_count = 0;
		var object = document.getElementById("span_" + x);
		object.style.position = "absolute";
		if (this.scroll_style == "horizontal")
			{
			object.style.top = "0px";
			object.style.left = this.total_width + "px";
			}
		else
			{
			object.style.left = "9px";
			object.style.top = this.total_height + "px";
			}
		this.total_height += parseInt(this.image_array[x].get_height() + this.vspacing);
		this.total_width += parseInt(this.image_array[x].get_width() + this.hspacing);
		}
	}

/* This does the actual animation of the scrolling region:
 */	
Image_Scroller.prototype.animate_scroller = function()
	{
	/* Only perform the scroll if scrolling is currently turned on:
	 */
	if (this.scroll_on)
		{
		for (var x = 0; x < this.image_count; x++)
			{
			var object = document.getElementById("span_" + x);
			if (this.scroll_style == "horizontal")
				{
				var new_value = parseInt(object.offsetLeft);
				new_value += this.move_increment;
				if (new_value < (0 - object.offsetWidth))
					new_value += this.total_width;
				if ((new_value + object.offsetWidth) > this.total_width)
					new_value -= this.total_width;
				object.style.left = new_value + "px";
				}
			else
				{
				var new_value = parseInt(object.offsetTop);
				new_value += this.move_increment;
				if (new_value < (0 - object.offsetHeight))
					new_value += this.total_height;
				if ((new_value + object.offsetHeight) > this.total_height)
					new_value -= this.total_height;
				object.style.top = new_value + "px";
				}
			}
		}
		
	setTimeout("animate_scroller();", this.refresh);
	}
	
/* The following class is used for storing information on the images within the scrolling region:
 */
function Image_Data(image_url, link_url, image_width, image_height, alt_text)
	{
	this.image_url = image_url;
	this.link_url = link_url;
	this.img_width = image_width;
	this.img_height = image_height;
	this.alt_text = alt_text;
	}
	
Image_Data.prototype.get_width = function()
	{
	return this.img_width;
	}
	
Image_Data.prototype.get_height = function()
	{
	return this.img_height;
	}
	
Image_Data.prototype.get_image_url = function()
	{
	return this.image_url;
	}
	
Image_Data.prototype.get_link_url = function()
	{
	return this.link_url;
	}
	
Image_Data.prototype.get_alt_text = function()
	{
	return this.alt_text;
	}