var topNormal = 300, topFull = 0;
var duracion = 300;
var duracion_norm = 600;
var transUp = Fx.Transitions.Quad.easeOut;
var transDown = Fx.Transitions.Quad.easeOut;

var fx = new Fx.Elements($('main'), {wait:false, duration:duracion, transition: transUp});
var fxs = {};	

window.addEvent("domready",function(){
	var openDiv = function(e) {
		e = new Event(e);	var a = e.target;	a = $(a);
		while(!a.match('div') || !a.hasClass('item'))
			a=$(a.getParent());
		if(a.hasClass("item")) {
			var b = a.getElement('div[class=desc]');
			b=$(b);		
			if(b) { 
				if(b.getProperty("moving") > 0) {
					fxs[b.getProperty("moving")].cancel();
					b.setProperty("moving",0);
				}

				fx = new Fx.Elements(b, {wait:false, duration:(b.getStyle("top").toInt()/topNormal)*duracion, transition: transUp});
				var o = {};   o[0]={ 'top': [topFull]};					   
				var ran = $random(0,100000);
				fxs[ran]=fx;
				b.setProperty("moving",ran);
				fx.start(o);
			}
		} 
	};

	var resetDiv = function(e) {
		e = new Event(e); 	var a = e.target;	a = $(a);
		while(!a.match('div') || !a.hasClass('item'))
			a=$(a.getParent());
		if(a.hasClass("item")) {
			var b = a.getElement('div[class=desc]');
			b=$(b);
			if(b) { 	
			    if( b.getProperty("moving") > 0) {
					fxs[b.getProperty("moving")].cancel();
					b.setProperty("moving",0);
				}

				fx = new Fx.Elements(b, {wait:false, duration:((topNormal-b.getStyle("top").toInt())/topNormal)*duracion_norm, transition: transDown});
			    var o = {};	o[0]={ 'top': [topNormal]};
				b.setProperty("moving",1);
			    var ran = $random(0,100000);
			    fxs[ran]=fx;
			    b.setProperty("moving",ran);						
			    fx.start(o);
			}
		};
	};
	

  var Tips3 = new Tips('.product_picture a img', {
    onShow: function(tip, el){
        tip.setStyles({
            visibility: 'hidden',
            display: 'block'
        }).fade('in');
    },
    onHide: function(tip, el){
      tip.fade('out').get('tween').chain(function(){
          tip.setStyle('display', 'none');
      });
    },
    'fixed': true,
    'windowPadding': {'x':-20, 'y': -20},
    'offset': {'x':0, 'y': -162}
  });

	//$$('.product_picture').addEvent("mouseenter",openDiv);		
	//$$('.product_picture').addEvent("mouseleave",resetDiv);
  $('ctrl_product_chooser').addEvent('change',function(){
       if(this.value != 'none') {
         var loc = window.location;
         window.location = loc.toString().split('productalias=').join('productalias=' + this.value);
       }
  });			
});

function str_replace(search, replace, subject) {
  return subject.split(search).join(replace);
}
