Element.implement({inputHint:function(val){switch(this.get('tag')){case'form':this.getElements('input[type="text"],textarea').inputHint(val);return this;case'input':case'textarea':this.store('default',(val||this.get('value')));this.addEvents({'focus':function(){if(this.get('value')==this.retrieve('default')){this.set('value','')}},'blur':function(){if(this.get('value').clean()==''){this.set('value',this.retrieve('default'))}}}).fireEvent('blur');default:return this}}});
function isEmpty(val){ if(val == null){return true;} for(var i=0; i < val.length; i++) { if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){ return false; } } return true; }
function isEmail(val){if (isEmpty(val)){ return false; }var i = 1,length = val.length;while ((i < length) && (val.charAt(i) != "@")){i++;}if ((i >= length) || (val.charAt(i) != "@")){ return false; }else { i += 2; }while ((i < length) && (val.charAt(i) != ".")){i++;}if ((i >= length - 1) || (val.charAt(i) != ".")){ return false; }else { return true; }}

function showHideElements(open){if (Browser.Engine.trident4){var elements = $$(document.getElementsByTagName('object'));elements.extend(document.getElementsByTagName(Browser.Engine.trident4 ? 'select' : 'embed'));elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });}}
var jsbox=new Class({Implements:[Options,Events],options:{from:'.jsbox',autostart:[false,0,0],width:120,height:120,htmlWidth:600,htmlHeight:250,overlay:true,opacity:0.8,border:1},initialize:function(options){this.setOptions(options);this.timer=0;this.index=0;this.opened=false;this.openClosePos={};this.attributes={};this.object={};this.build();switch($type(this.options.from)){case'string':this.from=$$(this.options.from);if(this.options.autostart[0]){this.open(this.from[this.options.autostart[1]])}this.from.each(function(el,i){el.addEvent('click',function(e){e.stop();this.open(el)}.bind(this))},this);break;case'element':var el=this.options.from;this.from=[el];this.options.autostart[0]?this.open(el):el.addEvent('click',function(e){e.stop();this.open(el)}.bind(this));break}},build:function(){this.overlay=new Element('div',{'class':'mask',styles:{display:'none','opacity':this.options.opacity},events:{'click':this.close.bind(this)}}).inject(document.body,'top');this.closeButton=new Element('div',{'class':'jswin-close'}).addEvent('click',this.close.bind(this));this.prevButton=new Element('div',{'class':'jswin-previous'}).addEvent('click',this.previous.bind(this));this.nextButton=new Element('div',{'class':'jswin-next'}).addEvent('click',this.next.bind(this));this.number=new Element('div',{'class':'jswin-number'});this.title=new Element('div',{'class':'jswin-title'});this.controlsInner=new Element('div',{'class':'jswin-controls-inner'}).adopt(this.prevButton,this.nextButton,this.number,this.title);this.controls=new Element('div',{'class':'jswin-controls'}).adopt(this.controlsInner);this.content=new Element('div',{'class':'jswin-content'});this.win=new Element('div',{'class':'jswin jswin-ns',styles:{display:'none','border-width':this.options.border}}).adopt(this.closeButton,this.content,this.controls).inject(document.body,'top');this.fxwin=new Fx.Morph(this.win,{duration:750,transition:Fx.Transitions.Cubic.easeOut});this.fxcontent=new Fx.Tween(this.content,{property:'opacity',duration:250}).set(0);this.fxcontrols=new Fx.Tween(this.controls,{property:'height',duration:250})},showOverlay:function(){var ssize=document.getScrollSize();this.overlay.setStyles({display:'',width:ssize.x+'px',height:ssize.y+'px'});showHideElements(true)},getOpenClosePos:function(el){var cords=el.getFirst()?el.getFirst().getCoordinates():el.getCoordinates();this.openClosePos={width:cords.width<0||cords.width>300?32:cords.width-(this.options.border*2),height:cords.height<60?32:cords.height-(this.options.border*2),top:this.options.autostart[0]?(this.options.autostart[2]?-50:cords.top):cords.top,left:this.options.autostart[0]?(this.options.autostart[2]?window.getWidth()/2:cords.left):cords.left};return this.openClosePos},open:function(el){this.index=this.from.indexOf(el);this.getOpenClosePos(this.from[this.index]);if(!this.opened){this.opened=true;if(this.options.overlay){this.showOverlay()}this.win.setStyles($merge({display:'',opacity:0.6},this.openClosePos));this.win.addClass('jswin-loading');this.load(this.index)}else{this.hide(this.index)}return false},load:function(index){var link=this.from[index];var relOptions={};this.attributes={title:link.title?link.title:'',number:index+1};this.win.addClass('jswin-loading');if($chk(link.rel)){var array=link.rel.split(',');array.each(function(el){var arr=el.split(':');relOptions[arr[0]]=arr[1]})}var extension=$defined(relOptions.type)?relOptions.type:link.href.substr(link.href.lastIndexOf('.')+1).toLowerCase();switch(extension){case'jpg':case'gif':case'png':this.type='image';break;default:this.type='html';break}this.number.set('html',this.attributes.number+' of '+this.from.length);this.title.set('html',this.attributes.title);if(this.type=='image'){this.object=new Image();this.object.onload=this.show.bind(this);this.object.src=link.href}else{var html_height=relOptions.height?relOptions.height.toInt():this.options.htmlHeight,html_width=relOptions.width?relOptions.width.toInt():this.options.htmlWidth;this.object=new Element('div',{styles:{padding:'20px',overflow:'auto',height:html_height}}).load($defined(relOptions.url)?relOptions.url:link.href);this.object.width=html_width;this.object.height=html_height;this.show()}},show:function(){var top=(window.getHeight()/2)-((this.object.height.toInt()/2))+window.getScrollTop(),left=(window.getWidth()/2)-(this.object.width/2);if(top<0){top=0}if(left<0){left=0}this.fxwin.cancel().start({width:this.object.width,height:this.object.height,top:top,left:left,opacity:1}).chain(function(){this.win.setStyle('height','').removeClass('jswin-ns').removeClass('jswin-loading');this.content.empty().adopt(this.object).fade('in');if(this.from.length>1){this.attributes.number==1?this.prevButton.addClass('jswin-previous-disabled'):this.prevButton.removeClass('jswin-previous-disabled');this.attributes.number==this.from.length?this.nextButton.addClass('jswin-next-disabled'):this.nextButton.removeClass('jswin-next-disabled');this.fxcontrols.cancel().start(this.controlsInner.getStyle('height'))}}.bind(this))},hide:function(index){this.fxcontrols.cancel().start(0);this.fxcontent.cancel().start(0).chain(function(){this.load(index)}.bind(this))},next:function(){if(this.index<this.from.length-1){this.index++;this.getOpenClosePos(this.from[this.index]);this.hide(this.index)}},previous:function(){if(this.index>0){this.index--;this.getOpenClosePos(this.from[this.index]);this.hide(this.index)}},close:function(){this.fxcontrols.start(0).chain(function(){this.win.addClass('jswin-ns').setStyle('height',this.object.height);this.content.empty();if(this.options.overlay){this.overlay.setStyles({display:'none',width:0,height:0});showHideElements()}this.fxwin.cancel().start({width:this.openClosePos.width,height:this.openClosePos.height,top:this.openClosePos.top,left:this.openClosePos.left,opacity:0.2}).chain(function(){this.opened=false;this.win.setStyle('display','none');this.openClosePos={}}.bind(this))}.bind(this))}});
