/**
 * @author Stéphane Roucheray
 * @extends jquery
 */

jQuery.fn.start = function(){
	firstElementOnViewPort = 1,
	allElementsWidth = 0;
	stopAppend = false;
	onlyOnce = false;
	u=0;
	left=500;
	//jQuery(query).css('left','500px');
	if (temp==2){
		jQuery(this).carousel();
	}
	//$('div.mtest').marquee();

}

 jQuery.fn.carousel = function(options){

/* ### preparations ### */
  temp++;
  increment = 1;
  var query = jQuery(this).children()[0];
  //elmnts = jQuery('slider-stage').children();
  elmnts = jQuery(this).children();
  numElmts = elmnts.length;
  //alert(numElmts);
  //alert(temp);
  /*
  jQuery(this).css('position','absolute');
  */
  //jQuery(this).css('backgroundColor','red');
  outerHeightAllItems = 0;


  /* append same amount of items*/

  for (i=0;i<numElmts;i++) {
	if (stopAppend==false) {
		jQuery('.tweet_list').append(jQuery(elmnts[i]).clone());
		outerHeightAllItems = outerHeightAllItems + jQuery(elmnts[i]).outerHeight("true");
		//jQuery(elmnts[i]).css('backgroundColor','green');
		//alert(jQuery(elmnts[i]).outerHeight("true"));
		//break;
	}


	if (i==(numElmts-1)){
		stopAppend=true;

		for (h=0;h<numElmts;h++) {
			if (onlyOnce==false) {
				jQuery('.tweet_list').append(jQuery(elmnts[h]).clone());
			}
			if (h==(numElmts-1)){
				onlyOnce=true;
			}
		}

		if (outerHeightAllItems != 0) { /*alert(outerHeightAllItems);*/ heightStorage = outerHeightAllItems;}
	}
}

   jQuery('.query').animate({
  				top: "-=" + heightStorage,
  				x: 0,
  				queue: true
  				},(120 /*80*/ * heightStorage), "linear",
          function(){
    				if(u % 2){
    					//alert(u);
						left = jQuery(query).css('left');
						jQuery('.query').css('top', "0px");
    					//jQuery('#slider-stage').carousel();
						jQuery(this).carousel();
						//reset();
						//move query
    				}
    				u++;
  				}
          );
};

