/*

Class: UI.Interface
	The UI.Interface class let you replace default dom components by mooolego components.

Require:
	UI.Skin
	UI.Canvas
	UI.Element
	And the compinents you want to be replaced

Arguments:
	Options
	
Options: 
	target - (string) define the element container id of what you want to be replaced (nice english, is'nt it?)

Example:
	(start code)
	new UI.Interface({
		target : 'formular'
	});
	(end)
*/

var Interface = new Class({
	Implements : [Options, Events],
	
	options: {
		target: 'div.element',
		container : document.body
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.zIndex = 1;
		// this.handleBox(this.options.target,this.options.container);
	},
	
	handleBox: function(target,container) {
		document.body.getElements(target).each(function(el){
			/*el.store('coordinates',el.getCoordinates());
			
			
			
			
			
			var close = new Element('div',{
				styles : {
						position : 'absolute',
					bottom:0,
					right:0,
					width: '10px',
					height: '10px',
					backgroundColor:'#000',
					opacity:'.3'
				}					
			})
			.inject(el)
			.addEvents({
				click: function(){
					el.setStyle('display','none');
				}
			});
			
			el.addEvents({
				mousedown: function(){
					el.setStyle('zIndex',this.zIndex++);
				}.bind(this)
			});
			
			
			this.dragHandler = new Drag(el, {
				limit: {
					x: 1000,
					y: 1000
				},
				onStart: function() {
					
				},
				onDrag: function() {
				},
				onComplete: function() {
					el.setStyles({
						left :	el.retrieve('coordinates').left,
						top :	el.retrieve('coordinates').top
					});
				},
			});	*/
		},this);
	}
});


/*
Script: SmoothScroll.js
	Class for creating a smooth scrolling effect to all internal links on the page.

License:
	MIT-style license.
*/

var SmoothScroll = new Class({

	Extends: Fx.Scroll,

	initialize: function(options, context){
		context = context || document;
		var doc = context.getDocument(), win = context.getWindow();
		this.parent(doc, options);
		this.links = (this.options.links) ? $$(this.options.links) : $$(doc.links);
		var location = win.location.href.match(/^[^#]*/)[0] + '#';
		this.links.each(function(link){
			if (link.href.indexOf(location) != 0) return;
			var anchor = link.href.substr(location.length);
			if (anchor && $(anchor)) this.useLink(link, anchor);
		}, this);
		if (!Browser.Engine.webkit419) this.addEvent('complete', function(){
			win.location.hash = this.anchor;
		}, true);
	},

	useLink: function(link, anchor){
		link.addEvent('click', function(event){
			this.anchor = anchor;
			this.toElement(anchor);
			event.stop();
		}.bind(this));
	}

});

var externalLink = new Class({
	initialize: function(links) {
		this.links = $$(links);
		this.attach();
	},

	attach: function() {
		this.links.each(function(link){
			//console.log('link');
			if (!link.get('href').contains(window.location.host)) {
				//console.log(link.get('href'), window.location.host);
				//link.addClass('external');

			}
  		});
	}
});



window.addEvent('domready',function() { 
									
	$$('.menunet').setStyles({
		position:'absolute',
		top: '-1000px',
		left: '3000px'
							 
	});
	//smooooooth scrolling enabled
	/*
	this.sortableElements = new Sortables(document.body.getElements('.section'), {
   		constrain: false,
    	clone: true,
		opacity: .3,
    	revert: true/*,
    	onStart : function() { this.selector.hide(); }.bind(this),
    	onSort : function() { this.selector.show(); this.selector.select(); }.bind(this),
		onComplete : function() { this.selector.show(); this.selector.select(); }.bind(this)
	});
	*/
	new externalLink('a.link');   
	
	new SmoothScroll({ duration:700 }, window); 

	/*var background  = new UI.Element({
		label: 'new window',
		skin: 'demo',
		type: 'gradient',
		state: 'radial2',
		width: '100',
		height: '100'
	}).inject($(document.body));*/
});

