﻿/*-------------------------------------------------------
############ ASOS JS LIBRARY version 1.3 ################
##### created by: Pavel Jacko  ##########################
#### released: 04/06/2008 ###############################
#### updated: 04/06/2008 ################################
--------------------------------------------------------*/
CREATIVE_EX={};
ASOS={};
_E=CREATIVE_EX;
/*-------------------------------------------------------
#################### General functions ##################
--------------------------------------------------------*/
CREATIVE_EX.GEN={
			       
//------------- mouse handler: mouse() -------------------------------------
  findMouse:function(e){
    var posx = 0;
	var posy = 0;
	if (!e){ 
	    e = window.event;
	}
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
	//clientLeft prop. is set in IE as border of explorer vidow and needs to be removed
		posx = e.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft-this.$("html","tag",0).clientLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop-this.$("html","tag",0).clientTop;
	}
	
	return [posx,posy];
  }
//----- find element position: findPos(object,[parent]) ------------------------------------- 
  ,
findPos:function(obj,parent){
  if(parent){
    var x_val=_E.GEN.findPos(obj)[0]-_E.GEN.findPos(parent)[0];
    var y_val=_E.GEN.findPos(obj)[1]-_E.GEN.findPos(parent)[1];
    return [x_val,y_val];
  }
  else{
    var curtop = 0;
    var curleft = 0;//set default position to 0,0
	if (obj.offsetParent) {//if element has parent find all of them and count their pos"
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
  }
    
  }
  ,
valueConvert:function(val,type){
    if(!type)type="";
    return parseFloat(val.substr(0,val.length-type.length));   
  }
  ,
setAlpha:function(_obj,_val){
  if(!document.all || window.opera)
  {
    _obj.style.opacity = _val;
  }
  else
  {
    //alert(_val*100);
    _obj.style.filter = "alpha(opacity="+(_val*100)+")";
  }
}
  ,
getAlpha:function(_obj){
  if(!document.all || window.opera)
  {
    return _obj.style.opacity;
  }
  else
  {
  //alert(_obj.style.filter);
  var $op = _obj.style.filter.substring(14);
 $op = $op.substring(0,$op.indexOf(")"));
  
    return $op*0.01;
  }
}
//------------- mouse handler: mouse() -------------------------------------
  ,
  mouse:{
    x:NaN//set mouse.x property
    ,
    y:NaN//set mouse.y property
    ,
    object:null//set listen mouse.object propery
    ,
    listen:function(obj){

    _C.CORE.addEvent(obj, "mousemove", function (e) {//add mousemove handler
      //position of mouse relative to document - position of element
      var x_val=_E.GEN.findMouse(e)[0]-_E.GEN.findPos(obj)[0];
      //position of mouse relative to document - position of element
      var y_val=_E.GEN.findMouse(e)[1]-_E.GEN.findPos(obj)[1];
      _E.GEN.mouse.x=x_val;
      _E.GEN.mouse.y=y_val;
      _E.GEN.mouse.object=obj;//set listen object to current object
      
      }  
    );
    //handle mouseout so outside functions knows that mouse is out
    _C.CORE.addEvent(obj, "mouseout", function () {
      _E.GEN.mouse.x=NaN;
      _E.GEN.mouse.y=NaN;
      _E.GEN.object=null;
      }
      );
    //}
    }
    ,
    listenAll:function(obj){
   //alert(_C.CORE.isArray(_C.CORE.$("divCoord2")));
      if(_C.CORE.isArray(obj)){
        for(var i=0;i<obj.length;i++){
          _E.GEN.mouse.listen(obj[i]);
        }
      }
      else{
        _E.GEN.mouse.listen(obj);
      }
    }
  }
};
/*-------------------------------------------------------
#################### object cache #####################
--------------------------------------------------------*/  

CREATIVE_EX.FX={};//cache for objects 

/*-------------------------------------------------------
#################### Animation functions ##################
--------------------------------------------------------*/  	
 	
CREATIVE_EX.ANI={
  speed:function(arr,speed){
    var help_l=arr.length;
    for(var x=0;x<speed;x++){
      for(var i=0;i<help_l;i++){
      arr.splice(i*2,0,[arr[i*2]]);
    }
    }
    
  }
  ,
 
 animating:function(obj,arr,dir,curr_frame,end,styleObj,ext){
	var cDir=_E.ANI.cDirection(arguments.callee);
	var cArr=_E.ANI.cArray(arguments.callee);
	var cFrame=_E.ANI.cActFrame(arguments.callee);
	var cEnd=_E.ANI.cEndFrame(arguments.callee);
	_E.ANI.cNextFrame(arguments.callee);
    _E.ANI.staticStyle(obj,styleObj,cArr[cFrame][0],ext);//fid value in frame array trought act-array
  }
  ,
  dropDown:function(_obj,_vals,_time){
  var obj=_C.CORE.$(_obj);
  var $links=_C.CORE.$(_obj+"_links");
  var $t=_time*33;//counts miliseconds in one minute
  
  var helpVal=(_vals[1]-_vals[0])/$t;
  var $ctr= _vals[0];
  var final_arr=[];
  for(var i=0;i<$t;i++){
    final_arr.push([$ctr]);
    $ctr+=helpVal;
  }
  obj.style.zIndex=500;
    _E.ANI.animation(_E.ANI.animating,obj,0,0,obj,final_arr,1,0,"pause","height","px");
    var $dir = _E.ANI.cache[(_E.ANI.cacheFind(obj,false))][7];
    _C.CORE.addEvent(obj,"mouseover",function(){
        _E.ANI.play(obj,0,"",false);
        _E.ANI.cache[(_E.ANI.cacheFind(obj,false))][8]=1;
        $links.style.display="block";
        //obj.style.borderWidth="1px";
        //obj.style.top="30px";
        //obj.style.left="-1px";
    });
    _C.CORE.addEvent(obj,"mouseout",function(){
        //obj.style.borderWidth="0px";
        //obj.style.top="31px";
        //obj.style.left="0px";
        $links.style.display="none";
        _E.ANI.cache[(_E.ANI.cacheFind(obj,false))][8]=-1;
        _E.ANI.play(obj,0,"",false);
        
    });
    
  }
  ,

  dynamicStyle:function(obj_arr,end_val,step,style,val_type,array){
    if(!array){
    //alert(obj_arr.style.opacity);
    if(style=="opacity" && (document.all && !window.opera)){//for IE
    var value=obj_arr.filters.alpha.opacity;
    //alert(value);
    value+=step*100;
    //alert(value);
    if((value>end_val*100 && step*100<=0) || (value<end_val*100 && step*100>=0))obj_arr.filters.alpha.opacity=value;
    else obj_arr.filters.alpha.opacity=end_val*100;//end value+"px"or "%"
    //alert(obj_arr.filters.alpha.opacity);
    }
    else{
    //console.log(start_vals+" "+cur_vals);
    //console.log(_E.GEN.findDim(obj_arr));
    var value=_E.GEN.valueConvert(obj_arr.style[style],val_type);
    //console.log(obj_arr.id+" : "+"style: "+style+": "+value);
    //console.log(value);
    value+=step;
    if((value>end_val && step<=0) || (value<end_val && step>=0))obj_arr.style[style]=value+val_type;
    else{
     obj_arr.style[style]=end_val+val_type;//end value+"px"or "%"
     //_E.ANI.button_lock=true;
     }
    //obj_arr[i].style.width=pos[0]+"px";
    }
    }
    else{
    //future code for dynamically created cache based style
    }
  }
  
  ,



  
//-------core fading: fading(id,strartvalue, endvalue, step|arrayofsteps, stop|pause|loop, smoothchange:true|false)----
  fading:function(obj_arr,start_val,end_val,step,selfstop,swap){
    this.counter=_E.ANI.counter;//set new unique counter
    var a=this.counter("count1",start_val,end_val,step,selfstop,swap);//call couter
    if(a!=undefined){//protect counter to pass undefined value after delete from cache(IE bug)
      if(!obj_arr[0]){
      obj_arr.styl=_E.ANI.style;//set new unique style
      obj_arr.styl("opacity",a);//call style(id)  
      }
      else{//if id is passed as array(class,tag)
        for(var i=0;i<obj_arr.length;i++){
          if (!document.all || window.opera) {
            obj_arr[i].style["opacity"]=a/100;
          }
          else {
            obj_arr[i].style.filter = "alpha(opacity=" + a + ")";
          }
        }
      }
    }
  }
  ,
//#UI fade: fade(func_id,prepause, duration, idname, id|class|tag|this, strartvalue, endvalue, step|arrayofsteps, stop|pause|loop, smoothchange:true|false)----
  fade:function(start_time,duration,obj_arr,start_val,end_val,step,selfstop,swap){
    
  var obj_ready=_E.ANI.convert(obj_arr);
    
    //console.log("fade:"+obj_ready);
    _E.ANI.animation(_E.ANI.fading,obj_ready,start_time,duration,obj_arr,start_val,end_val,step,selfstop,swap);
  }
	,

  cDirection:function(object){
  return _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][8];
  }
  ,
  cArray:function(object){
  return _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][7];
  }
  ,
  cActFrame:function(object){
  return _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9];
  }
  ,
  cEndFrame:function(object){
  return _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][10];
  }
  ,
  cNextFrame:function(object){
  var act_frame=_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9];
      act_frame=act_frame+_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][8];//frame++
    
    if(act_frame>=_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][7].length){
      switch(_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][10]){
       case "stop":
        //console.log("stop");
        _E.ANI.stop(object.arguments[0],false);
       break;
       case "pause":
        
        //_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9]=_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][7].length-20;//safe end
       _E.ANI.pause(object.arguments[0],false);
       //console.log("paaaaaaaaaaaaaaaaaaaaause");
       break;
       case "loop":
        _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9]=0;
       break;
       case "reverse":
        _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9]=_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][7].length-2;//set last frame to 1 smaller as last was edge
        _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][8]=-1;
       break;
       default:
        //console.log("function")
        _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][10]();
      }
    }
    //else _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9]=act_frame;
    
    if(act_frame<0){
      switch(_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][10]){
       case "stop":
        //console.log("stop");
        _E.ANI.stop(object.arguments[0],false);
       break;
       case "pause":
        _E.ANI.pause(object.arguments[0],false);
       break;
       case "loop":
        _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9]=_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][7].length-1;
       break;
       case "reverse":
        //console.log("reverse");
        _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9]=1;//set frame to 1 as previous was 0
        _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][8]=1;
       break;
       default:
        //console.log("function")
        _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][10]();
      }
    }
    if(act_frame>=0 && act_frame <=_E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][7].length-1) _E.ANI.cache[(_E.ANI.cacheFind(object.arguments[0],false))][9]=act_frame;
    
  }
  ,
  staticStyle:function(obj,style_name,val,ext){//
    switch(style_name) {
      case "opacity":
      if (!document.all || window.opera) {
        obj.style[style_name]=val;
      }
      else {
        obj.style.filter = "alpha(opacity=" + val*100 + ")";
      }
      break;
      default:
        obj.style[style_name]=val+ext;
    }; 
  }
  ,
//#UI fade: fade(func_id,prepause, duration, idname, id|class|tag|this, strartvalue, endvalue, step|arrayofsteps, stop|pause|loop, smoothchange:true|false)----
  fadeInOut:function(listen_obj,obj_arr,prepause,start_val,end_val,speed,event,lock){
 
  //registering events
    if(listen_obj[0]){//register animation to more objects
      for(var i=0;i<listen_obj.length;i++){
        _C.CORE.addEvent(listen_obj[0],event,function(){
          //if(lock!=true)_E.ANI.stop(obj_arr);
          //alert(_E.ANI.cache);
          _E.ANI.fade(0,"",obj_arr,start_val,end_val,speed,"stop",false);
        });
      }
    }
    else{  
      _C.CORE.addEvent(listen_obj,event,function(){
        //if(lock!=true)_E.ANI.stop(obj_arr);
        //console.log(this.cache);
        _E.ANI.fade(0,"",obj_arr,start_val,end_val,speed,"stop",false);
      });
    }
    
    
  }
	,
//-------external frame counting: counter(count_id,strartvalue, endvalue, step, stop|pause|loop,swapping)----
  counter:function(id,start_val,end_val,step,selfstop,swap){
    if(selfstop){//if been passed more than 2 parameters overally
    var obj=id;
    var obj_arr=id+"arr";
    //console.log(this.id);
    if(this[obj]==undefined){
      this[obj]=-1;//begining value(before return will count +1)
      this[obj+"arr"]=[];
      var arr_val=start_val;
      if(step.pop){//if step is passed as array(make array of keyframes)
        this[obj+"arr"].push(start_val);
        this[obj+"arr"]=this[obj+"arr"].concat(step);
        this[obj+"arr"].push(end_val);
      }
      else{//or step is just single value and find keyframes
        if(end_val<start_val){
        var fk=(start_val-end_val)/step;
        for(var i=0;i<fk;i++){
          this[obj+"arr"][i]=arr_val;
          arr_val=arr_val-step;
        } 
        this[obj+"arr"].push(end_val);//put last value
        }
        else{
        var fk=(end_val-start_val)/step;
        for(var i=0;i<fk;i++){
          this[obj+"arr"][i]=arr_val;
          arr_val=arr_val+step;
        } 
        this[obj+"arr"].push(end_val);//put last value
        }
      } 
    } 	
    var y=this[obj];
    //console.log("itselfname:"+this.id);
    if(selfstop!="" && y>=this[obj+"arr"].length-1 && end_val!==""){
      if(selfstop=="loop"){//code for swapping
        if(swap==true){this[obj+"arr"].reverse();}//if set swapping change order of array
        this[obj]=-1;//set back to begining value 
        return this[obj+"arr"][y+1];//return same value while swapping
      }
      else{
      /*if(arguments[6]!=""){
     //console.log(this.id);
      //this.func=function(){alert(this.id);}(); 
      }*/
      _E.ANI[selfstop](this.id,false);//stop or pause animation
      //console.log("autostop"+this.id);
      
      return this[obj+"arr"][y+1];
      } 
    } 
    y++;
    this[obj]=y;
      
    //console.log(y);
    //console.log("len "+this[obj+"arr"][y]);
    
    return this[obj+"arr"][y];//return value of counter
    }
    else{
    if(this[obj]==undefined)this[obj]=[0,0];
    var x=this[obj][0];
    var y=this[obj][1];
    //alert(y);
    x+=start_val;
    y+=end_val;
    this[obj][0]=x;
    this[obj][1]=y;
    //if(_E.ANI.cacheFind(id,false)[9]==undefined)_E.ANI.cacheFind(id,false).push((this[obj][0])/step,(this[obj][1])/step);
    //_E.ANI.cacheFind(id,false)[9]=[(this[obj][0])/step,(this[obj][1])/step];
    _E.ANI.cache[(_E.ANI.cacheFind(id,false))][10]=[(this[obj][0])/step,(this[obj][1])/step];
    //console.log(id.id+": "+_E.ANI.cache[(_E.ANI.cacheFind(id,false))][10]+" #### "+[(this[obj][0])/step,(this[obj][1])/step]);
    return [(this[obj][0])/step,(this[obj][1])/step];
    
    }
  }
	,
//-------------------------- style object -------------------------------------------------
  style:function(style_name,val){//one timer for all animations(itself timeout recurection)
    switch(style_name) {
      case "opacity":
      if (!document.all || window.opera) {
        return this.style[style_name]=val/100;
      }
      else {
        return this.style.filter = "alpha(opacity=" + val + ")";
      }
      break;
      case "top":
        return this.style.top =val + "px";
      break;
      case "left":
        return this.style.left =val + "px";
      break;
      case "width":
        return this.style.width =val + "px";
      break;
      case "height":
        return this.style.height =val + "px";
      break;
    }; 
  }
  ,
//------------------------- cache for animated functions and objects	-----------------------------
	cache:[]//create cache for animated functions
  ,
//-------------------------- root single timeline -------------------------------------------------
  timer:function(){//one timer for all animations(itself timeout recurection)
    this.T1=setTimeout(
      function(){
        _E.ANI.animate();
        _E.ANI.timer();
      },30
    );    
  }
  ,
//-------------------------- test func to ensure calling setTimeout once ---------------------------
  begin:function(){
    if(this.timer_Eounting==false){
      _E.ANI.timer();
      this.timer_Eounting=true;
    }
  }
  ,
//-------------------------- automated calling of all objects from cache ---------------------------
  animate:function(){
  //take values from cache:([function, id, cache index, starttime | startvalue, duration, endtime | endvalue, originalFunctionParameters])
      for(var i=0;i<this.cache_length;i++){
        //check initial pause + passed duration + if duration is set to nonstop
        if((this.actTime()<this.cache[i][5] & this.actTime()>this.cache[i][4]) ||(this.actTime()>this.cache[i][4] & typeof(this.cache[i][5])!="number") ){        
          //calling abstract function with recurection to real object in FX
          this.cache[i][0].apply(_E.FX[this.cache[i][1]],this.cache[i].slice(6));//call function trough itself parent object
        }
      }
  }
  ,
//-------------------------- setting real-time for ani objects --------------------------------------
  actTime:function(){
    return (new Date()).getTime();
  }
  ,
//-------------------------- initialize ani function ------------------------------------------------
  animation:function(func,id,prepause,duration){
  //console.log("cache from animation"+_E.ANI.cache.length); 
    //preventing calling same fx more than once
    var rem_obj;
    for(var i=0;i<this.cache_length;i++){
      if(this.cache[i][1]==_E.ANI.convert(id)){//find array with specified id
        rem_obj=i;//attach index of found row
        this.stop(id);
        //console.log("cachesize after animation stop:"+_E.ANI.cache.length);
        break;
      }
    } 
    //console.log("normal continue animation");
    //if(rem_obj==undefined){//if fx not already exist create one   
      var index=_E.ANI.cache.length;
      var startTime=_E.ANI.actTime()+prepause;//set delay before start
      var endTime=_E.ANI.actTime()+duration+prepause;//set final timeout
      var helpArr=[func,id,index,_E.ANI.actTime(),startTime,endTime];//push root values to cache
      for(var i=4;i<arguments.length;i++){//first 4 arguments are already set
        helpArr.push(arguments[i]);//push all parameters from function to cache
      }
      _E.ANI.cache.push(helpArr);//push new row to cache
      _E.FX[this.cache[this.cache_length][1]]={};//prepare new object for animated function
      _E.FX[this.cache[this.cache_length][1]].id=id;
      this.cache_length=_E.ANI.cache.length;//update cache  
      _E.ANI.begin();//start animation
    //}
  }
  ,
//-------------------------- pause of animation without removing it from cache ------------------------
  pause:function(id,use_Eonversion){//pause of animation(object won"t be removed from cache): pause(obj.index | all)
    
    if(id=="all"){//pause all obj
      for(var i=0;i<=this.cache_length;i++){
        this.cache[i][5]=this.actTime();//set end of animation value to actual time
      }
    }
    else{
      var rem_obj;
      if(use_Eonversion!=false)var obj_ready=_E.ANI.convert(id);
      else obj_ready=id;
      for(var i=0;i<this.cache_length;i++){
        if(this.cache[i][1]==id){//find array with specified id
          rem_obj=i;//attach index of found row
        break;
        }
      } 
      if(rem_obj!=undefined){
        this.cache[rem_obj][5]=this.actTime();//pause just selected obj
       } 
    } 
  }
  ,
//-------------------------- stop of animation with removing from cache -------------------------------
  stop:function(id,use_Eonversion){
    //if id is passed as result of _E.ANI.$() func, change to appropiate name
    
    if(id=="all"){//remove all objs from cache
      this.cache=[];//empty cache
      _E.FX={};//empty all animated objects
      this.cache_length=0;//reset cache
    }
    
    else{
      var rem_obj;
      if(use_Eonversion!=false)var obj_ready=_E.ANI.convert(id);
      else obj_ready=id;
      for(var i=0;i<this.cache_length;i++){
        if(this.cache[i][1]==obj_ready){//find array with specified id
          rem_obj=i;//attach index of found row
          //console.log("stopped!")
        this.cache.splice(rem_obj,1);//remove specified row from cache
        
        _E.FX[obj_ready]=null;//remove object with function
        this.cache_length--;
        break;
        }
      } 
      
          } 
  }
,
//-------------------------- play paused object ------------------------
  play:function(id,prepause,duration,use_Eonversion){//play paused object: play(id, [duration in miliseconds])
    //if id is passed as result of _E.ANI.$() func, change to appropiate name
    if(id=="all"){//play all objects
      for(var i=0;i<=this.cache_length;i++){
        this.cache[i][5]=this.actTime()+duration;//set end of animation value to actual time+duration
      }
    }
    else{
      var rem_obj;
      if(use_Eonversion!=false)var obj_ready=_E.ANI.convert(id);
      else obj_ready=id;
      for(var i=0;i<this.cache_length;i++){
        if(this.cache[i][1]==obj_ready){//find array with specified id
          rem_obj=i;//attach index of found row
          this.cache[rem_obj][5]=this.actTime()+duration;//play just selected obj
          this.cache[rem_obj][4]=this.actTime()+prepause;//play just selected obj
        break;
        }
      } 
    } 
  }
  ,
//-------------------------- convert object in caches ------------------------
  convert:function(obj_arr){//play paused object: play(id, [duration in miliseconds])
    switch(obj_arr.typ) {//creatin unique id names for FX cache
      case "id":
      obj_ready=obj_arr.id+obj_arr.typ;
      break;
      case "class":
      obj_ready=obj_arr[0].className+obj_arr.typ;
      break;
      case "tag":
      obj_ready=obj_arr[0].tagName+obj_arr.typ;
      break;
    };
    return obj_ready; 
  }
  ,
//-------------------------- convert object in caches ------------------------
  cacheFind:function(obj_arr,use_Eonversion){//(object,conversion)
      if(use_Eonversion!=false)var obj_ready=_E.ANI.convert(obj_arr);
      else obj_ready=obj_arr;
      for(var i=0;i<this.cache_length;i++){
        if(this.cache[i][1]==obj_ready){//find array with specified id
          return i;
        }
      } 
     
  }
  /*circFading:function(obj_arr,start_val,end_val,step,selfstop,swap){
  
    this.counter=_E.ANI.counter;//set new unique counter
    if(!this.counter2)this.counter2=0;
    var a=this.counter("count1",start_val,end_val,step,selfstop,swap);//call couter
    if(a!=undefined){//protect counter to pass undefined value after delete from cache(IE bug)
      
       
          if (!document.all || window.opera) {
            obj_arr[this.counter2].style["opacity"]=a/100;
          }
          else {
            obj_arr[this.counter2].style.filter = "alpha(opacity=" + a + ")";
          }
        
      
      if(a==end_val){
      //console.log(this.id);
      
      
      _E.ANI.play(this.id,5000,"",false);
      if (!document.all || window.opera) {
            obj_arr[this.counter2].style["opacity"]=start_val/100;
          }
          
          
          else {
            obj_arr[this.counter2].style.filter = "alpha(opacity=" + start_val + ")";
          }
          //console.log(obj_arr.length);
          for(var i=0;i<obj_arr.length;i++){
        obj_arr[i].style["zIndex"]=obj_arr[i].style["zIndex"]+1;
      }
          obj_arr[this.counter2].style["zIndex"]=0;
          if(this.counter2>=obj_arr.length-1)this.counter2=0;
          else this.counter2=this.counter2+1;
      }
    }
  }*/
  
};

_E.ANI.cache_length=0;//initialize cache to empty
_E.ANI.timer_Eounting=false;//set timer to stop
/*-------------------------------------------------------
  #################### Image functions ##################
--------------------------------------------------------*/

CREATIVE_EX.IMG={
	
//preload (path to images, extension, number of images to preload)
	  
    "preload":function(path, xt, count) {
    	for (var i=1;i<=count;i++) {
	var j=new Image();
	j.src=path+i+"_over."+xt;
	}
    },

//rollovers assignemt, first fixes parameters, than preload or images
//than changes links to images and writes mouse-over and mouse-out events
        
    "rollovers":function(folder, object, xt, className, _addObjects, _trigger, _tParams) {
    //console.log(typeof(_trigger));
	var data=_E.IMG.lib.fixdata(folder, object, xt, className);
	_E.IMG.preload(data.path, data.xt, data.count);
	var links=_C.CORE.$.call(data.object, data.className, "class");
	for (var i=0;i<links.length;i++) {
	var $alt= links[i].innerHTML;
	var _img=document.createElement("img");
	_img.src=data.path+(i+1)+"."+data.xt;
	_img.alt = $alt;
	links[i].title = $alt;
	_C.CORE.addEvent(_img, "mouseover", new Function("_E.IMG.changeImage(this, \""+data.path+(i+1)+"_over."+data.xt+"\")"));
	_C.CORE.addEvent(_img, "mouseout", new Function("_E.IMG.changeImage(this, \""+data.path+(i+1)+"."+data.xt+"\")"));
	
//	if(_addObjects != undefined || _addObjects!=null){
//	    for(var i2 = 0;i2<_addObjects.length;i2++){
//	        _C.CORE.addEvent(_img, "mouseover", new Function("_E.IMG.change(\""+_addObjects[i2]+(i+1)+"\",\"block\","+_trigger+",\""+_tParams+"\" )"));
//	        _C.CORE.addEvent(_img, "mouseout", new Function("_E.IMG.change(\""+_addObjects[i2]+(i+1)+"\",\"none\","+_trigger+" ,\""+_tParams+"\" )"));
//	    }
//	}  
//	console.log(_tParams); 
	links[i].innerHTML="";
	links[i].appendChild(_img);
	
	}
},

//lib=library
//object for helper functions

    "lib":{
	   
	//fixdata - fixes parameters that are passed to rollovers function
	 
	fixdata:function(folder, object, xt, className) {
	className=className||"rollover";
	object=object?_C.CORE.$(object):document;
	var path;
	//alert(folder.charAt(0));
	if(folder.charAt(0) == "/"){
	    path= folder+"/"+className;
	}
	else{
	    path=_C.prefix + folder+"/"+className;
	}
	xt=xt||"jpg";
	//console.log(object)
	//console.log(_C.CORE.$.call(object, className, "class"));
	var count=_C.CORE.$.call(object, className, "class").length;
	//console.log(count)
	return {path:path,object:object,xt:xt,className:className,count:count};
	}
     },
     
     //change image - changes object (which must be image) to another image
     
       "changeImage":function(object, what) {
	object.src=what;
	}
	,
	"change":function(_obj,_display,_trigger,_tParams){
	    //console.log(_obj);
	    if(_trigger!= undefined || _trigger!=null){
	        _trigger.apply(_tParams);
	        //console.log(_tParams);
	    }
	    if(_C.CORE.$(_obj)!= undefined || _C.CORE.$(_obj)!=null){
	        _C.CORE.$(_obj).style.display = _display;
	    }
	    
	}
  };
 

/*-------------------------------------------------------
  ################## ASOS custom interface ###########
--------------------------------------------------------*/
ASOS={
//-------fRollOvers()---------------------------------------------------------
    fRollOvers:function(parent_obj,listen_obj,attach_obj){
     
     switch(arguments.length){
     case 1://listening itself
     _E.ANI.fadeInOut(_C.CORE.$(arguments[0],"class"),_C.CORE.$(arguments[0],"class"),0,0,100,10,"mouseover",false);
      _E.ANI.fadeInOut(_C.CORE.$(arguments[0],"class"),_C.CORE.$(arguments[0],"class"),0,100,0,10,"mouseout",false);
     break;
     case 2://listening and attaching the same class
     var ix=1;
     var a=1;

        while(a==1){
        if(!_C.CORE.$(parent_obj).$(listen_obj+ix,"class")[0]){
        ix=ix-1;
        a=0;
        }
        else ix=ix+1;
        
        }
     for(var i=1;i<=ix;i++){
     _E.ANI.fadeInOut(_C.CORE.$(listen_obj+i,"class"),_C.CORE.$(listen_obj+i,"class"),0,0,100,10,"mouseover",false);
      _E.ANI.fadeInOut(_C.CORE.$(listen_obj+i,"class"),_C.CORE.$(listen_obj+i,"class"),0,100,0,10,"mouseout",false);
      }
     break;
     case 3:
     var ix=1;
     var a=1;

        while(a==1){
        if(!_C.CORE.$(parent_obj).$(listen_obj+ix,"class")[0]){
        ix=ix-1;
        a=0;
        }
        else ix=ix+1;
        
        }
     for(var i=1;i<=ix;i++){//listening class and attaching different class
     _E.ANI.fadeInOut(_C.CORE.$(listen_obj+i,"class"),_C.CORE.$(attach_obj+i,"class"),0,0,100,10,"mouseover",false);
      _E.ANI.fadeInOut(_C.CORE.$(listen_obj+i,"class"),_C.CORE.$(attach_obj+i,"class"),0,100,0,10,"mouseout",false);
      }
     break;
     }   

    }
  ,
//-------autoRollOvers() (imagefolder, parent object,extension, classname)
  autoRollOvers:function(folder, object, xt, className  ){
	 var data=_E.IMG.lib.fixdata(folder, object, xt, className);
	 _E.IMG.preload(data.path, data.xt, data.count);
	 var links=_C.CORE.$.call(data.object, data.className, "class");	 
	 for (var i=0;i<links.length;i++) {
	    var $con = links[i].innerHTML;
	   //create 2 images inside of anchor and put 2nd image under function fRollOvers()
	   var code='<img src="'+data.path+(i+1)+'.'+data.xt+'" alt="'+ $con+'" style="position:absolute;top:0px;left:0px;"/><img class="'+className+(i+1)+'" src="'+data.path+(i+1)+'_over.'+data.xt+'" alt="'+ $con+'" style="position:absolute;top:0px;left:0px;opacity:0;filter: alpha(opacity=0);"/>';
	   links[i].innerHTML=code;//put code into anchor
	   ASOS.fRollOvers(object,className);//call fRollOvers() for 2nd image
	 }
	}
	,
	tRollOvers:function(folder, object, xt, className, _addObjects  ){
	 var data=_E.IMG.lib.fixdata(folder, object, xt, className);
	 _E.IMG.preload(data.path, data.xt, data.count);
	 var links=_C.CORE.$.call(data.object, data.className, "class");	 
	 for (var i=0;i<links.length;i++) {
	   //create 2 images inside of anchor and put 2nd image under function fRollOvers()
	   var code='<img src="'+data.path+(i+1)+'.'+data.xt+'" style="position:absolute;top:0px;left:0px;"/><img class="'+className+(i+1)+'" src="'+data.path+(i+1)+'_over.'+data.xt+'" style="position:absolute;top:0px;left:0px;opacity:0;filter: alpha(opacity=0);"/>';
	   links[i].innerHTML=code;//put code into anchor
	   //ASOS.fRollOvers(object,className);//call fRollOvers() for 2nd image
	   	

	 }
	},
	moveBlog:function(){
	    var $speed = 1;
	    //ANI.addTween(_C.CORE.$("blogStrip").style,{time:10,left:500,transition:"linear"});
	    var $blog = _C.CORE.$("blogStrip");
	    //alert($blog.style.left);
	    function movingBlog(){
	        //console.log("aaa");
	        var $l = _E.GEN.valueConvert($blog.style.left,"px");
	        $blog.style.left = ($l-$speed)+"px";
	        if($l<-_C.CORE.blogEntryWidth)
	        {
	            $blog.style.left = "0px";
	        }
	        //_E.ANI.style("left",100);
	    }
	    _E.ANI.animation(movingBlog,$blog,0,"",$blog);
	    _C.CORE.addEvent($blog, "mouseover", ASOS.stopBlog);
	    _C.CORE.addEvent($blog, "mouseout", ASOS.startBlog);
	    
	},
	circFading:function(_data){
	//UI
	var $con = _C.CORE.$("fadingNav");
	    
	
	    var $navItems = [];
	    var $navBars = [];
	//ANIMATION
	    var $data = [];
	    var $currFade = 0;
	    var $stopFade = null;
	    var $n = 1;
	    var $paused = false;
	    var $fadeActive = true;
	    var $bw = 0;
	    var $barSpeed = 0.5;
        for(var i=0;i<_data.length;i++)
        {
            //images
            $data.push(_C.CORE.$(_data[i]));
            $data[i].style.zIndex = _data.length - i;
            _E.GEN.setAlpha($data[i],1);
            //buttons
            var $b1 = document.createElement("a");
            $b1.className="circ_btn";
            $b1.href="#";
            $b1.id="circBtn"+i;
            $b1.style.left = (44*i)+"px";
            _C.CORE.addEvent($b1, "click",gotoPage);
            var $bIn = document.createElement("img");
            $bIn.className="circ_btnIn";
            //$bIn.href = "#";
            $bIn.src = "http://images.asos.com/homepage/2008_08_26_AWSiteRefresh/w/btn"+(i+1)+".gif";
            $bIn.id = "circBtnIn"+i;
            _C.CORE.addEvent($bIn, "mouseover",onOver);
            _C.CORE.addEvent($bIn, "mouseout",onOut);
            //$bIn.innerHTML = "";
            
            var $bBar = document.createElement("div");
            $bBar.className="circ_btnBar";
            
            $b1.appendChild($bBar);
            $b1.appendChild($bIn);
            $con.appendChild($b1);
            $navItems.push($b1);
            $navBars.push($bBar);
            //btn bars
            
        }
            var $b1 = document.createElement("a");
            $b1.id="circPause";
            $b1.className="circ_pause";
            $b1.href = "#";
            //$b1.innerHTML = "||";
            $b1.innerHTML = "";
            $con.appendChild($b1);
            _C.CORE.addEvent($b1, "click", onClick);
        function gotoPage(_a)
        {
            var $id = returnIdNum(findTarget(_a));
            if($id != $currFade)
            {
            $barSpeed = 100;
            $bw = 100;
            $stopFade = $id;
            //alert($stopFade);
            if($paused){
            onClick();
            }
            }
        }
        function onOver(_a)
        {
            var $id = returnIdNum(findTarget(_a));
            var $el = findTarget(_a);
            $el.src = "http://images.asos.com/homepage/2008_08_26_AWSiteRefresh/w/btn"+($id+1)+"_over.gif";
        }
        function onOut(_a)
        {
            var $id = returnIdNum(findTarget(_a));
            var $el = findTarget(_a);
            $el.src = "http://images.asos.com/homepage/2008_08_26_AWSiteRefresh/w/btn"+($id+1)+".gif";
        }
        function onClick()
        {
            if($paused)
            {
                _E.ANI.play($data[0],0,"",false);
                $paused = false;
            }
            else
            {
                _E.ANI.pause($data[0]);
                $paused = true;
            }
        } 
        function findTarget(_a)
        {
            var $el;
            if(_a.srcElement!=null)
            {
                $el=_a.srcElement;
            }
            else
            {
                $el=_a.target;
            }
            return $el;
        }
        function returnIdNum(_el)
        {
            var $id = _el.id;
            $id = $id.substring($id.length-1,$id.length);
            return Number($id);
        } 
	    function circFade(_data,_currFade){
        if($fadeActive){
	        if($n>0)
	        {
	            _E.GEN.setAlpha(_data[$currFade],$n);
	        }
	        else
	        {
	            for(var i=0;i<_data.length;i++)
	            {
	                if(i!=$currFade)
	                {
	                    var $i1 = _data[i].style.zIndex;
	                    _data[i].style.zIndex = $i1 + 1;
	                }
	                else
	                {
	                     _data[i].style.zIndex = 1;
	                }
	            }
	            _E.GEN.setAlpha(_data[$currFade],1);
	            
	            $n = 1;
	            $fadeActive = false;
	            //console.log(typeof($stopFade)+":"+typeof($currFade));
	            if($stopFade == $currFade)
	            {
	                //console.log("AAAAAA");
	                $barSpeed = 0.5;
	                $stopFade = null;
	            }
	        }	
	        $n-=0.1;  
	    }
	    //moving bars
	    else
	    {
	        if($bw<=100)
	        {
	            $navBars[$currFade].style.width = $bw + "%";
	            $bw+=$barSpeed;
	        }
	        else
	        {
	            $fadeActive = true;
	            $bw = 0;
	            if($currFade==_data.length-1)
	            {
	                $currFade = 0;
	                for(var i=0;i<$data.length;i++)
	                {
	                    $navBars[i].style.width = "0%";
	                }
	                
	            }
	            else
	            {
	                $currFade ++;
	            }
	        }
	    }      
	    }
	    function moveBar(){
	        
	    }
	    function updateIndexes(_index){
	        
	    }
	    _E.ANI.animation(circFade,$data[0],0,"",$data,$currFade);
	    //_C.CORE.addEvent($blog, "mouseover", ASOS.stopBlog);
	    //_C.CORE.addEvent($blog, "mouseout", ASOS.startBlog);
	    
	},
	simpleCircFading:function(_data,_parent,_speed,_pause){
	//UI
	var $con = _C.CORE.$(_parent);

	//ANIMATION
	    var $data = [];
	    var $currFade = 0;
	    var $stopFade = null;
	    var $n = 1;
	    var $paused = false;
	    var $fadeActive = true;
	    var $bw = 0;
	    var $barSpeed = _pause;
        
        for(var i=0;i<_data.length;i++)
        {
            $data.push(_C.CORE.$(_data[i]));
        }

        

        function findTarget(_a)
        {
            var $el;
            if(_a.srcElement!=null)
            {
                $el=_a.srcElement;
            }
            else
            {
                $el=_a.target;
            }
            return $el;
        }
        
        /*function returnIdNum(_el)
        {
            var $id = _el.id;
            $id = $id.substring($id.length-1,$id.length);
            return Number($id);
        } */
        
	    function circFade(_data,_currFade){
	    //console.log($currFade);
        if($fadeActive){
	        if($n>0)
	        {
	            _E.GEN.setAlpha(_data[$currFade],$n);
	        }
	        else
	        {
	            for(var i=0;i<_data.length;i++)
	            {
	                if(i!=$currFade)
	                {
	                    var $i1 = _data[i].style.zIndex;
	                    _data[i].style.zIndex = $i1 + 1;
	                }
	                else
	                {
	                     _data[i].style.zIndex = 1;
	                }
	            }
	            
	            _E.GEN.setAlpha(_data[$currFade],1);
	            
	            $n = 1;
	            $fadeActive = false;
	            //console.log(typeof($stopFade)+":"+typeof($currFade));
	            if($stopFade == $currFade)
	            {
	                
	                $barSpeed = 0.5;
	                $stopFade = null;
	            }
	        }	
	        $n-=_speed;  
	    }
	    //moving bars
	    else
	    {
	        if($bw<=100)
	        {
	            $bw+=$barSpeed;
	        }
	        else
	        {
	            $fadeActive = true;
	            $bw = 0;
	            if($currFade==_data.length-1)
	            {
	                $currFade = 0;
	            }
	            else
	            {
	                $currFade ++;
	            }
	        }
	    }      
	    }
	    _E.ANI.animation(circFade,$data[0],0,"",$data,$currFade);
	    //_C.CORE.addEvent($blog, "mouseover", ASOS.stopBlog);
	    //_C.CORE.addEvent($blog, "mouseout", ASOS.startBlog);
	    
	},
	startBlog:function(){
	  _E.ANI.play(_C.CORE.$("blogStrip"),0,"",false);
	},
	stopBlog:function(){
	  _E.ANI.pause(_C.CORE.$("blogStrip"));
	}


	
};
ASOS.$=_C.CORE.$;
ASOS.rollOvers=_E.IMG.rollovers;
//####
