/************************************************
*   scrollerMoo v.0                             *
*   Http: WwW.developer.ps/moo/scrollermoo      *
*   Dirar Abu Kteish dirar@zanstudio.com        *
*   The code was inspired from jd.gallery.js    *
*    and jd.gallery.css. WebSite:               *
*    smoothgallery.jondesign.net                *
/***********************************************/

var scrollerMoo = new Class({
    initialize: function(element, options) {
		this.setOptions({
			steps: 3, 
			wrapperClass: 'div.scrollerMooWrapper',
			scrollerItemSelector: 'div.scrollerMooItem'			
	    }, options);
	    this.currentPos = 0;
	    this.scrollerItems = null;
	    this.scrollerElement = element;
	    this.wrapperDiv = element.getElement(this.options.wrapperClass);
	    this.scrollEff = new Fx.Scroll(this.wrapperDiv, {wait: false,duration: 600,
                                        offset: {'x': -3, 'y': 0},
                                        transition: Fx.Transitions.Quad.easeInOut
                        });
	    this.initScrollerMoo();
	    
	},
	initScrollerMoo: function() {
	    var ele = this.scrollerElement;
		var options = this.options;
		this.scrollerItems = this.wrapperDiv.getElements(options.scrollerItemSelector);
		if (this.scrollerItems.length > 1)
		{
			new Element('a').setProperties({id: 'left'}).addClass('left').addEvent(
				'click',function(){this.scrollToItem(-1);}.bind(this)).injectBefore(this.wrapperDiv);
			new Element('a').setProperties({id: 'right'}).addClass('right').addEvent(
				'click',function(){this.scrollToItem(1);}.bind(this)).injectAfter(this.wrapperDiv);
		}		
	},
	scrollToItem: function(dir) {
        var move = dir * this.options.steps;	
		
		
        var index = (this.scrollerItems[this.currentPos+move]) ? this.currentPos+move : ((this.currentPos+move) > 0) ? this.scrollerItems.length-1 : 0;
		//$('txt').value = index + "-";

		
		
		//$('scrollerMooStatusDot' + (this.currentPos/this.options.steps+2)).src = 'images/spotlight/point_active.png';	
		
        
		
		if((index + 1) < (this.scrollerItems.length) && index >= 0)
		{
			$('scrollerMooStatusDot'+1).src = 'images/spotlight/point_no.png';
			$('scrollerMooStatusDot'+2).src = 'images/spotlight/point_no.png';
			$('scrollerMooStatusDot'+3).src = 'images/spotlight/point_no.png';
			
			$('right').style.backgroundImage   = 'url(images/spotlight/arrow_right_active.png)';
			$('left').style.backgroundImage   = 'url(images/spotlight/arrow_left_active.png)';
			
			this.scrollEff.toElement(this.scrollerItems[index]);
			
			
			
			$('scrollerMooStatusDot'+ ((index / this.options.steps) + 1)).src = 'images/spotlight/point_active.png';	
			$('right').style.cursor   = 'pointer';
			this.currentPos = index; 
		}
		
		//$('txt').value = $('txt').value  + this.currentPos +  " " + this.scrollerItems.length;
        
		if(((index + 1) >= (this.scrollerItems.length-5)) && (index % this.options.steps) == 0)
		{			
			$('right').style.backgroundImage   = 'url(images/spotlight/arrow_right_no.png)';
			$('right').style.cursor   = 'auto';
			return;
		}
        
		if(((index) == 0                        ) && (index % this.options.steps) == 0)
		{
			$('left').style.backgroundImage   = 'url(images/spotlight/arrow_left_no.png)';
			$('left').style.cursor   = 'auto';
			return;
		}
		
		
		
	}
	
});

// image change functions
function _2effectMpVpMoveDot() {
	for(i=1;i<4;i++) {
		$('scrollerMooStatusDot'+i).src = 'images/gray_status.gif';
		$('scrollerMooStatusDot'+i).onmouseover = function() {this.src = 'images/gray_active_status.gif';}
		$('scrollerMooStatusDot'+i).onmouseout = function() {this.src = 'images/gray_status.gif';}
	}
	$('scrollerMooStatusDot'+_2effectMpVpCurPage).src = 'images/gray_active_status.gif';
	$('scrollerMooStatusDot'+_2effectMpVpCurPage).onmouseover = function() {}
	$('scrollerMooStatusDot'+_2effectMpVpCurPage).onmouseout = function() {}
}
function _2effectMpVpUpdateBtns() {
	if(_2effectMpVpCurPage > 1) {
		$('_2effectMpVidBtnL').style.cursor ='auto';
		$('_2effectMpVidBtnL').src = 'images/left_red_btn.gif';
		$('_2effectMpVidBtnL').onmouseover = function() { this.src='images/left_red_over_btn.gif'; }
		$('_2effectMpVidBtnL').onmouseout = function() { this.src='images/left_red_btn.gif'; }
	}
	else {
		$('_2effectMpVidBtnL').style.cursor ='default';
		$('_2effectMpVidBtnL').src = 'images/left_gray_btn.gif';
		$('_2effectMpVidBtnL').onmouseover = function() {}
		$('_2effectMpVidBtnL').onmouseout = function() {}
	}

	if(_2effectMpVpCurPage < 3) {
		$('_2effectMpVidBtnR').style.cursor ='auto';
		$('_2effectMpVidBtnR').src = 'images/right_red_btn.gif';
		$('_2effectMpVidBtnR').onmouseover = function() {this.src = 'images/right_red_over_btn.gif';}
		$('_2effectMpVidBtnR').onmouseout = function() {this.src = 'images/right_red_btn.gif';}
	}
	else {
		$('_2effectMpVidBtnR').style.cursor ='default';
		$('_2effectMpVidBtnR').src = 'images/right_gray_btn.gif';
		$('_2effectMpVidBtnR').onmouseover = function() {}
		$('_2effectMpVidBtnR').onmouseout = function() {}
	}
}
/* end main page video box
===================================================================== */
scrollerMoo.implement(new Options);
