function hosm(oid) {
	if(document.getElementById(oid).style.display=="none") document.getElementById(oid).style.display="block";
	else document.getElementById(oid).style.display="none";
	return false;
} 

function AnimateText() {
	$('#top-text').html($('#top-text').html()+$('#top-text').html());
	this.firstText=$('#top-text p:first');
	this.lastText=$('#top-text p:last');
	this.textWidth=this.firstText.width();
	this.elWidth=$('#top-text').width();
	this.div=20;
	this.step1();
}

AnimateText.prototype.step1=function() {
	text=this;
	this.lastText.css({left:-(this.textWidth-this.elWidth-this.div)+'px'});
	this.firstText.animate({left:-(this.textWidth-this.elWidth)+'px'}, this.getDur(this.textWidth-this.elWidth,0), 'linear', function() { text.step2()});
}

AnimateText.prototype.step2=function() {
	text=this; 
	this.firstText.animate({left:-(this.textWidth)+'px'}, this.getDur(this.textWidth,(this.textWidth-this.elWidth)), 'linear');
	this.lastText.animate({left:-(2*this.textWidth-this.elWidth+this.div)+'px'}, this.getDur(2*this.textWidth-this.elWidth+this.div,this.textWidth-this.elWidth-this.div), 'linear', function() { text.step3()});
}

AnimateText.prototype.step3=function() {
	text=this;
	this.firstText.css({left:this.elWidth+'px'});
	this.lastText.animate({left:-(2*this.textWidth)+'px'}, this.getDur(2*this.textWidth,2*this.textWidth-this.elWidth+this.div), 'linear');
	this.firstText.animate({left:0}, this.getDur(this.elWidth,0), 'linear', function() { text.step1()});
}

AnimateText.prototype.getDur=function(width, left) {
	return (width-left)*35;
}

function order(link) {
        var ll=(document.body.clientWidth-550)/2;
        newWindow = window.open(link+"&tem=2", "ttt", "scrollbars=1, width=560 , height=450 ,left="+ll+", top=50");
        newWindow.focus();
        return false;
}

function Reiting() {
	this.flag=0;
	el=this;
	$('.golos').mouseover(function(){ el.onOver(this.id); }).mouseout(function(){ el.onOut(this.id); }).click(function(){ if(!el.flag) { el.flag=1; el.onClick(this.id); } });
}

Reiting.prototype.onOver=function(sid) {
	fid=sid.substr(7);
	$('#reit'+fid+' .golos').removeClass('golos-on').addClass('golos-off');
	$('#'+sid).removeClass('golos-off').addClass('golos-on');
}

Reiting.prototype.onOut=function(sid) {
	fid=sid.substr(7);
	$('#'+sid).removeClass('golos-on').addClass('golos-off');
	reit=this.getReiting('reit'+fid);
	if (reit) {
		for (i=1; i!=reit+1; i++) {
			$('#gol'+i+'for'+fid).removeClass('golos-off').addClass('golos-on');
		}
	}
}

Reiting.prototype.onClick=function(sid) {
	el=this;
	fid=sid.substr(7);
	addRait=sid.substr(3,1);
	$.post('/catalog/rating.html', { id:fid, rait:addRait }, function(data){ el.setNewRaitg(data,fid); el.flag=0; });
}

Reiting.prototype.setNewRaitg=function(data,sid) {
	newReit='';
	eval(data);
	if (newReit!='') {
		reit=this.getReiting('reit'+sid);
		$('#reit'+sid).removeClass('count'+reit).addClass('count'+newReit);
		$('#reit'+sid+' .golos').removeClass('golos-on').addClass('golos-off');
		$('#message').html(message).show();
		setTimeout(function() { $('#message').hide() }, 1500);
		this.onOut('gol1for'+sid);
	}
	else {
		$('#message').html(message).show();
		setTimeout(function() { $('#message').hide() }, 1500);
	}
}

Reiting.prototype.getReiting=function(sid) {
	reit=0;
	if ($('#'+sid).hasClass('count1')) reit=1;
	if ($('#'+sid).hasClass('count2')) reit=2;
	if ($('#'+sid).hasClass('count3')) reit=3;
	if ($('#'+sid).hasClass('count4')) reit=4;
	if ($('#'+sid).hasClass('count5')) reit=5;
	return reit;
}

jQuery(document).ready(function() {


//    alert('dfdf');
    var temp = $('ul.main_left_list li');
    $(temp).html($(temp).html() + '<a href="http://www.y-expo.ru/"><img src="/img/a_85999 copy.jpg" width="260" style="margin-top: 15px;" /></a>');
    



	if(document.getElementById('top-text')) {
		var AnText=new AnimateText();
	}
	//$('.catalog-item a.order').click(function(){ order(this.href); return false; });
	//$('#popupwindow').click(function(){ order(this.href); return false; });
	addReiting=new Reiting();
//	if ($.cookie('path') !== null){
//	   prepare_history();
//	}
//	var RegExp = /[dom|cottage|siti|jubilejnye\-doma|trend|esite|classic|easy|optimi|mini|town\-houses]..tem=/;
//	var url = document.location.toString().replace(/http:\/\/[^\/]*\/(.*)/,'$1');
//	var matchPos = url.toString().search(RegExp);
//	if(matchPos != -1){
//	  if ($.cookie('path') == null){
//	   path = '';
//	  } else {
//	   path = $.cookie('path');
//	  }
//// alert(path.indexOf(url,0));
////	  if ((path.indexOf(url,0) == -1) || (path == '')){
//// alert(encodeURIComponent(url));
////	    path = path.replace(encodeURIComponent(url), '');
//	    path = path.replace(url, '');
//	    path = path.replace('||', '|');
//	    path = url + '|' + path;
//	    arr = path.split('|', 10);
//	    path = arr.join('|');
//	    $.cookie('path', path, { expires: 365, path: '/'});
////	  }
//	}



});


