// JavaScript Document
Casto.brand={
		active:false,
		current:0,
		currentBlock:1,
		tot:0,
		speed:70,
		data:'',
		tot_width:0,
		width:1003,
		highlights:new Array(),
		names:new Array(),
		load: function(url){
			this.VoidAjax(url);
		},
		init:function() {
			this.tot =this.names.length;
			for(var i=0;i<this.tot;i++){
				this.data+='<div class="brand-name" style="background-image:url('+this.names[i]['image']+'); width:'+this.names[i]['width']+'px;" onclick="javascript:window.location=\''+this.names[i]['link']+'\';">&nbsp;</div>';
				this.highlights[i] = this.tot_width;
				this.tot_width += parseInt(this.names[i]['width'])+10;
				//alert((parseInt(this.names[i]['width'])+10)+' of '+this.names[i]['image'] +' with total of '+this.tot_width);
			}			
			
			$$('.brand-scroll-area .scroller').each(function(ob) {
				ob.update(Casto.brand.data).setStyle('width:'+Casto.brand.tot_width+'px;'); 
			});
			$$('.brand-scroll-area div[class^=scroll-]').each(function(ob) {ob.hide();});
			if(Prototype.Browser.IE && (navigator.appVersion.indexOf('MSIE 7.0')>=0)) {
				$$('.brand-scroll-area .scroll-2')[0].setStyle('top:-1px;');
			}
			$$('.scroll-'+this.currentBlock)[0].show();
			if(this.tot_width<this.width) {
				$$('.scroll-'+this.currentBlock)[0].setStyle('padding-left:'+((this.width-this.tot_width)/2)+'px;');
			} else
				this.start();
		},
		start:function(){
			this.active=true;
			$$('.scroll-'+this.currentBlock)[0].show();
			var obj=$$('.scroll-'+this.currentBlock+' .scroller')[0];
			var speed = ((Casto.brand.tot_width+this.width)/this.speed);
			
			obj.setStyle('left:'+this.width+'px;').morph('left:-'+Casto.brand.tot_width+'px;',{duration:speed,transition:Effect.Transitions.linear});
			var next_switch = ((Casto.brand.tot_width)/this.speed);
			//alert(next_switch);
			var next_high;
			this.current=0;
			//alert(this.highlights[5]);
			for(var i=0;i<this.highlights.length;i++) {
				next_high = ((this.highlights[i]+((this.width/2)))/this.speed);
				if(i>0)
					setTimeout('Casto.brand.out('+this.currentBlock+');',(next_high-0.3)*1000);
				setTimeout('Casto.brand.hover('+i+','+this.currentBlock+')',next_high*1000);
			}
			if(i>1) {
				//alert(i +' ' +this.highlights[5] );
				next_high += (this.tot_width - this.highlights[i-1])/this.speed;
				//alert(next_high);
				setTimeout('Casto.brand.out('+this.currentBlock+');',((next_high-0.3))*1000);
			}
			setTimeout(function() {Casto.brand.switchBlock(); },(next_switch+0.3)*1000);
		},
		pause:function() {
			
		},
		resume:function() {
			
		},
		switchBlock:function() {
			if(Casto.brand.currentBlock==1) Casto.brand.currentBlock = 2;
			else Casto.brand.currentBlock = 1;
			Casto.brand.start();
		},
		hover:function(no,bl) {
			$$('.scroll-'+bl+' .scroller .brand-name')[no].className='brand-name-hover';
		},
		out:function(bl) {
			$$('.scroll-'+bl+' .scroller .brand-name-hover')[0].className='brand-name';
		}, 
		VoidAjax: function(url) {
			callAjaxActive = true;
			new Ajax.Request(url, {
				method:"GET",
				parameters: "",
				onSuccess: function(retailer){ 
					var responseArray = retailer.responseText.evalJSON();	
					if(responseArray['response']['status']==true) {
						if(responseArray['response']['valid']) { 
							Casto.brand.names = responseArray['response']['value'];
							Casto.brand.init();
						} else {
							
						}
					}
				},
				onFailure: function(){ 
					
				}
			});
		}
	};
	
