// JavaScript Document
//var Casto={};
Casto.home={};
Casto.home.advr={
		active:false,
		current1:0,
		current2:0,
		currentBlock:1,
		preBlock:2,
		tot:0,		
		speed:70,
		data:'',
		tot_width:0,
		width:265,
		scroll:1,
		view:3,		
		preAction:'',
		highlights:new Array(),
		init:function() {			
			this.tot_width = this.tot * this.width;
			$$('.home-advertisement .scroller-2 .scroller')[0].update($$('.home-advertisement .scroller-1 .scroller')[0].innerHTML);
			$$('.home-advertisement .scroller').each(function(ob) {
				ob.setStyle('width:'+Casto.home.advr.tot_width+'px;'); 
			});			
			$$('.home-advertisement div[class^=scroller-]').each(function(ob) {ob.show();});
			$$('.home-advertisement .scroller-'+this.currentBlock)[0].show();
			$$('.photo-gallery .scroll a')[0].observe('click',function() {
				Casto.home.advr.previous();
				//setTimeout("Casto.home.advr.previous();",500);
			});
			$$('.photo-gallery .scroll a')[1].observe('click',function() {
				Casto.home.advr.next();
				//setTimeout("Casto.home.advr.next();",500);
			});
			if(this.tot<=3) {
				$$('.photo-gallery .scroll a').each(function(ob) {ob.hide();})
			}
			if(Prototype.Browser.IE && (navigator.appVersion.indexOf('MSIE 7.0')>=0)) {
				$$('.home-advertisement .scroller-2')[0].setStyle('top:-1px;');
			}
			this.current1 = 0;
			this.current2 = -1*this.tot;
		},		
		next:function() {	
			if(this.active) return;
			this.active=true;
			
			if(this.currentBlock==1) {
				if(this.current2<=this.tot && this.current2>=(this.tot-this.view) && this.preAction=='previous') 
					this.current2 = (this.current1+this.tot);
				else {
					this.current2 = -1*(this.tot-this.current1);
					this.preAction = 'next';
				}
			} else {
				if(this.current1<=this.tot && this.current1>=(this.tot-this.view) && this.preAction=='previous')
					this.current1 = (this.current2+this.tot);
				else {
					this.current1 = -1*(this.tot-this.current2);
					this.preAction = 'next';
				}
			}
			
			this.debug('Next == Current Block: '+this.currentBlock+', with '+this.current1+' && '+this.current2+"\n");
			$$('.home-advertisement .scroller-1 .scroller')[0].show().setStyle('left:'+(-1*(this.current1*(this.width*this.scroll)))+'px;');
			$$('.home-advertisement .scroller-2 .scroller')[0].show().setStyle('left:'+(-1*(this.current2*(this.width*this.scroll)))+'px;');
			var start = 0-this.view;
			var end = this.tot;
			if(this.current1>=start && this.current1 <= end) {
				this.current1+=this.scroll;
				$$('.home-advertisement .scroller-1 .scroller')[0].show().morph('left:'+(-1*(this.current1*(this.width*this.scroll)))+'px;');
			} else {
				this.current1+=this.scroll;
				$$('.home-advertisement .scroller-1 .scroller')[0].show().setStyle('left:'+(-1*(this.current1*(this.width*this.scroll)))+'px;');
			}
			if(this.current2>=start && this.current2 <= end) {
				//alert("");
				this.current2+=this.scroll;
				$$('.home-advertisement .scroller-2 .scroller')[0].show().morph('left:'+(-1*(this.current2*(this.width*this.scroll)))+'px;');
			} else {
				this.current2+=this.scroll;
				$$('.home-advertisement .scroller-2 .scroller')[0].show().setStyle('left:'+(-1*(this.current2*(this.width*this.scroll)))+'px;');	
			}
			setTimeout('Casto.home.advr.active=false;',1100);
			this.debug('Next == Current Block: '+this.currentBlock+', with '+this.current1+' && '+this.current2+"\n");
			if(this.currentBlock==1 && this.current1>this.tot) this.switchBlock();
			else if(this.currentBlock==2 && this.current2>this.tot) this.switchBlock();
		},
		previous:function() {		
			if(this.active) return;
			this.active=true;
			if(this.currentBlock==1) {
				if(this.current2>=(0-this.view) && this.current2<=0 && this.preAction=='next') {
					this.current2 = (this.current1-this.tot);
				} else {
					this.current2 = (this.tot+this.current1);
					this.preAction = 'previous';
				}
			} else {
				if(this.current1>=(0-this.view) && this.current1<=0 && this.preAction=='next') {
					this.current1 = (this.current2-this.tot);
				} else {
					this.current1 = (this.tot+this.current2);
					this.preAction = 'previous';
				}
			}
			
			this.debug('Previous == Current Block: '+this.currentBlock+', with '+this.current1+' && '+this.current2+"\n");
			$$('.home-advertisement .scroller-1 .scroller')[0].show().setStyle('left:'+(-1*(this.current1*(this.width*this.scroll)))+'px;');
			$$('.home-advertisement .scroller-2 .scroller')[0].show().setStyle('left:'+(-1*(this.current2*(this.width*this.scroll)))+'px;');
			var start = 0-this.view;
			var end = this.tot;
			if(this.current1>=start && this.current1 <= end) {
				this.current1-=this.scroll;
				$$('.home-advertisement .scroller-1 .scroller')[0].show().morph('left:'+(-1*(this.current1*(this.width*this.scroll)))+'px;');
			} else {
				this.current1-=this.scroll;
				$$('.home-advertisement .scroller-1 .scroller')[0].show().setStyle('left:'+(-1*(this.current1*(this.width*this.scroll)))+'px;');
			}
			if(this.current2>=start && this.current2 <= end) {
				//alert("");
				this.current2-=this.scroll;
				$$('.home-advertisement .scroller-2 .scroller')[0].show().morph('left:'+(-1*(this.current2*(this.width*this.scroll)))+'px;');
			} else {
				this.current2-=this.scroll;
				$$('.home-advertisement .scroller-2 .scroller')[0].show().setStyle('left:'+(-1*(this.current2*(this.width*this.scroll)))+'px;');	
			}
			setTimeout('Casto.home.advr.active=false;',1100);
			this.debug('Previous == Current Block: '+this.currentBlock+', with '+this.current1+' && '+this.current2+"\n");
			if(this.currentBlock==1 && this.current1<(0-this.view)) this.switchBlock();
			else if(this.currentBlock==2 && this.current2<(0-this.view)) this.switchBlock();
			
		},		
		switchBlock:function() {		
			//alert("Change");
			Casto.home.advr.preBlock = Casto.home.advr.currentBlock;
			if(Casto.home.advr.currentBlock==1) Casto.home.advr.currentBlock = 2;
			else Casto.home.advr.currentBlock = 1;		
		},
		debug:function(str) {
			//$('debug').value+=str;
			//$('debug').scrollTop=5000;
		}
	};
