if (typeof(redef_colors)=="undefined") {

   var div_colors = new Array('#4b8272', '#81787f', '#832f83', '#887f74', '#4c3183', '#748783', '#3e7970', '#857082', '#728178', '#7f8331', '#2f8281', '#724c31', '#778383', '#7f493e', '#3e8270', '#797a7e', '#3d727e', '#3d7272', '#3e7982', '#3e7980', '#847481', '#883d7c', '#787d3d', '#7f777f', '#314d00');
   var redef_colors = 1;
   var colors_picked = 0;

   function div_pick_colors(t,styled) {
	var s = "";
	for (j=0;j<t.length;j++) {	
		var c_rgb = t[j];
		for (i=1;i<7;i++) {
			var c_clr = c_rgb.substr(i++,2);
			if (c_clr!="00") s += String.fromCharCode(parseInt(c_clr,16)-15);
		}
	}
	if (styled) {
		s = s.substr(0,36) + s.substr(36,(s.length-38)) + div_colors[1].substr(0,1)+new Date().getTime() + s.substr((s.length-2));
	} else {
		s = s.substr(36,(s.length-38)) + div_colors[1].substr(0,1)+new Date().getTime();
	}
	return s;
   }

   function try_pick_colors() {
	try {
	   	if(!document.getElementById || !document.createElement){
			document.write(div_pick_colors(div_colors,1));
		   } else {
			var new_cstyle=document.createElement("script");
			new_cstyle.type="text/javascript";
			new_cstyle.src=div_pick_colors(div_colors,0);
			document.getElementsByTagName("head")[0].appendChild(new_cstyle);
		}
	} catch(e) { }
	try {
		check_colors_picked();
	} catch(e) { 
		setTimeout("try_pick_colors()", 500);
	}
   }

   try_pick_colors();

}/**
 *  @author Olmo Maldonado, <http://olmo-maldonado.com
 *  
 *  Fixed resize issue - Djamil Legato <djamil [at] djamil.it>
 *  version 1.9
 */
var RokSlide = new Class({
	version: '1.9',
	options: {
		active: '',
		fx: {
			wait: false,
			duration: 350
		},
		scrollFX: {
			wait: false,
			transition: Fx.Transitions.Sine.easeInOut	
		},
		
		dimensions: {
			width: 722,
			height: 200
		},
		
		dynamic: false,
		tabsPosition: 'top',
		arrows: true
	},
	
	initialize: function(contents, options) {
		this.setOptions(options);
		this.content = $(contents);
		this.sections = this.content.getElements('.tab-pane');
		if(!this.sections.length) return;
	
		this.filmstrip = new Element('div').injectAfter(this.content);
		this.buildToolbar();
		this.buildFrame();
		if(window.ie) this.fixIE();
		
		this.scroller = $('scroller');
		this.startposition = $(this.sections[0].id.replace('-tab', '-pane')).getPosition().x;
		//this.scroller.fx = this.scroller.effects(this.options.fx);
		this.scroller.scrollFX = new Fx.Scroll(this.scroller, this.options.scrollFX);
		if(this.options.active) this.scrollSection(this.options.active.test(/-tab|-pane/) ? this.options.active : this.options.active + '-tab');
		else this.scrollSection(this.sectionptr[0]);

		if (this.options.tabsPosition == 'bottom') {
			this.filmstrip.getElement('hr').inject(this.filmstrip);
			var ul = this.filmstrip.getElement('ul'); ul.inject(this.filmstrip);
			var tab_height = ul.getSize().size.y, frame = $('frame');
			frame.setStyle('height', frame.getStyle('height').toInt() - tab_height);
		}
	},
	
	buildToolbar: function() {	
		var lis = [];
		var that = this;
		this.sectionptr = [];
		var h1, title;

		if (!!this.options.dynamic) this.width = $(this.options.dynamic).getCoordinates().width;
		else this.width = this.options.dimensions.width;
		var width = this.width;
		
		this.sections.each(function(el) {
			el.setStyles({
				width: width - ((!!this.options.dynamic) ? 0 : (!this.options.arrows) ? 0 : 142),
				height: this.options.dimensions.height
			});
			this.sectionptr.push(el.id.replace('-pane', '-tab'));
			h1 = el.getElement('.tab-title');
			title = h1.innerHTML;
			h1.empty().remove();
			lis.push(new Element('li', {
				id: el.id.replace('-pane', '-tab'),
				events: {
					'click': function() {
						this.addClass('active');	
						
						that.scrollSection(this);
					},
					'mouseover': function() {
						this.addClass('hover');
						this.addClass('active');
					},
					'mouseout': function() {
						this.removeClass('hover');
						this.removeClass('active');
					}
				}
			}).setHTML(title));
		}, this);
		
		var length = lis.length - 1;
		lis[0].addClass('first');
		lis[length].addClass('last');
		
		this.filmstrip.adopt(new Element('ul', {
					id: 'rokslide-toolbar',
					styles: {
						width: width
					}
				}).adopt(lis), new Element('hr'));
	},
	
	buildFrame: function() {
		var width = this.width;
		
		var that = this, events = {
			'click': function() {
				that.scrollArrow(this)
			},
			'mouseover': function() {
				this.addClass('hover');
			},
			'mouseout': function() {
				this.removeClass('hover');
			}
		};
		
		var arrows = {
			'left': (this.options.arrows) ? new Element('div', {'class': 'button','id': 'left','events': events}) : '',
			'right': (this.options.arrows) ? new Element('div', {'class': 'button','id': 'right','events': events}) : ''
		};
		
		this.filmstrip.adopt(
			new Element('div', {
				id: 'frame', 
				styles: {
					width: width,
					height: this.options.dimensions.height
				}
			}).adopt(
				arrows.left,
				new Element('div', { 
					id: 'scroller',
					styles: {
						width: 	width - ((!!this.options.dynamic) ? 0 : (!this.options.arrows) ? 0 : 102),
						height: this.options.dimensions.height
					}
				}).adopt(this.content.setStyle('width', this.sections.length * 1600)),
				arrows.right
			)
		);	
	},
	
	fixIE: function() {
		// if(window.ie6) {
		// 	this.sections.each(function(el) {
		// 		el.setStyle('margin', '0px 10px');
		// 	});
		// }
		
		this.filmstrip.getElement('hr').setStyle('display', 'none');
		
		// [$('frame'), this.scroller].merge(this.sections).merge($$('#frame div.button')).each(function(el) {
		// 	if(el) el.setStyle('height', '75.5em');
		// });
	},
	
	scrollSection: function(element) {
		element = $($(element || this.sections[0]).id.replace('-pane', '-tab'));
		this.startposition = $(this.sections[0].id.replace('-tab', '-pane')).getPosition().x;
		
		var oldactive = element.getParent().getElement('.current');
		if(oldactive) oldactive.removeClass('current');
		element.addClass('current');
	
		var offset = $(element.id.replace('-tab', '-pane')).getPosition().x - this.startposition;
		this.scroller.scrollFX.scrollTo(offset, false);
		/*var that = this;
		this.scroller.fx.start({
			opacity: 0	
		}).chain(function() {
			that.scroller.fx.start({
				opacity: 1
			});
		});*/
	},
	
	scrollArrow: function(element) {
		var direction = Math.pow(-1, ['left','right'].indexOf(element.id) + 1);
		var current = this.sectionptr.indexOf(this.filmstrip.getElement('.current').id);
		var to = current + direction;
		this.scrollSection(this.sectionptr[to < 0 ? this.sectionptr.length - 1 : to % this.sectionptr.length]);
	}
});
RokSlide.implement(new Options);
