/** 
 * Copyright (c) 2008, Ravinder Singh Rawat
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *     * The Ravinder Singh Rawat may be used to endorse or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * Mail rsrawat2008@Zapak.com for obtaining license.
 */

//*************** These are the variables which i will use later in the script.................

var st_length = 0; ra = 0; arr = new Array(); scroll_amt = 1; count = 0;

//*************** here in this function i set the property of div and paragraph tag.................

function news_animation() {
	var scrollAmount = 1;
	var a = document.getElementById("rsr");
	var par = a.getElementsByTagName("p");
	st_length = par.length;
	for(r=0; r<st_length; r++) {
		arr[r] = 0;
	}
	//alert(st_length);
	/*a.style.position = "relative";
	a.style.width = 200 + "px";
	a.style.height = 180 + "px";
	a.style.overflow = "hidden";*/
	for(i=0; i<st_length; i++){
			par[i].style.position = "absolute";
			par[i].style.width = 100 + "%";
			par[i].style.height = "auto";
			par[i].style.margin = 0 + "px";
			par[i].style.padding = 0 + "px";
			//par[i].style.display = "inline-block";
			//par[i].style.backgroundColor = "red";
			par[i].style.top = ra + "px";
			ra = ra + par[i].offsetHeight + 24;
	}
	setInterval("anis()", 30);
	//alert("hi");
}

//******************** this is the main function causing paragraph to move above...................

function anis(){
		var hi = document.getElementById("rsr");
		var b = document.getElementById("rsr").getElementsByTagName("p");
		for(j=0; j<b.length; j++){
			//alert(j);
			if(parseInt(b[j].style.top) == 0 && arr[j] == 0){
				count++;
				if(count<120){
					scroll_amt = 0;
				}
				if(count >= 120){
					scroll_amt = 1;
					count = 0;
					arr[j]=1;
				}
			}
			else if (parseInt(b[j].style.top) > -parseInt(b[j].offsetHeight)){
				b[j].style.top = parseInt(b[j].style.top) - scroll_amt + "px";
			}
			else if (parseInt(b[j].style.top) == -parseInt(b[j].offsetHeight)){
				//b[j].style.display = "none";
				arr[j]=0;				
				if(j==0 && (st_length-1)!=0){
					b[j].style.top = parseInt(b[st_length-1].style.top) + parseInt(b[st_length-1].offsetHeight) + 24 + "px";
				}
				else if(j==0 && (st_length-1)==0){
					b[j].style.top = 185 + "px";
				}
				else {
					b[j].style.top = parseInt(b[j-1].style.top) + parseInt(b[j-1].offsetHeight) + 24 + "px";
				}
			}
		}
	}