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

var RolMedLeft = $$('.RolMediaLeft');
RolMedLeft.set('morph', {duration: 'long', transition: Fx.Transitions.Bounce.easeOut});
var LoadRolMedia = function(){
	RolMedLeft.morph({ 'left':'-120px'});
}.delay(10000);

$$('#carsall A').addEvents({
	mouseenter:function(){
//		alert('марка');
	}
});

var Tips01 = new Tips(('.otzivRow','.LST','.LFT','.LFB','.tips'), {
	className: 'zindex'
});

var otzivRating = $$('.item .ball B', '.showStars');
otzivRating.each(function(item) {
	var rVal = item.get('text');
	var rShow = (rVal*1).round(2);
	var rPers = (rVal/5.0*100).round();
	item.set('html',
	'<SPAN class="ratingStars"><DIV style="width:'+ rPers +'%;"></DIV></SPAN>'+rShow
	);
});

$$('.linesTab .row').addEvents({
	mouseenter:function(){
		this.setProperty('class', 'row_over');
/*		this.getElements('.filial TD').setStyle('background-color','#d8e7f5');
		this.getElement('.check').setStyle('background-color','#fdfbe7');*/
	},
	mouseleave:function(){
		this.setProperty('class', 'row');
	}
});

$$('.RolMediaLeft').addEvents({
	mouseenter:function(){
		this.morph({'left':'-10px'});
		
	},
	mouseleave:function(){
		this.morph({'left':'-120px'});
	}
});


var navigators = $$('.navPas .rowDownNav', '.navAct .rowDownNav', '.navPas .rowTopNav', '.navAct .rowTopNav');
navigators.addEvents({
	mouseenter:function(){
		this.setStyle('background-color', '#f3e8c3');
		this.getElement('.right').setStyle('background-position','-25px 0px');
	},
	mouseleave:function(){
		this.setStyle('background-color', '#f3f1e4');
		this.getElement('.right').setStyle('background-position','-35px 0px');
	},
	click:function(){
		var objName = this.getProperty('name');
		var objClass = this.getProperty('class');
		if(objClass == 'rowDownNav') {
			this.setProperty('class', 'rowTopNav');
			if(objName) {
				$$('.'+objName).setStyle('display','block');
			}
			else {
				navMenu(this.getParent(), 'show');
			}
		}
		else {
			this.setProperty('class', 'rowDownNav');
			if(objName) {
				$$('.'+objName).setStyle('display','none');
				if(objName=='markaBlock') $$('.markaBlockTop').setStyle('display','none');
			}
			else {
				navMenu(this.getParent(), 'hide');
			}
		}
	}
});

$$('.navPas', '.navAct').addEvents({
	mouseenter:function(){
		this.setStyle('z-index', 100);
	},
	mouseleave:function(){
		this.setStyle('z-index', 10);
	}
});

$$('.navMenu').addEvents({
	mouseleave:function(){
		var rowTop = this.getParent().getElement('.rowTopNav');
		if (rowTop) rowTop.setProperty('class', 'rowDownNav'), this.setStyle('display','none'), $$('#cars_tab SELECT').setStyle('visibility','visible');
	}
});
function navMenu(obj, what) {
	if(what=='show'){
		obj.getElement('.navMenu').setStyle('display', 'block');
		$$('#cars_tab SELECT').setStyle('visibility','hidden');
		//alert('this: '+ obj.getProperty('class'));
	}
	else{
		obj.getElement('.navMenu').setStyle('display', 'none');
		$$('#cars_tab SELECT').setStyle('visibility','visible');
		// alert('this: '+ obj.getProperty('class'));
	}
};


// Процедура сворачивания марок
	var ShowMarkaBlock = $$('.markaBlockTop TABLE TD A.dash','.markaBlock TABLE TD A.dash', '.markaBlockSelect A.dash');
	ShowMarkaBlock.addEvents({
		'click':function(){
			var thisName = this.getProperty('name');
			var thisID = this.getProperty('id');
			if (thisName == 'modelShow' || thisID == 'modelShow') {
				$$('.modelRower').setStyle('display','');
				this.erase('name').set({'name':'modelHide', 'id':'modelHide', 'text':'скрыть модели'});
				this.getParent().getElement('.RowDown').set('class', 'RowTop');
			}
			else if (thisName == 'modelHide' || thisID == 'modelHide') {
				$$('.modelRower').setStyle('display','none');
				this.erase('name').set({'name':'modelShow', 'id':'modelShow', 'text':'все модели'});
    			this.getParent().getElement('.RowTop').set('class', 'RowDown');
			}
			else {
				this.getParent('div').setStyle('display','none');
				$$('.'+thisName).setStyle('display','block');
	//			$$('#navigator').getElement('span[name='+this.getParent('div').getProperty('class')+']').set('class','rowDownNav');
			}
		}
	});
// сворачивание закончено
	
	var MarkaLogo = $$('.markaBlockTop IMG', '.markaBlock IMG');

	var CarsTabView = Cookie.read('CarsTabView');
	if (CarsTabView) { setCarsTabView(CarsTabView); }
	else { $$('#LikeTable').setStyle('display', 'block'); }

	var ViewSelect = $$('#ViewSelect span');
		ViewSelect.addEvents({
		click: function(){
			ViewSelect.setStyle('cursor','pointer'),
			setCarsTabView( this.getProperty('class') );
			}
		});


		$$('tr.row3 .small').each(function(item) { if (item.getProperty('name')) { item.set('src', item.getProperty('name')).erase('name'); } });

	
	function setCarsTabView(howView) {
		if (howView == 'LFT') {
			$$('.zoomMe').setStyles({'width':'100px', 'display':'none'});
			$$('#ViewSelect .LST').setStyle('background-position', '0px -19px');
			$$('#ViewSelect .LFT').setStyles({'background-position' : '-19px 0px', 'cursor' : 'default'});
			$$('#ViewSelect .LFB').setStyle('background-position','-38px -19px');
			$$('#LikeTable').setStyle('display', 'block');
			$$('#LikeBlocks').setStyle('display', 'none');
			$$('.carsTabImgA .ico').setStyle('display', 'none');
			$$('.carsTabImgA .small').setStyle('display', 'block');
			$$('#LikeTable .zoomMe').setStyle('opacity', '0');
			$$('#LikeTable .small').each(function(item) {
				if (item.getProperty('name')) { item.set('src', item.getProperty('name')).erase('name'); }
			});

			Cookie.write('CarsTabView', 'LFT', {path: '/'});
			viewSort('hide');
			showMarkLogo('hide');
		}
		else if (howView == 'LFB') {
			$$('#ViewSelect .LST').setStyle('background-position','0px -19px');
			$$('#ViewSelect .LFT').setStyle('background-position','-19px -19px');
			$$('#ViewSelect .LFB').setStyle('background-position','-38px 0px');
			$$('#LikeTable').setStyle('display', 'none');
			$$('#LikeBlocks').setStyle('display', 'block');
			$$('#LikeBlocks .zoomMe').setStyle('opacity', '0');
			$$('#LikeBlocks .hiddenFoto').each(function(item) {
				if (item.getProperty('name')) { item.set('src', item.getProperty('name')).erase('name'); }
				});

			Cookie.write('CarsTabView', 'LFB', {path: '/'});
			viewSort('show');
			showMarkLogo('show');
		}
		else {
			$$('.zoomMe').setStyles({'width':'20px', 'display':'none'});
			$$('.carsTabImgAP .zoomMe').setStyle('width','100px');
			$$('#ViewSelect .LST').setStyle('background-position','0px 0px');
			$$('#ViewSelect .LFT').setStyle('background-position','-19px -19px');
			$$('#ViewSelect .LFB').setStyle('background-position','-38px -19px');
			$$('#LikeTable').setStyle('display', 'block');
			$$('#LikeBlocks').setStyle('display', 'none');
			$$('.carsTabImgA .ico').setStyle('display', 'block');
			$$('.carsTabImgA .small').setStyle('display', 'none');
			$$('#LikeTable .zoomMe').setStyle('opacity', '0');
			Cookie.dispose('CarsTabView', {path: '/'});
			viewSort('hide');
			showMarkLogo('hide');
		}
	};

	function viewSort(how) {
		var sortPan = $$('#carsTabPanel .sort');
		var sW = sortPan.getProperty('rel');
		if (sW =='S') var sortWidth = '300px';
		else if (sW =='SS') var sortWidth = '200px';
		else { var sortWidth = '670px'; /*$$('#GeoCarsH').setStyle('display','none');*/ }; 
		if (how == 'show') sortPan.morph ({ 'width': sortWidth });
		else if (how == 'hide') { sortPan.morph ({ 'width': '1px' }); /*$$('#GeoCarsH').setStyle('display','block');*/ } 		
	};


// MarkLogo Display Function

	function showMarkLogo(what) {
		if(what == 'show') {
//			$$('.m_List','.m_ListTop').setStyle('height','20px');
			var imgURL = 'http://img2.autonavigator.ru/images/logos/ico/';
			$$('.m_List img','.m_ListTop img','.m_List_act img','.m_ListTop_act img').setStyle('display','inline-block').each(function(item) {
				if (item.getProperty('name')) { item.set({'src':imgURL+item.getProperty('name')+'.gif', 'height':'20', 'width':'36'}).erase('name'); }
			});
		} else { 
//			$$('.m_List','.m_ListTop').setStyle('height','16px');
			$$('.m_List img','.m_ListTop img').setStyle('display','none');
		}
	// src="/testimages/logos/ico/.gif"
	}

// setPriceType
	var PriceType = Cookie.read('PriceType');
	if (PriceType) {
		setCur(PriceType);
	}

	var PriceTypeSelect = $$('#PriceTypeSelect', '#PanelPriceTypeSelect');
	PriceTypeSelect.addEvents({
		'change': function(){
			setCur( this.getSelected().getProperty('value') );
		}
	});

	function setCur(cur) {
		if (cur == 'RUR') {
			$$('.DEF', '.USD', '.EUR').setStyle('display', 'none');
			$$('.RUR').setStyle('display', 'inline-block');
			Cookie.write('PriceType', 'RUR', {path: '/'});
			$$('#PriceTypeSelect', '#PanelPriceTypeSelect').getElement('option[value=RUR]').setProperty('selected','selected');
		}
		else if (cur == 'USD') {
			$$('.RUR', '.DEF', '.EUR').setStyle('display', 'none');
			$$('.USD').setStyle('display', 'inline-block');
			Cookie.write('PriceType', 'USD', {path: '/'});
			$$('#PriceTypeSelect', '#PanelPriceTypeSelect').getElement('option[value=USD]').setProperty('selected','selected');
		}
		else if (cur == 'EUR') {
			$$('.RUR', '.USD', '.DEF').setStyle('display', 'none');
			$$('.EUR').setStyle('display', 'inline-block');
			Cookie.write('PriceType', 'EUR', {path: '/'});
			$$('#PriceTypeSelect', '#PanelPriceTypeSelect').getElement('option[value=EUR]').setProperty('selected','selected');
		}
		else {
			$$('.RUR', '.USD', '.EUR').setStyle('display', 'none');
			$$('.DEF').setStyle('display', 'inline-block');
			Cookie.dispose('PriceType', {path: '/'});
			$$('#PriceTypeSelect').getElement('option[value=DEF]').setProperty('selected','selected');
		}
	};
	


	var imgZoomerText = $$('.carsTabImg', '.carsTabImgP');
	imgZoomerText.addEvents({
		mouseenter: function(){
			$$('#'+this.id+'a .zoomMe').morph ({ width: 200, opacity: 1 }),
			$$('#'+this.id+'a .zoomMe').setStyle('display', 'block'),
			$$('#up'+this.id+'a').morph({'z-index': '30'});
			if ($$('#'+this.id+'a .zoomMe').getProperty('name')) { $$('#'+this.id+'a .zoomMe').set('src', $$('#'+this.id+'a .zoomMe').getProperty('name')).erase('name'); }
			
		},
		mouseleave: function(){
			// what ON and what OFF
			if ($$('#'+this.id+'a .small').getStyle('display') != 'none') {
				var oldZoomWidth = 100; /*$$('#'+this.id+'a .small').get('width')*/ var oldOpacity = 0; }
			else if ($$('#'+this.id+'a .ico').getStyle('display') != 'none') {
				var oldZoomWidth = 20; /*$$('#'+this.id+'a .ico').get('width')*/ var oldOpacity = 0; }
			$$('#'+this.id+'a .zoomMe').morph ({ 'width': oldZoomWidth, 'opacity': oldOpacity }),
			$$('#'+this.id+'a .zoomMe').setStyle('display', 'block');
			$$('#up'+this.id+'a').morph({'z-index': '10'});
		 }
	});

	var imgZoom = $$('.carsTabImgA', '.carsTabImgAP');
	imgZoom.addEvents({
		mouseenter: function(){ 
			$$('#'+this.id+' .zoomMe').morph ({ width: 200, opacity: 1 }),
			$$('#'+this.id+' .zoomMe').setStyle('display', 'block'),
			$$('#up'+this.id).morph({'z-index': '30'});
			if ($$('#'+this.id+' .zoomMe').getProperty('name')) { $$('#'+this.id+' .zoomMe').set('src', $$('#'+this.id+' .zoomMe').getProperty('name')).erase('name'); }
		},
		mouseleave: function(){
			// what ON and what OFF
			if ($$('#'+this.id+' .small').getStyle('display') != 'none') {
				var oldZoomWidth = 100; var oldOpacity = 0; }
			else if ($$('#'+this.id+' .ico').getStyle('display') != 'none') {
				var oldZoomWidth = 20; /*$$('#'+this.id+'a .ico').get('width')*/ var oldOpacity = 0; }
			$$('#'+this.id+' .zoomMe').morph ({ 'width': oldZoomWidth, 'opacity': oldOpacity }),
			$$('#'+this.id+' .zoomMe').setStyle('display', 'block'),
			$$('#up'+this.id).morph({'z-index': '10'});
		}
	});

	var iZoom = $$('a.carsFotoZoom');
	iZoom.addEvents({
		mouseenter: function(){ 
			$$('#'+this.id+' .zoomMe').morph ({ width: 200, opacity: 1 }),
			$$('#'+this.id+' .zoomMe').setStyles({'display':'inline-block'})
			$$('#'+this.id).setStyle('z-index', '300');
		},
		mouseleave: function(){
			$$('#'+this.id+' .zoomMe').morph ({ width: 100, opacity: 0 }),
			$$('#'+this.id).setStyle('z-index', '10');
		}
	});


	var oldRow1Color = '#FFFFFF';
	var oldRow2Color = '#F0F0F0';
	var oldRow3Color = '#dbf5ff';
	var newRowColor = '#c5e4ff';
	$$('.row1').addEvents({
		mouseenter: function(){ this.setStyle('background-color', newRowColor); },
		mouseleave: function(){ this.setStyle('background-color', oldRow1Color); }
	});
	$$('.row2').addEvents({
		mouseenter: function(){ this.setStyle('background-color', newRowColor); },
		mouseleave: function(){ this.setStyle('background-color', oldRow2Color); }
	});
	$$('.row3', '.row4').addEvents({
		mouseenter: function(){ this.setStyle('background-color', newRowColor); },
		mouseleave: function(){ this.setStyle('background-color', oldRow3Color); }
	});



	var markRow = $$('.m_List', '.m_ListTop');
	markRow.addEvents ({
		mouseenter:function(){ this.setStyles({'background-color': '#e1edf9'}); },
		mouseleave:function(){ this.setStyles({'background-color':'transparent'}); }
	});

	var MediaBox = $$('#MediaHBox SPAN', '#MediaVBox SPAN');
	MediaBox.addEvents({
		mouseenter:function(){
			var toHeight = this.getElement('.cont').getStyle('height');
			this.setProperty('class', 'bl_lightgreen');
			this.getElement('.inner').morph({'height': toHeight });
		},
		mouseleave:function(){
			this.setProperty('class', 'bl_lightgray');
			this.getElement('.inner').morph({'height':'78px'});
		}

	});


if ($('CardsInfoSlider')) {
	var CardsInfoSlider = $('CardsInfoSlider');
	var CardsInfoSlideBut = $$('#CardsInfoSlideBut');
	var CardsInfoSlide = new Fx.Slide (CardsInfoSlider, { mode:'vertical', transition:'sine:in', duration: 300 }).hide();
	CardsInfoSlideBut.addEvent('click', function(){
		CardsInfoSlider.setStyle('display', 'block');
		CardsInfoSlide.toggle();
		if(CardsInfoSlide.open) $$('#salon_row_ico').setStyle('margin-left', '-12px')
		else $$('#salon_row_ico').setStyle('margin-left', '0px')
	});
	};

$$('#tm_all', '#tm_new', '#tm_search', '#tm_salon', '#tm_gides', '#tm_news', '#tm_forum', '#tm_used').addEvents({
	mouseenter:function(){
		if(this.getProperty('class') != 'act') {
			/*this.getElement('.sub').setStyle('z-index','101');*/
			this.set('class', 'over');
		}
	},
	mouseleave:function(){
		if(this.getProperty('class') != 'act') {
			//this.getElement('.sub').setStyle('z-index','-1');
			this.erase('class');
		}
	}

});
	
});