Cufon.replace('h1.key-color, h2.key-color, h3.key-color, h4.key-color, h5.key-color, h6.key-color, a.menu-url, li.menu-fruit-element a, button.ui-button span', {
    hover : true
});

Object.extend(String.prototype, {
	ensureEndsWith: function(str) {
		return this.endsWith(str) ? this : this + str;
	},
	px: function() {
		return this.ensureEndsWith('px');
	},
	em: function(){
		return this.ensureEndsWith('em');
	},
	plural: function(titles) {
	    return parseInt(titles).plural(titles);
	}
});

Object.extend(Number.prototype, {
	px: function() {
		return this.toString().px();
	},
	em: function(){
		return this.toString().em();
	},
    plural: function(titles) {
        var cases = [2,0,1,1,1,2];
        return titles[ (this % 100 > 4 && this % 100 < 20) ? 2 : cases[[this % 10, 5].min()] ];
    }
});

UI = {};
// UI.ProgrammSlider = Class.create(Control.Slider, {
//  cellWidth: 87,
//  initialize: function($super, track, options){
//      var nullHandle = new Element('div');
//      $super(nullHandle, track, options);
//      this.options = Object.extend(this.options, options);
//  },
//  _setTrackWidth: function(value){}
// });

UI.Tooltip = Class.create({
	
	container: {},
	triggers: [],
	closeTriggers: [],
	options: {},
	initialize: function(options){
		
		this.options = Object.extend({
			triggers: [],
			close: {
				className: '',
				event: 'mouseout'
			},
			triggerEvent: Prototype.emptyFunction,
			triggerOffset: Prototype.emptyFunction,
			nodeSelect: Prototype.emptyFunction
		}, options);
		
		this.container = new Element('div', {
			className: 'ui-popup-fixed project-info-tooltip',
			style: 'display: none'
		});
		
		this.triggers = this.options.triggers;
		this.closeTriggers = this.options.closeTriggers;
		
		this.triggers.each(function(t){
			t.observe('mouseover', function(event){
			    
				var offset = t.cumulativeOffset();
				var content = this.options.nodeSelect(t);
		
	            this.container.setStyle({
					top : ((offset.top) - 22).px(),
					left : ((offset.left) - 24).px()
				});
				this.updateContainer(content).show();
			}.bind(this));
			
		}.bind(this));
		
        document.body.appendChild(this.container);
	},
	
	updateContainer: function(node){
		this.container.update();
		this.container.insert(node);
		
		this.container.select(this.options.close.className).each(function(item){
			item.observe(this.options.close.event, function(event){
				this.hide();
			}.bind(this));
		}.bind(this));
		return this;
	},
	
	show: function(){
		this.container.setStyle({display:'block'});
	},
	
	hide: function(){
		this.container.setStyle({display:'none'});
	}
	
	
});

UI.Slider = Class.create(Control.Slider, {
	minWidth: 80,
	maxWidth: 960,
	minHeight: 240,
	maxHeight: 240,
	area: {},
	
	initialize: function($super, handle, track, options){
		$super(handle, track, options);
		this.options = Object.extend(this.options, options);
		
		if(this.options.area){

			this.area = $(this.options.area);
			
			if(this.options.onItemOver){
				this.options.onItemOver(this);
			}
			
			if(this.options.onItemClick){
				this.options.onItemClick(this);
			}
			
			var count = this.area.select(this.options.elements).size();
			this.range = $R(0, count - 1);
			this.values = $R(0, count - 1);
			this.minimum = 0;
			this.maximum = count - 1;

			if(count > this.options.min){
				if(this.options.axis != 'vertical'){
					var size = this.maxWidth - (this.minWidth * count);
					this.setHandleWidth(size);
				}else{
					var size = this.maxHeight * this.maxHeight / Math.min(1000, this.getAreaHeight());
					if(this.maxHeight >= this.getAreaHeight()) {
						this.hide();
						if(this.options.container){
							var container = $(this.options.container);
							var d = this.area.select('.slider-height')[0].getDimensions();
							container.addClassName('slider-v-noslide');
							container.setStyle({width: d.width.px(), height: d.height.px()});
						}
					} else {
					    this.area.setStyle({height: $(this.options.container).getHeight().px()});
					}
					this.setHandleHeight(size);
				}
			}else{
				this.hide();
				if(this.options.container){
					var container = $(this.options.container);
					var d = this.area.select('.slider-height')[0].getDimensions();
					container.addClassName('slider-v-noslide');
					container.setStyle({width: d.width.px(), height: d.height.px()});
				}
			}
			//this.scroll();
		}
	},
	
	getAreaWidth: function(){
		return this.area.select('.slider-width')[0].getDimensions().width;
	},
	
	getAreaHeight: function(){
		return this.area.select('.slider-height')[0].getDimensions().height; 
	},
	
	scroll: function(){
		function wheel(event){
			var delta = this.value;
			if (!event) /* For IE. */
				event = window.event;

			if (!event) /* For IE. */
				event = window.event;
			if (event.wheelDelta) { /* IE/Opera. */
				delta -= Math.round(event.wheelDelta /  (this.maximum * this.maximum)) * 0.05;
				/** In Opera 9, delta differs in sign as compared to IE. */
				if (window.opera)
					delta = -delta;
			} else if (event.detail) { 
				/** Mozilla case. */
				/** In Mozilla, sign of delta is different than in IE.
				* Also, delta is multiple of 3.
				*/
				delta += event.detail * 0.05;
			}
			if (delta)
				this.setValue(delta);
			/** Prevent default actions caused by mouse wheel.
			* That might be ugly, but we handle scrolls somehow
			* anyway, so don't bother here..
			*/
			if (event.preventDefault)
				event.preventDefault();
			event.returnValue = false;
		}
		Event.observe(this.area, 'mousewheel', wheel.bind(this));
		Event.observe(this.area, 'DOMMouseScroll', wheel.bind(this));
	},
	
	_setHandleWidth: function(value){
		this.handleLength = value;
		var handle = this.handles[0];
		handle.setStyle({width: value + 'px'});
		handle.select('.handle-center')[0].setStyle({'width': (value - 20).px()});
	},
	
	setHandleWidth: function(value){
		if(value <= this.minWidth){
			this._setHandleWidth(this.minWidth);
			return this;
		}
		if(value >= this.maxWidth){
			this._setHandleWidth(this.maxWidth);
			return this;
		}
		this._setHandleWidth(value);
		return this;
	},
	
	_setHandleHeight: function(value){
		this.handleLength = value;
		var handle = this.handles[0];
		handle.setStyle({height: value + 'px'});
		handle.select('.handle-center')[0].setStyle({'height': (value - 20).px()});
	},
	
	setHandleHeight: function(value){
		this._setHandleHeight(value);
		return this;
	},	
	
	hide: function(){
		$(this.track).hide();
		return this;
	},
	
	show: function(){
		$(this.track).show();
		return this;
	}
});

UI.Accordition = Class.create({
    initialize: function(args){
		this.options = Object.extend({
			triggerSelector: '.ui-accord-head a',
			visibleSelector: '.ui-accord-body',
			parentSelector: '.ui-accord-container',
			animation: true,
			ajax: false,
			expand: true
		}, args);

		this.options.animation = true;
        if (Prototype.Browser.Opera) this.options.animation = false; // No opera in my internets!!1
		
		$$(this.options.triggerSelector).each(function(item, index){
			item.observe('click', function(e){
				if(!this.options.parentSelector){
					var parent = $(item.ancestors()[1]);
				}else{
					var parent = $(item.up(this.options.parentSelector));
				}
				var img = parent.select(this.options.imagesSelector)[0];
				var faq = parent.select(this.options.visibleSelector)[0];
				if(Element.visible(faq)){
					this.hideVisible(faq, img);
				}else{
					this.showVisible(faq, img);
				}
			}.bind(this));
		}.bind(this));
	},

	hideVisible: function(element, image){
		if(this.options.animation){
			new Effect.SlideUp(element, {duration: 0.5});
		}else{
			element.hide();
		}
		return this;
	},

	expandAll: function(){
		$$(this.options.visibleSelector).each(function(visible){
			if(Element.visible(visible)){
				if(this.options.animation){
					new Effect.SlideUp(visible, {duration: 0.5});
				}else{
					visible.hide();
				}
			}
		}.bind(this));
    },

    showVisible: function(element, image){
		if(this.options.expand){
			this.expandAll();
		}
		if(this.options.animation){
			new Effect.SlideDown($(element), {duration: 0.5});
		}else{
			element.show();
		}
		$$(this.options.parentSelector).invoke('removeClassName', 'active');
		element.up(this.options.parentSelector).addClassName('active');
		return this;
	}
});

Programm = {}
Programm.Element = Class.create({
	
	initialize: function(){
		
	},
	
	build: function(json){
/*
<table border="0" cellspacing="0" cellpadding="0" class="tele-grid programm show-grid-#DAY_NUM#" width="100%">
	<tbody>
		<tr class="#IF# whbscnbu #/IF#">
			<td class="t-time">
				<span class="icon icon-6"></span>
				<span>13:00</span>
			</td>
			<td class="t-name">
				<a href="#PROJECT_URL#">#WATCHED ELEMENT#</a>
			</td>
			<td class="t-type">#GENRE#</td>
		</tr>
					
		<tr class="t-announce" style="display: none;">
			<td colspan="3">
				<img src="#SRC#" width="#WIDTH#" height="#HEIGHT#" alt="" />
				#ANOUNCE TEXT#
			</td>
		</tr>
	</tbody>
</table>
*/
	}
	
});

News = {}
News.List = Class.create({
	from: 0,
	cleared: false,
	params: {},
	list: {},
	options: {},
	container: {},
	
	initialize: function(options){
		this.options = Object.extend({
			container: 'news_list_list',
			limit: 7,
			url: '',
			info: false,
			moreLabel: 'Ещё новости'
		}, options);

		this.list = new Element('ul', {
							className: 'no-list news-list'
						});
		this.more = new Element('a', {
							href: '#from' + this.from, 
							className: 'key-color-dashed', 
							onclick: 'return false;'
						}).observe('click', function(event){
							this.get();
							//e.cancelBubble is supported by IE - this will kill the bubbling process.
							event.cancelBubble = true;
							event.returnValue = false;

							//e.stopPropagation works only in Firefox.
							if (event.stopPropagation) {
								event.stopPropagation();
								event.preventDefault();
							}

							return false;
						}.bind(this)).update(this.options.moreLabel);
		this.container = $(this.options.container);

	},
	
	get: function(parameters){

		this.params = Object.extend({
			from: this.from,
			limit: this.options.limit,
			id: this.params.id ? this.params.id : null
		}, parameters);
		
		new Ajax.Request(this.options.url, {
			contentType: 'application/json',
			method: 'get',
			onComplete: function(transport){
				json = transport.responseJSON;
				this.build(json.data);
				this.more.href = "#from=" + this.from + (this.params.id ? ("&id=" + this.params.id) : "");
				
				this.from += json.count;
				if(json.count < this.options.limit){
					$(this.more.up('div.boxy')).hide();
					//this.more.hide();
				}
			}.bind(this),
			parameters: this.params
		});
	},
	
	createNode: function(node){
	    var container = new Element('div', { className: 'container' }),
	        description = new Element('div', { className: 'span-9 last'});
	    description.insert(new Element('span', {className: 'date'}).update(node.date));
	    description.insert(new Element('br'));
	    description.insert(new Element('a', {href: node.url, title: node.name}).update(node.name));
	    description.insert(new Element('p').update(node.teaser));
	    if (this.options.info) {
	    description.insert(
	        new Element('div', {className:'info'}).insert(
	            new Element('span', {className:'views'}).update(node.views)
	        ).insert(
	            new Element('span', {className:'comments'}).update(node.comments)
	        )
	    );

	    }
	    container.insert(
	        new Element('div', { className: 'span-4' }).insert(
	            new Element('a', { href: node.url, title: node.name }).insert(
	                new Element('img', { src: node.image, alt: node.name, width: 150, height: 100 })
	            )
	        )
	    );
        container.insert(description);	    
	    return new Element('li', {
	        className: 'margin-2'
	    }).insert(container);
	},
	
	clear: function(force){
		if(force){
			this.cleared = false;
		}
		
		if(!this.cleared){
			this.from = 0;
			this.container.update();
			this.list.update();
			var divTop 		= new Element('div', {className: 'top'});
			var divBottom	= new Element('div', {className: 'bottom'});

			divTop.insert(this.list);
			divBottom.insert(
			    new Element('div', { 
			            className : 'boxy' 
			        }).insert(this.more)
			);
			this.container.insert(divTop);
			this.container.insert(divBottom);
			this.cleared = true;
		}
		return this;
	},

	build: function(json){
		json.each(function(news, index){
			this.list.insert(this.createNode(news));
		}.bind(this));
        this.container.select('li.clearfix').invoke('remove');
		this.list.insert(new Element('li', {className: 'clearfix'}).setStyle({height: '1px', margin: 0, padding: 0}).update(' '));
	}
});


Video = {}
Video.List = Class.create({
	from: 0,
	cleared: false,
	sorted: false,
	params: {},
	options: {},
	container: {},
	requestSent: false,
	sort: '-_sort',
	filter: null,
	settingsPanel: null,
	settingsList: null,
	projectId: null,
	
	initialize: function(options){	
		this.options = Object.extend({
			container: 'video_list',
			sortContainer: "video_sort",
			sort: [],
			limit: 6,
			sort: [],
			filters: [],
			settingsPanel: null,
			url: '',
			moreLabel: ''
		}, options);
		
		this.more = new Element('div', { className : 'boxy block margin-2' }).insert( 
		    new Element('a', {
				href: '#', 
				className: 'key-color-dashed', 
				onclick: 'return false;'
			}).observe('click', function(event){
				this.get();

				//e.cancelBubble is supported by IE - this will kill the bubbling process.
				event.cancelBubble = true;
				event.returnValue = false;

				//e.stopPropagation works only in Firefox.
				if (event.stopPropagation) {
					event.stopPropagation();
					event.preventDefault();
				}

				return false;
			}.bind(this)).update(this.options.moreLabel));
						
		this.list = new Element('div', {});
		this.container = $(this.options.container);

        if (this.options.settingsPanel) {
            this.settingsPanel = $(this.options.settingsPanel);
            this.createOptions();
        }
        this.container.insert(this.list);
        this.container.insert(this.more);
	},
	
	setUrl: function(url) {
	    this.options.url = url;
	    return this;
	},
	
	setProjectId: function(id) {
	    this.projectId = id;
	    return this;
	},
	
	get: function(parameters){
		this.params = Object.extend({
			from: this.from,
			sort: this.sort,//(this.options.sort.size() > 0 ) ? (this.options.sort.first().sort) : false,
			limit: this.options.limit,
			type: this.filter,
			id: this.projectId
		}, parameters);
		
		if (!this.requestSent) {
		    this.requestSent = true; // prevent really FAST sequance of clicks (hitting Enter, for example)
    		new Ajax.Request(this.options.url, {
    			contentType: 'application/json',
    			method: 'get',
    			onComplete: function(transport){
    			    this.requestSent = false;
    				json = transport.responseJSON;
    				this.build(json.data);
    				this.from += json.count;
    				if(json.count < this.options.limit || json.total <= this.from){
    					this.more.hide();
    				}
    			}.bind(this),
    			parameters: this.params
    		});
        }
	},
	
	createNode: function(node, index){
	    var container = new Element('div', { className: 'append-bottom column span-6' + (index % 2 ? ' last' : '') }),
	        description = new Element('div');
	    description.insert(new Element('span', {className: 'date'}).update(node.date));
	    description.insert(new Element('br'));
	    description.insert(new Element('a', {href: node.url, title: node.name}).update(node.name));
	    description.insert(
	        new Element('div', {className:'info'}).insert(
	            new Element('span', {className:'views'}).update(node.views)
	        ).insert(
	            new Element('span', {className:'comments'}).update(node.comments)
	        ).insert(
	            new Element('span', {className:'ratings'}).update(node.ratings)
	        )
	    );
	    container.insert(
	        new Element('div', { className: 'span-6' }).insert(
	            new Element('a', { href: node.url, title: node.name }).insert(
	                new Element('img', { src: node.video_image_banner, alt: node.name, width: 280, height: 140 })
	            )
	        )
	    );
        container.insert(description);
        return container;
	},
	
	createOptions: function() {
	    this.settingsList = new Element('div', {className: 'filters'});
	    this.settingsPanel.insert(this.settingsList);
	    if (this.options.sort.length) {
	        this.createSettings('Сортировка: ', 'sort', this.options.sort, this.changeSort);
	        if (this.options.filters.length) this.createSeparator();
	    }
        if (this.options.filters.length) this.createSettings('Фильтр: ', 'filter', this.options.filters, this.changeFilter);
	},

	createSettings: function(title, className, settings, callback) {
	    var name = new Element('span', {className:'bold'}).update(title);
	    this.settingsList.insert(name);
	    settings.each(function(opts){
	        var opt = new Element('a', {href: '#', className: 'dashed video-sort ' + className}).update(opts.label)
	        if (opts[className] === this[className]) opt.addClassName('selected').removeClassName('dashed');
	        this.settingsList.insert(opt);
	        opt.observe('click', callback.bind(this, opts[className], className));
	    }.bind(this));
	},

    createSeparator: function() {
        this.settingsList.insert(new Element('span', {className: 'separator'}));
    },

    changeSort: function(sort, className, evt) {
        this.sort = sort;
        evt.stop();
        this.settingsList.select('a.' + className).invoke('removeClassName', 'selected').invoke('addClassName', 'dashed');
        $(evt.target).addClassName('selected').removeClassName('dashed');
        this.clear().get();
    },
    
    changeFilter: function(filter, className, evt) {
        this.filter = filter;
        evt.stop();
        this.settingsList.select('a.' + className).invoke('removeClassName', 'selected').invoke('addClassName', 'dashed');
        $(evt.target).addClassName('selected').removeClassName('dashed');
        this.clear().get();
    },

	clear: function(force){
		this.h = 0;
		this.from = 0;
        this.list.childElements().invoke('remove');
		return this;
	},

	build: function(json){
        var self = this;
        var t = json.map(this.createNode.bind(this)).inGroupsOf(2).each(function(group){
            var elt = new Element('div', {className: 'append-bottom'});
            group.each(function(v,k){ if (v) elt.insert(v); if (k == 1) elt.insert(new Element('div', {className: 'clearfix'})); });
            self.list.insert(elt);
        });
	}
});


var AnchorNav = Class.create({
    initialize : function(options) {
        Object.extend(this, options);
        this.run();
        if (window.location.hash) {
            var elem = $($$('a[href=' + window.location.hash+ ']').first());
            if (elem) this.processLink(elem);
        }
    },
    run : function() {
        $$(this.selector).filter(function(v){ return !$(v).readAttribute('href').startsWith('#'); }).invoke('stopObserving', 'click').each(this.anchor).invoke('observe', 'click', this.observer.bind(this));
    	if (Cufon) Cufon.refresh('h1.key-color, h2.key-color, h3.key-color, h4.key-color, h5.key-color, h6.key-color, a.menu-url, li.menu-fruit-element a');
    },
    anchor : function(elem) {
        elem.writeAttribute('href', '#' + elem.readAttribute('href'));
    },
    evalTarget: function(target) {
        target.select('script').each(function(elem){eval(elem.innerHTML);});
    },
    loadTarget : function(type, data) {
        var type = type.split(':');
        var target = (type[1] ? $(type[1]) : $(this.target));
        switch (type[0]) {
            case 'replace' : target.innerHTML = data.responseText; this.evalTarget(target); break;
            case 'append'  : target.innerHTML += data.responseText; break;
        }
        this.run();
    },
    processLink : function(target) {
        var link = target.readAttribute('href').split('#')[1];
        var type = target.readAttribute('rel') || 'replace';
        if (link){
            new Ajax.Request(link, {
                parameters: {is_ajax: 1},
                evalJS : false,
                onSuccess : this.loadTarget.bind(this, type) 
            });  
        } 
        return false;
    },
    observer : function(e) {
        var target = $(e.target);
        this.processLink(target);
    }
});

var CProgrammPopups = Class.create({
    popup: null,
    initialize: function() {
        $('programm_list').observe('mouseover', this.mouseOver.bind(this));
        //$$('table.programm td.t-name a').invoke('observe', 'mouseover', this.mouseOver.bind(this));
        this.popup = new Element('div', {className:'telepopup'});
        // this.popup.setStyle({
        //     width: '680px',
        //     zIndex: 9999,
        //     padding: '0px'
        // //,padding: '0 5px'
        // });
        this.popup.observe('mouseover', this.popupOver.bind(this));
        this.popup.hide();
        document.body.appendChild(this.popup);
    },
    lookupTarget: function(node) {
        return $($(node).up('tr.pop'));
    },
    renderTable: function(target, html) {
        var table = '\
            <table>\
                <tbody>\
                    <tr>' + target.innerHTML + '</tr>\
                </tbody>\
            </table>\
            <div style="padding: 0 8px; text-align: left;">' + html + '</div>';
        return table;
    },
    positionPopup: function(position) {
        var widths = ['38px','330px','185px'];
        this.popup.setStyle({
            position: 'absolute',
            top: position.top.px(),
            left: (position.left - 5).px()
        });
        
        this.popup.select('tr:first-child td').each(function(v,k){
            $(v).setStyle({
                width: widths[k],
                border: 'none'
            });
        });
    },
    mouseOver: function(e) {
        var target = this.lookupTarget(e.target);
        if (target) var html = $(target.down('div.shitty_announce')).innerHTML;
        else return;
        e.stop();
        this.popup.innerHTML = this.renderTable(target, html);
        this.positionPopup(target.cumulativeOffset());
        this.popup.show();
    },
    popupOver: function(e) {
        var target = $(e.target);
        if (target.nodeName != 'TR' && target.up('tr') === undefined) this.popup.hide();
        e.stop();
        return true;
    }
});

var CActorPopups = Class.create({
    initialize: function() {
        
    },
    setHtml: function(node) {
        
    }
});

var CPoll = Class.create({
    options: {},
    top: null,
    bottom: null,
    initialize: function(options) {
        this.options = options;
        if (this.options['element']) this.run();
    },
    run: function() {
        this.buildPollLayout();
    },
    buildPollLayout: function() {
        this.bottom = new Element('div', {className: 'poll-form'}).insert(
            new Element('h4').update(this.options['question'])
        );
        if (this.options['voted']) this.voted(); else this.bottom.insert(this.buildPollForm());
        if (this.options['background']) this.bottom.setStyle({
            backgroundImage: 'url(' + this.options['background'] + ')',
            backgroundRepeat: 'no-repeat',
            backgroundPosition: 'top left',
            height: this.options['backgroundHeight'].px()
        });
        this.options['element'].appendChild(this.bottom);
    },
    buildPollForm: function() {
        var form = new Element('form'), poll_id = Math.round(Math.random(1,100)*100000000);
        this.options['answers'].each(function(item, index){
            var choice_id = ['poll', poll_id, index].join('_'),
                choice = new Element('input', {type:'radio', id: choice_id, name:'poll_' + poll_id});
            choice.observe('click', this.choiceClick.bind(this, item['id']));
            form.appendChild(
                new Element('div').insert(choice).insert(new Element('label', {'for': choice_id}).update(item['title']))
            );
        }.bind(this));
        return form;
    },
    choiceClick: function(id) {
        new Ajax.Request(this.options['url'], {
            method: 'post',
            parameters: {
                _resource: 'rating',
                document_id: this.options['document_id'],
                vote_id: id,
                kind: 3,
                type: this.options['type']
            },
            onComplete: this.voted.bind(this)
        });
    },
    voted: function() {
        this.bottom.innerHTML = '<div class="poll-result">Спасибо, ваш голос учтён</div>';
    },
    getResults: function() {
        new Ajax.Request(this.options['url'], {
            method: 'get',
            parameters: {
                _resource: 'rating',
                document_id: this.options['document_id'],
                kind: 3
            },
            onComplete: this.drawResults.bind(this)
        });
    },
    drawResults: function(data) {
        var container = new Element('div');
        if (data && data.responseJSON) {
            var sum = data.responseJSON.inject(0, function(acc,n){return acc + parseInt(n['rating']);});
            data.responseJSON.each(function(item,index){
                var share = Math.ceil( 100 * item['rating'] / sum );
                container.insert(new Element('div', {className: 'vote-share'}).update(item['text'] + '&nbsp;&mdash;&nbsp;' + share + '%'));
            });
        }
        this.bottom.innerHTML = '';
        this.bottom.insert(container);
    }
});

var loadDynamic = function(url) {
    var head = $$('head')[0];
    if (head) {
        var script = new Element('script', { type : 'text/javascript', src : url + '?' + Math.random(1,1000) });
        head.appendChild(script);
    }
}

window.onload = function(){
	if($('slider-handle') && $('slider-track')){
		var slider = new UI.Slider('slider-handle', 'slider-track', {
			area: 'slider_area',
			elements: 'li',
			min: 4,
			onSlide: function(v){
				slider.area.scrollLeft = Math.round(v / slider.maximum * (slider.area.scrollWidth - slider.area.offsetWidth));
			},
			onChange: function(v){
				slider.area.scrollLeft = Math.round(v / slider.maximum * (slider.area.scrollWidth - slider.area.offsetWidth));
			}
		});
	}

	new AnchorNav({
	    selector: 'a.anchornav',
        target: 'content'
	});
    if ($('programm_search')) loadDynamic('/js/program_search.js');
	if ($('programm_list')) new CProgrammPopups();
	
	/*
	konami.code = function(){
		$('header').addClassName('carpet-rise');
	}
	konami.load();	
    */

    var loginForm = $('login-form');
    if (loginForm) {
        var formInputs = loginForm.select('input[type=text],input[type=password]');
        var sendAuthForm = function(evt) {
            evt.stop();
            loginForm.request({
                onComplete: function(data){
                    if (data && data.responseJSON && data.responseJSON['status']) window.location.reload(true);
                    else formInputs.each(function(elem){
                        new Effect.Highlight(elem, {
                            startcolor: '#ee6666',
                            endcolor: '#ffffff',
                            duration: 0.3
                        });
                    });
                }
            });
            return false;
        }
        $(loginForm.down('input[type=submit]')).observe('click', sendAuthForm);
        loginForm.observe('submit', sendAuthForm);
    }

    Ajax.Responders.register({ onComplete : function(){
        Cufon.refresh('h1.key-color, h2.key-color, h3.key-color, h4.key-color, h5.key-color, h6.key-color, a.menu-url, li.menu-fruit-element a, button.ui-button span');
    }});

    $$('script[src]').filter(function(v){ return v.innerHTML; }).each(function(v){eval(v.innerHTML);});
}
