var Explorer = new Class({

initialize:function(){

if(window.ActiveXObject && !window.XMLHttpRequest){
this.flickerFix();
this.positionFixedEmulation();
this.hoverSubmit();
}
},

flickerFix:function(){

document.execCommand('BackgroundImageCache',false,true);
},

positionFixedEmulation:function(){

var c= document.styleSheets[0];
c.addRule('.fixed','top: expression(eval(document.documentElement.scrollTop));');
c.addRule('body','background-attachment: fixed;');
},

hoverSubmit:function(){
if(window.ActiveXObject && !window.XMLHttpRequest){
var i= $S('input');
$A(i).each(function(el){
if(el.getProperty('type') == 'button'){
el.addEvent('mouseover',function(){ this.setStyle('backgroundPosition','bottom left'); });
el.addEvent('mouseout',function(){ this.setStyle('backgroundPosition','top left'); });
}
},this);
}
}

});


var Btns = new Class({

initialize: function(o){
this.o= o;
this.btns= o.getElementsByClassName('btn');

$A(this.btns).each(function(el){
el.o = el.effect('opacity', {duration: 750, transition: Fx.sineInOut});

el.onmouseover= function(){

var curOpacity = el.getStyle('opacity') == undefined ? 1:Math.round((el.getStyle('opacity')) * 100) / 100;
this.fade(el,curOpacity,0.6);
}.bind(this);

el.onfocus= el.onmouseover;

el.onmouseout= function(){
if(el.getStyle){
var curOpacity = Math.round((el.getStyle('opacity')) * 100) / 100;
this.fade(el,curOpacity,1);
}
}.bind(this);

el.onclick= function(){
delete btns;
delete login;
}.bind(this);

el.onblur= el.onmouseout;
},this);
},

fade: function(el,curOpacity,opacity){
el.o.clearTimer();
el.o.custom(curOpacity,opacity);
}

});


var Pnav = new Class({

initialize: function(){

if($('pnav')){
this.items= $S('#pnav dd a');

$A(this.items).each(function(el){
if(!el.hasClassName('ignore')){
var o= new Element('div');
o.addClassName('over');

window.ActiveXObject && !window.XMLHttpRequest ? o.setStyle('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/pnav.item.over.bg.ie.html', sizingMethod='image')"):null;

if(el.hasClassName('dbl')){
o.addClassName('overDbl');
window.ActiveXObject && !window.XMLHttpRequest ? o.setStyle('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/pnav.item.dbl.over.bg.ie.html', sizingMethod='image')"):null;
}

o.over= o.effects('opacity', { duration: 750, transition: Fx.sineOut });
o.out= o.effects('opacity', { duration: 50, transition: Fx.sineOut });

o.onmouseover= function(){
el.delay ? $clear(el.delay):null;
el.isOver= true;
}

o.onclick= function(){ document.location= el.href; };


var oo= new Element('div');

var classNameAr= el.className.split(' ');

for(var x = 0; x < classNameAr.length; x++){
var c= classNameAr[x];
if(c.indexOf('icon') >= 0){
oo.addClassName(c);
}
}

oo.setHTML(el.innerHTML);

oo.injectInside(o);

o.injectInside(el);

el.o= o;

if(el.hasClassName('active')){
this.moveOver(el);
el.removeAttribute('href');
el.o.setStyle('cursor','default');
}else{
el.onmouseover= function(){ this.moveOver(el); }.bind(this);

el.onfocus= el.onmouseover;

el.onmouseout= function(){ this.moveOut(el); }.bind(this);

el.onblur= el.onmouseout;
}
}
},this);
}

},

moveOver:function(el){
if(el.isOver != true){
el.delay ? $clear(el.delay):null;
el.isOver= true;
el.o.out.clearTimer();
el.o.setStyle('left',194 + 'px');
el.o.over.move(0,-10);
}
},

moveOut:function(el){
el.delay= (function(){ el.o.over.clearTimer(); el.o.out.move(0,194); el.isOver = false; }).delay(100);
}

});




var ToTop= new Class({
/*
s:new Fx.Scroll({ duration: 300, transition: Fx.sineInOut }),

initialize:function(){
var b= document.getElementsByClassName('btnToTop');

$A(b).each(function(el){
el.setAttribute('href','javascript:void(0);');
el.addEvent('click',function(){ this.ToTop()}.bind(this));
},this);
},

ToTop:function(){
this.s.scrollTo($('login'));
}
*/
});


var Login= new Class({

maxHeight:274,
opacity:0,
Explorer:new Explorer('noinit'),

initialize:function(){
this.c= $('loginContent');
this.t= $('tabLogin');

this.t.setProperty('href','javascript:void(0)');

new ajax('inc/login.inc', { postBody: 'freak', update: 'loginContent', onComplete: function(){ this.switchPanels();  }.bind(this) }).request();
this.t.addEvent('click',function(){ this.expandCollapse()}.bind(this));
},

expandCollapse:function(){
if(this.opacity === 0){
this.c.eComplete= this.c.effect('height', { duration: 350, transition: Fx.sineInOut, onComplete: function(){ this.showHide(); this.opacity = 1; }.bind(this) });
this.c.e= this.c.effect('height', { duration: 350, transition: Fx.sineInOut });
this.c.eComplete.custom(0,this.maxHeight);
this.t.addClassName('clicked');
}else{
this.t.removeClassName('clicked');
this.showHide();
}
},

showHide:function(){
if(this.opacity === 0){
var h= $('hiddenLogin');
h.setStyle('opacity','0');
h.setStyle('display','block');
var hiddenMove= h.effect('opacity', { duration: 350, transition: Fx.sineInOut });
hiddenMove.custom(0,1);
}else{
var h= $('hiddenLogin');
var hiddenMove= h.effect('opacity', { duration: 350, transition: Fx.sineInOut, onComplete: function(){ this.c.e.custom(this.maxHeight,0); this.opacity = 0; }.bind(this) });
hiddenMove.custom(1,0);
}
},

switchPanels:function(){

this.Explorer.hoverSubmit();

frmLogin = new SmartForm('#frmLogin', { objNme: 'frmLogin', required: ['Username','Password'], processor: 'ajax.login.php', ignoreEmpty: true, evalScripts: true });
frmForgot = new SmartForm('#frmForgot', { objNme: 'frmForgot', required: [['forgotUser','email']], processor: 'ajax.forgot.php', ignoreEmpty: true });

this.la= $S('#frmLogin a');
this.la[0].addEvent('click', function(){ this.showHidePanel(this.frmLogin,1,0) }.bind(this));

this.fa= $S('#frmForgot a');
this.fa[0].addEvent('click', function(){ this.showHidePanel(this.frmForgot,1,0) }.bind(this));

this.frmLogin= $('frmLogin');
this.frmForgot= $('frmForgot');

this.frmForgot.setOpacity(0);
this.frmForgot.setStyle('display','block');

this.frmLogin.eOut= this.frmLogin.effect('opacity', { duration: 350, transition: Fx.sineInOut, onComplete: function(){ this.showHidePanel(this.frmForgot,0,1) }.bind(this) });
this.frmLogin.eIn= this.frmLogin.effect('opacity', { duration: 350, transition: Fx.sineInOut });
this.frmForgot.eOut= this.frmForgot.effect('opacity', { duration: 350, transition: Fx.sineInOut, onComplete: function(){ this.showHidePanel(this.frmLogin,0,1) }.bind(this) });
this.frmForgot.eIn= this.frmForgot.effect('opacity', { duration: 350, transition: Fx.sineInOut });
},

showHidePanel:function(panel,from,to){
if(from == 1){
panel.eOut.custom(from,to);
}else{
panel.eIn.custom(from,to);
}
}

});

var DemoLogin = new Class({

initialize:function(){
this.btn= $E('#header li.btnDemo a');
this.btn.addEvent('click', function(){ this.login()}.bind(this));
},

login:function(){
this.a= new ajax('ajax.login.html', { postBody: 'Username=demo&Password=demo&jsvalidated=true', onComplete: function(){ this.post(); }.bind(this) }).request();
},

post:function(){
this.response= this.a.transport.responseText.split('||');

if(this.response[0] == 'redirect'){
window.location= this.options.redirect;
}else if(this.response[0] == 'error'){
$('errorUpdate').setHTML(this.response[1]);
new Modal(null,'errorPanel',this.options.objNme);
}else if(this.response[0] == 'confirmation'){
$('confirmationUpdate').setHTML(this.response[1]);
new Modal(null,'confirmationPanel',this.options.objNme);
}else if(this.response[0] == 'continue'){

}

this.evalScripts();
},

evalScripts: function(){
if(scripts = this.response[1].match(/<script[^>]*?>.*?<\/script>/g)){
scripts.each(function(script){
eval(script.replace(/^<script[^>]*?>/, '').replace(/<\/script>$/, ''));
});
}
}

});

var btns, login,tips;

function delayOnload(){
tips= new Tips($S('a'));
}

var frmReseller;
var frmContact;
var frmForgot
var frmLogin

window.addEvent('load',function(){
new DemoLogin();
btns= new Btns($('oracle'));
new ToTop();
new Explorer();
new Pnav();

});

