/*
Script: Corner.js
	Show Corner like Corner()
Author: 
	Tiago Mateus  -  tiagomsp@hotmail.com
License:
	MIT-style license.
Notes:
	Requie:
		Mootools-release-1.11.js ( Class.js , Class.Extras.js,Element.js)

*/

Corner=new Class({
    options:{
        width: 400,
        height: 200,
		top:0,
		left:0,
		style:"",
		thema:"default",
		path:"",
		imagesPath:"",
		inner:"",
		cornerWidth:18
    },
    initialize: function(id,options){
		if($defined($(id))){
			this.id=id;			
			var el=$(id);
			this.setOptions(options);
			this.options.width=$pick($pick(el.getProperty('width'),el.getStyle('width')),this.options.width);
			this.options.height=$pick($pick(el.getProperty('height'),el.getStyle('height')),this.options.height);
			el.setStyle('display','block');
			el.setStyle('width',this.options.width);
			el.setStyle('height',this.options.height);
	        this.options.inner=el.innerHTML;
	        this.options.path=this.getPath();
			this.options.imagesPath=this.options.path+this.options.thema+"/";
			if(window.ie5 || window.ie6){
				el.innerHTML="<div style=\"background:transparent url("+this.options.imagesPath+"tl.gif) left no-repeat;float:left;width:"+this.options.cornerWidth+"px;height:"+this.options.cornerWidth+"px;display:block;\"></div><div style=\"width:"+(this.options.width-(this.options.cornerWidth*2))+"px;background:transparent url("+this.options.imagesPath+"tm.gif) left bottom repeat-x;float:left;height:"+this.options.cornerWidth+"px;display:block\"></div><div style=\"background:transparent url("+this.options.imagesPath+"tr.gif) right no-repeat;float:right;width:"+this.options.cornerWidth+"px;height:"+this.options.cornerWidth+"px;display:block\"></div><div style=\"width:"+this.options.width+"px;background:transparent url("+this.options.imagesPath+"ml.gif) repeat-y;float:left;display:block;clear:both\"><div style=\"background:transparent url("+this.options.imagesPath+"mr.gif) right repeat-y;float:right;width:"+this.options.width+"px;height:"+this.options.height+"px;overflow:hidden;display:block;\"><img id=\""+el.id+"-scroll"+"\" src=\""+this.options.imagesPath+"scroll.gif\" style=\"float:right;margin-right:3px;position:absolute;display:block;cursor:hand;\"/><div id=\""+this.id+"\" style=\"height:"+this.options.height+"px;width:"+(this.options.width-(this.options.cornerWidth*2))+"px;margin:0 "+this.options.cornerWidth+"px 0 "+this.options.cornerWidth+"px;overflow:hidden;background:url("+this.options.imagesPath+"mm.gif) 50% 50%;display:block\">"+this.options.inner+"</div></div></div><div style=\"background:transparent url("+this.options.imagesPath+"bl.gif) left top no-repeat;float:left;width:"+this.options.cornerWidth+"px;height:"+this.options.cornerWidth+"px;display:block;clear:left\"></div><div class=\"br\"style=\"width:"+(this.options.width-(this.options.cornerWidth*2))+"px;background:transparent url("+this.options.imagesPath+"bm.gif) repeat-x;float:left;height:"+this.options.cornerWidth+"px;display:block\"></div><div style=\"background:transparent url("+this.options.imagesPath+"br.gif) right top no-repeat;float:right;width:"+this.options.cornerWidth+"px;height:"+this.options.cornerWidth+"px;display:block\"></div>"
			}else{
				el.innerHTML="<div style=\"background:transparent url("+this.options.imagesPath+"tl.png) left no-repeat;float:left;width:"+this.options.cornerWidth+"px;height:"+this.options.cornerWidth+"px;display:block;\"></div><div style=\"width:"+(this.options.width-(this.options.cornerWidth*2))+"px;background:transparent url("+this.options.imagesPath+"tm.png) left bottom repeat-x;float:left;height:"+this.options.cornerWidth+"px;display:block\"></div><div style=\"background:transparent url("+this.options.imagesPath+"tr.png) right no-repeat;float:right;width:"+this.options.cornerWidth+"px;height:"+this.options.cornerWidth+"px;display:block\"></div><div style=\"width:"+this.options.width+"px;background:transparent url("+this.options.imagesPath+"ml.png) repeat-y;float:left;display:block;clear:both\"><div style=\"background:transparent url("+this.options.imagesPath+"mr.png) right repeat-y;float:right;width:"+this.options.width+"px;height:"+this.options.height+"px;overflow:hidden;display:block;\"><div style=\"display:block;float:right;background-color:red;height:"+this.options.height+"\"><div id=\""+el.id+"-scroll"+"\" style=\"float:right;margin-right:3px;position:relative;display:block;cursor:hand;width:5px;height:50px;background-color:black\"></div></div><div id=\""+this.id+"\" style=\"height:"+this.options.height+"px;width:"+(this.options.width-(this.options.cornerWidth*2))+"px;margin:0 "+this.options.cornerWidth+"px 0 "+this.options.cornerWidth+"px;overflow:hidden;background:url("+this.options.imagesPath+"mm.png) 50% 50%;display:block\">"+this.options.inner+"</div></div></div><div style=\"background:transparent url("+this.options.imagesPath+"bl.png) left top no-repeat;float:left;width:"+this.options.cornerWidth+"px;height:"+this.options.cornerWidth+"px;display:block;clear:left\"></div><div class=\"br\"style=\"width:"+(this.options.width-(this.options.cornerWidth*2))+"px;background:transparent url("+this.options.imagesPath+"bm.png) repeat-x;float:left;height:"+this.options.cornerWidth+"px;display:block\"></div><div style=\"background:transparent url("+this.options.imagesPath+"br.png) right top no-repeat;float:right;width:"+this.options.cornerWidth+"px;height:"+this.options.cornerWidth+"px;display:block\"></div>"
			}
			el.id=el.id+"-Corner";
			var size=$(this.id).getSize().scrollSize.y;
			
			//if(size>=this.options.height){
			
			var id=this.id;
			var Slide = new Slider($(this.id+"-scroll").getParent(), $(this.id+"-scroll"), {	
				steps: size,	
				mode: 'vertical',
				onChange: function(step){
					$(id).scrollTo(0, step)
				}
			}).set(0);
			//}else{$(this.id+"-scroll").setStyle('display','none');}
			
			
		}else{alert("Javascript componet fail!\nid=\""+id+"\" Not Defined in Corner.js Componet")}
    },
	getPath:function(){
		var result;
		$$('script').each(function(el){
			var path=el.getProperty('src');
			var er =/Corner\/Corner.js/g;
			if (er.test(path)){result=path}
		});
		return result.substr(0,result.length-9);
	}
});
Corner.implement(new Options);