var Accordion = Class.create();
Object.extend( Accordion.prototype, {
	active: null,
	_callback: "open",
	_id: 0,

	initialize: function(element)
	{

		Accordion.prototype._id++;
		this._pid = this._id++;
		this._content = element.select( '.accordion_content' )[0];
		this._toggle  = element.select( '.accordion_toggle' )[0];
		this._header  = element.select( '.accordion_header' )[0];
		this._rel = this._toggle.up().rel;
		
		Event.observe( this._toggle, 'click', this.callback_onclick.bindAsEventListener(this) );

		Event.observe( this._header, 'click', this.callback_onclick.bindAsEventListener(this) );
		this._header.title = "Click top open";
		
	},
	
	callback_onclick: function(e)
	{
  			this[this._callback]();
//		$( this._toggle ).innerHTML = this._callback;
		Event.stop(e);
	},
	
	open_user:function()
	{
		alert( 'You must override function "open_user"' );
		
	},
	
	open:function()
	{

		this._callback = 'close';

		active = Accordion.prototype.active;

		if( active ) {
			active.reset();
		}


		// call user function
		this.open_user();


		Accordion.prototype.active = this		
	},

	close:function()
	{
		new Effect.SlideUp( this._content, {queue:'front'} ); 
		this._callback = 'open';
		Accordion.prototype.active = null;
//		this._content.innerHTML = '';
	},
	
	reset:function()
	{

		this._content.hide();
		this._content.innerHTML = '';
		this._callback = 'open';
		this._toggle.InnerHTML = 'open';
		
		Accordion.prototype.active = null;

	}
	
});


function preload( prefix, imgs, ext ) {
  for( i=0; i<imgs.length; i++ ) {
    img = prefix + imgs[i];
    eval( img + '_on  = new Image();' );
    eval( img + '_on.src = \'images/'  + prefix + imgs[i] + '_on.' + ext + '\';' );
    eval( img + '_off  = new Image();' );
    eval( img + '_off.src = \'images/' + prefix + imgs[i] + '_off.' + ext + '\';' );

  }
}   

function preloader()
{
	for( i=1;i <= image_count; i++){
		eval( 'mood_' + i + ' = new Image();');
		eval( 'mood_' + i + '.src= "/images/' + i +'mood.jpg";' );			
	}
}


function change_image(){
	Element.setStyle('mood' + act_holder , {'zIndex':'0'} );
	act_image = act_image % image_count + 1;
	old_holder = act_holder;
	act_holder = !act_holder % 2;
	Element.setStyle('mood' + act_holder , {'zIndex':'10'} );
  $('mood' + act_holder).src = eval( "mood_" + act_image + ".src" );

	Effect.Appear( 'mood' + act_holder, { 
			afterFinish: function(){ Element.hide( 'mood' + old_holder); },
			transition: Effect.Transitions.sinoidal,
			duration: 1
	});
}

function mover( name ) {
    eval( "document.images." + name + ".src = " + name + "_on.src" );
}  

function mout( name )
{
    eval( "document.images." + name + ".src = " + name + "_off.src" );
}

  function checkTimeZone() {
     var rightNow = new Date();
     var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
     var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
     var temp = date1.toGMTString();
     var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
     var temp = date2.toGMTString();
     var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
     var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
     var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
     if (hoursDiffDaylightTime == hoursDiffStdTime) {
        alert("Time zone is GMT " + hoursDiffStdTime + ".\nDaylight Saving Time is NOT observed here.");
     } else {
        alert("Time zone is GMT " + hoursDiffStdTime + ".\nDaylight Saving Time is observed here.");
     }
  }
  
Effect.MoveBG = Class.create();
Object.extend(Object.extend(Effect.MoveBG.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'relative'
    }, arguments[1] || {});
    this.start(options);
  },
  setup: function() {
    // Bug in Opera: Opera returns the "real" position of a static element or
    // relative element that does not have top/left explicitly set.
    // ==> Always set top and left for position relative elements in your stylesheets 
    // (to 0 if you do not need them) 
//    this.element.makePositioned();
    pos =  this.element.getStyle( 'background-position' ).split( ' ' );
    this.originalLeft = parseFloat( pos[0] );
    this.originalTop  = parseFloat( pos[1] );
    
    if(this.options.mode == 'absolute') {
      // absolute movement, so we need to calc deltaX and deltaY
      this.options.x = this.options.x - this.originalLeft;
      this.options.y = this.options.y - this.originalTop;
      
    }
  },
  
  update: function(position) {

    this.element.setStyle({
      backgroundPosition: Math.round(this.options.x  * position + this.originalLeft) + 'px' + ' ' + Math.round(this.options.y  * position + this.originalTop)  + 'px' 
    });
  }
});                      
  
  function showTimezone()
  {
    d = new Date();

    m = d.getMinutes();
    s = d.getSeconds();
    h = d.getUTCHours() - 7;
  
    new Effect.MoveBG( 'hours', { y: -( h ) * 7, mode: 'absolute', duration: 0.5 } );
    new Effect.MoveBG( 'minutes', { y: -( m ) * 7, mode: 'absolute', duration: 0.5 } );    
    new Effect.MoveBG( 'seconds', { y: -( s ) * 7, mode: 'absolute', duration: 0.5 } );
  }


  Effect.Transitions.exponential = function(pos) {
    return 1-Math.pow(1-pos,2);
  }

try { document.execCommand( "BackgroundImageCache", false, true); } catch(e) {};
