jQuery.noConflict();
	var currentPhoneHandler = 1;

function changePhone() { 
	var phonesCount = jQuery(".hiddenPhone").length;
	currentPhoneHandler++;
	if(currentPhoneHandler>phonesCount){
		currentPhoneHandler = 1;
	}
    jQuery("#phoneNum, #phoneName").fadeTo("fast", 0,function(){
    	//	set new phone
    	jQuery("#phoneNum").html(jQuery("#phone"+currentPhoneHandler).html());
    	jQuery("#phoneName").html(jQuery("#phone"+currentPhoneHandler).attr("ph"));
    	jQuery("#phoneNum, #phoneName").fadeTo("fast", 1);
    });

}

//	phone switcher
jQuery(document).ready(function(){

	intervalID = window.setInterval(changePhone, 3500);
});


function SetCheckVal()
{
	var el = $('as_IsPriceReq');
   	var checkVal= el.getProperty('value');
   	if (checkVal == '1')
   	{
    	el.setProperty('value','0');
   	}
   	else
  	{
        el.setProperty('value','1');
  	}
}


function setrating(num,rating) {

  for (count = 1; count < 6; count++) {

    if (rating >= count) $("r_"+num+"_"+count).src = "/i/rate-"+count+".gif";

    else $("r_"+num+"_"+count).src = "/i/rate-0.gif";

  }

}



function compareAdd(obj,id,ison) {

  var data = compareGet(obj);

  if(ison) { if(!data.contains(id)) data[data.length] = id; }

  else data.remove(id);

  comp.set('k'+obj, data);

}

function compareGet(obj) {

  return comp.get('k'+obj) || [];

}

function compareClear() {

  comp.erase();

}



function add2cart(a,helper) {

	var src = $(a).getProperty('href');

	if($(a).hasClass('del'))
	{
		$(a).getFirst().src='/i/ico-buy.png';
		$(a).setProperty('href', src.replace("act=add", "act=del"));
	}
	else
	{
		//selector
		if(jQuery.browser.safari){
			var selector = "body";
		} else {
			var selector = "html";
		}
		$(a).getFirst().src='/i/ready.png';
		$(a).setProperty('href', src.replace("act=del", "act=add"));
	
		
		var startedFrom = jQuery(window).scrollTop();
		
				
		//	slide page scroll to cart
			var destination = jQuery("#cart").offset().top;
			//	drop to cart
				//	add copy
				
				switch(helper){
			
					case 'notshort':
					//	category
					jQuery("#minWidth").prepend("<img src=\""+jQuery(a).parent().parent().find(".item-cover").attr("src")+"\" class=\"zoomed\" style=\"position: absolute; z-index:2000; left: "+jQuery(a).parent().parent().find(".item-cover").offset().left+"px; top: "+jQuery(a).parent().parent().find(".item-cover").offset().left+"px;\">");
					break;
			
					case 'full':
					//	item card
					jQuery(".big-image").prepend("<img src=\""+jQuery("#fucimage").attr("src")+"\" class=\"zoomed\" style=\"position: absolute; z-index:2000; left: "+jQuery("#fucimage").offset().left+"px; top: "+jQuery("#fucimage").offset().left+"px;\">");
					break;
			
					case 'new':
					//	new! mainpage
					jQuery("#minWidth").prepend("<img src=\""+jQuery(a).parent().parent().parent().find(".ph-left .ph img").attr("src")+"\" class=\"zoomed\" style=\"position: absolute; z-index:2000; left: "+jQuery(a).parent().parent().parent().find(".ph-left .ph img").offset().left+"px; top: "+jQuery(a).parent().parent().parent().find(".ph-left .ph img").offset().top+"px;\">");
					break;
					
					case 'raspr':
					//	starred
					jQuery("#minWidth").prepend("<img src=\""+jQuery(a).parent().parent().parent().find(".ph-left .ph img").attr("src")+"\" class=\"zoomed\" style=\"position: absolute; z-index:2000; left: "+jQuery(a).parent().parent().parent().find(".ph-left .ph img").offset().left+"px; top: "+jQuery(a).parent().parent().parent().find(".ph-left .ph img").offset().top+"px;\">");	
					break;
					
					case 'recomend':
					
							jQuery("#minWidth").prepend("<img src=\""+jQuery(a).parent().parent().parent().find(".item-cover").attr("src")+"\" class=\"zoomed\" style=\"position: absolute; z-index:2000; left: "+jQuery(a).parent().parent().parent().find(".item-cover").offset().left+"px; top: "+jQuery(a).parent().parent().parent().find(".item-cover").offset().top+"px;\">");	
					
					break;
					
				}
				
				var destination = jQuery("#cart img").offset().top;
			//	drop to cart
				//	add copy
		
				//	start slide to cart
				jQuery(".zoomed").animate({top:jQuery("#cart img").offset().top,left:jQuery("#cart img").offset().left,width:"10px"},800,'easeOutBounce',function(){
					//	droped!
					jQuery(".zoomed").remove();
					var destination = jQuery(a).offset().top;
					jQuery(selector).animate({ scrollTop: startedFrom}, 700,'linear', function() {
							// slide back?
					});	
				});
			//	slide up
			jQuery(selector).animate({ scrollTop: destination-10}, 500,'linear', function() {
				
			});
			
	}
  	$(a).toggleClass('del');
  	return true;
}



function showsub(num) 
{
	jQuery("#sub"+num).show();
  //new Fx.Style($('sub'+num), 'opacity', {duration:100}).custom(0, 1);

}

function closesub(num) 
{
	jQuery("#sub"+num).hide();
  //new Fx.Style($('sub'+num), 'opacity', {duration:500}).custom(1, 0);
}



function shLF(f) { $('login').setStyle('display', f ? 'none' : 'block'); }



var TabsBlock = new Class({

  initialize: function() {

    if(!$('tabs')) return null;

    this.li = $('tabs').getChildren();

    this.liIterator(this.liInit.bind(this));

  },

  liInit: function(el) { el.addEvent('click', this.liClick.pass(el,this)) },

  liIterator: function(f) { this.li.each(f) },

  liClick: function(e) { this.liClearAll(); this.liAddClass(e) },

  liAddClass: function(el) { el=$(el); var tab=el.addClass('selected').id; $('v'+tab).setStyle('display','') },

  liRemoveClass: function(el) { var tab=el.removeClass('selected').id; $('v'+tab).setStyle('display','none') },

  liClearAll: function() { this.liIterator(this.liRemoveClass) }

});



var ImageScroller = new Class({

  initialize: function(cont, left, right, img) {

    this.cont = $(cont);

    this.left = $(left);

    this.right = $(right);

    this.img = $(img);

    this.allInit();

  },

  allInit: function() {

    this.contlist = this.cont.getElements('td');

    this.cw = this.cont.getCoordinates().width; //film

    //this.vw = this.cont.getParent().getCoordinates().width; //tv

    this.w = this.cw/this.contlist.length; // kadr

    this.left.addEvent('click', this.leftClick.pass(this.left,this));

    this.right.addEvent('click', this.rightClick.pass(this.right,this));

    this.contIterator(this.addBordClicks.bind(this));

    if(this.contlist.length > 3) this.sh_r();

    this.sh_l(1);

  },

  addBordClicks: function(el) { el.addEvent('click', this.bordClick.pass(el,this)) },

  bordClick: function(el) {

    this.bordClearAll();

    el.addClass('selected');

    var i = el.getFirst().getFirst().getProperty('msrc');

    new Asset.image(i, {onload: function(img){ this.img.src = img; }.pass(i,this) });

  },

  bordClearAll: function() { this.contIterator(this.bordRemoveClass) },

  bordRemoveClass: function(el) { el.removeClass('selected') },

  contIterator: function(f) { this.contlist.each(f); },

  leftClick: function(e) {

    var oldl = this.cont.getStyle('left').toInt();

    var left = oldl+this.w;

    if(left >= 0) { left=0; this.sh_r(); this.sh_l(1); }

    else { this.sh_r(); }

    this.setL(left,oldl);

  },

  rightClick: function(e) {

    var oldl = this.cont.getStyle('left').toInt();

    var left = oldl-this.w;

    var c = (this.contlist.length-3);

    if(left <= -c*this.w+5) { left=-c*this.w; this.sh_l(); this.sh_r(1); }

    else { this.sh_l() }

    this.setL(left,oldl);

  },

  setL: function(v,oldv) {

    new Fx.Style(this.cont, 'left', {duration:500}).start(oldv, v);

    //this.cont.setStyle('left', v);

  },

  sh_l: function(h) { this.left.setStyle('visibility', (h ? 'hidden' : 'visible')); },

  sh_r: function(h) { this.right.setStyle('visibility', (h ? 'hidden' : 'visible')); }

});



var liTabs = null, comp = null;

window.addEvent('domready', function () {

  comp = new Hash.Cookie('compare', {duration:3600,path:'/'});

  liTabs = new TabsBlock('tabs');
  
  $('minWidth').getElements('a.del').addEvent('mouseover', function(){
     	this.setProperty('value','Убрать');
		this.setStyle('color', '#ff976e');
	});
  $('minWidth').getElements('a.del').addEvent('mouseout', function(){     	
     	this.setProperty('value','В корзине');
		this.setStyle('color', 'white');
	});

});




















