/*-----------REZA--------------*/


jQuery(document).ready(function(){
	//Initialize scrolling:
	if(jQuery('ul.scrollX').length > 0) scroll_X('ul.scrollX');
	
	//Auto scroll if "?pid=X" is set where 'X' is Index:
	var urlArr=window.location.href.split('#pid=');
	if( urlArr.length >1 && jQuery('ul.scrollX').length >0 ){
		var pid = parseInt(urlArr[1]);
		while(curBox!=pid && pid < $('ul.scrollX > li').length && pid>=0)
			jQuery('.buts_box .butn_next').trigger('click');
	}
	
	/*if($('a[rel*=lightbox], area[rel*=lightbox]').length > 0){
		$('a[rel*=lightbox], area[rel*=lightbox]').lightBox();
	}*/
	
});

/*===================SCROLLing only by X-axis===========================*/
var curBox=0, nextBox=0;
function scroll_X(elem){
	var direction=+1, total=jQuery(elem+' > li').length, eachBoxWidth=$(elem+' li:first').outerWidth();
	jQuery(elem+' li:eq('+curBox+')').css('left','0');
	jQuery('.buts_box .butn_pre, .buts_box .butn_next').click(function(){
		if(jQuery(this).is('.buts_box .butn_pre')){
			nextBox = (curBox == (total-1))? 0 : curBox+1;
			direction = +1;
		}
		else{
			nextBox = (curBox == 0)? (total-1) : curBox-1;
			direction = -1;
		}
		jQuery(elem+' > li:eq('+nextBox+')').css('left', (-1)*direction*eachBoxWidth+'px');
		jQuery(elem+' > li:eq('+curBox+')').stop(true,true).animate({left : direction*eachBoxWidth+'px'},{
			queue:false,
			duration:'medium',
			step:function(n, fx){
				//$(elem+' > li:eq('+nextBox+')').css('left' , (direction*eachBoxWidth-n)+'px');
				jQuery(elem+' > li:eq('+nextBox+')').css('left' , (-1*direction*eachBoxWidth+n)+'px');
			}
		});
		curBox=nextBox;
	});
}


