/*
 * BASED ON  -> jQuery JavaScript Library v1.3.2
 * http://jquery.com/
 *
 * let some DIV Elements scroll to the side and fade them back to the start
 *
 * Copyright (c) 2009 Michael Preis
 * m.preis@simadesign.de
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 *
 * Date: 2009-03-04
 *
 */

(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);



function doMove(move,end,start) {

		var position = parseFloat($('.wrapper').css('left'),10);

		if (position >= 0) {
			
			$('.wrapper').fadeOut(3000 , function(){ $(this).css({"left":start +"px"}); } ); 
			$('.background').fadeOut(3000); 
			
		}
		else {
		$('.background').fadeIn(500); 
		$('.wrapper').css({"display":"block"});
		$('.wrapper').animate({	"left" : "+=" + move + "px" }, 1000);
  		$('.wrapper').animate({ dummy: 1 }, 2000);


		}

		// console.log(position);
}

$(function(){

		var box_count = $('.wrapper div.box').size();
		var box_margin = parseFloat($('.wrapper div.box').css('margin-right'),10);
		var box_size = parseFloat($('.wrapper div.box').css('width'),10);
		var box_totalsize = box_size / 2;
		var outerbox_size = parseFloat($('#outerbox').css('width'),10) / 2;
		var move = outerbox_size + box_totalsize;
		var end = box_count * (box_size + box_margin);
		var start =  box_size - (end + box_size);

		$('.wrapper').css({"width":end +"px"});
		$('.wrapper').css({"left":start +"px"});

		// console.log(box_count);
		// console.log(box_size);

		// console.log(end);
		// console.log(start);
				
		
		 sliderIntervalID = setInterval(function(){
			doMove(move,end,start);
		},6000);

});

