var is_rated = null;

Asset.images([
	'/images/moognify.gif',
	'/images/b_home1-on.gif',
	'/images/b_home2-on.gif',
	'/images/b_home3-on.gif',
	'/images/b_home4-on.gif',
	'/images/ico_photos-on.gif',
	'/images/ico_archive-on.gif',
	'/images/b_munis2.gif',
	'/images/b_plus2.gif',
	'/images/tbl3_7.gif',
	'/images/tbl3_9.gif',
	'/images/scroll.gif',
	'/images/knob.gif'
]);

var MooScroller = new Class({

    options: {
	  knobclone: null,
	  knobcloneTrack: null,
	  usePreloader: false,
	  thumbWidth: 100,
      maxThumbSize: 10,
      scrollSteps: 10,
      mode: 'vertical',
      width: 0, //required only for mode: horizontal
      wheel: true,
      scrollLinks: {
        forward: 'scrollForward',
        back: 'scrollBack'
      },
      offset: 0,
      onScroll: Class.empty,
      onPage: Class.empty
    },

    initialize: function(content, knob, options){
      this.setOptions(options);
      this.horz = (this.options.mode == "horizontal");
      this.content = $(content).setStyle('overflow', 'hidden');
      this.knob = $(knob);
	  this.track = this.knob.getParent();

	  if (this.options.knobclone!=null) {
		  this.knob2 = $('scroll_knob2');
		  this.track2 = $(this.options.knobcloneTrack);
	  }

      this.setPositions();

      if(this.horz && this.options.width) {
        this.wrapper = new Element('div');
        this.content.getChildren().each(function(child){
          this.wrapper.adopt(child);
        });
        this.wrapper.injectInside(this.content).setStyle('width', this.options.width);
      }

      this.bound = {
        'start': this.start.bind(this),
        'end': this.end.bind(this),
        'drag': this.drag.bind(this),
        'wheel': this.wheel.bind(this),
        'page': this.page.bind(this),
        'move': this.move.bind(this)
      };

      this.position = {};
      this.mouse = {};
      this.update();
      this.attach();

      var clearScroll = function (){
        $clear(this.scrolling);
      }.bind(this);
      ['forward','back'].each(function(direction) {
        var lnk = $(this.options.scrollLinks[direction]);
        if(lnk) {
          lnk.addEvents({
            mousedown: function() {
              this.scrolling = this[direction].periodical(50, this);
            }.bind(this),
            mouseup: clearScroll.bind(this),
            click: clearScroll.bind(this)
          });
        }
      }, this);

	  this.knob.addEvent('click', clearScroll.bind(this));

	  if (this.options.knobclone!=null) {
		  this.knob2.addEvent('click', clearScroll.bind(this));
	  }

	  window.addEvent('domready', function(){
        try {
          $(document.body).addEvent('mouseup', clearScroll.bind(this));
        }catch(e){}
      }.bind(this));
    },

	setPositions: function(){
      [this.track, this.knob].each(function(el){
        if (el.getStyle('position') == 'static') el.setStyle('position','relative');
      });
    },

    update: function(){
      var plain = this.horz?'Width':'Height';
      this.contentSize = this.content['offset'+plain];
      this.contentScrollSize = this.content['scroll'+plain];
      this.trackSize = this.track['offset'+plain];
      this.trackSize -= this.options.offset * 2;
      this.contentRatio = this.contentSize / this.contentScrollSize;
      this.knobSize = (this.trackSize * this.contentRatio).limit(this.options.maxThumbSize, this.trackSize);
      this.scrollRatio = this.contentScrollSize / this.trackSize;
	  this.knob.setStyle(plain.toLowerCase(), this.knobSize+'px');

	  if (this.options.knobclone!=null) {
		  this.knob2.setStyle(plain.toLowerCase(), this.knobSize+'px');
	  }

	  this.updateThumbFromContentScroll();
      this.updateContentFromThumbPosition();
    },

    updateContentFromThumbPosition: function(){
      this.content[this.horz?'scrollLeft':'scrollTop'] = this.position.now * this.scrollRatio;
    },

    updateThumbFromContentScroll: function(){
      this.position.now = (this.content[this.horz?'scrollLeft':'scrollTop'] / this.scrollRatio).limit(0, (this.trackSize - this.knobSize));
	  this.knob.setStyle(this.horz?'left':'top', this.position.now+'px');

	  if (this.options.knobclone!=null) {
		  this.knob2.setStyle(this.horz?'left':'top', this.position.now+'px');
	  }
	},

    attach: function(){
      this.knob.addEvent('mousedown', this.bound.start);

	  if (this.options.scrollSteps) this.content.addEvent('mousewheel', this.bound.wheel);

	  if (this.options.knobclone!=null) {
		  this.knob2.addEvent('mousedown', this.bound.start);
		  this.track2.addEvent('mouseup', this.bound.move);
	  }

      this.track.addEvent('mouseup', this.bound.page);
    },

    wheel: function(event){
      event = new Event(event);
      this.scroll(-(event.wheel * this.options.scrollSteps));
      this.updateThumbFromContentScroll();
      event.stop();
    },

    scroll: function(steps){
      steps = steps||this.options.scrollSteps;
      this.content[this.horz?'scrollLeft':'scrollTop'] += steps;
      this.updateThumbFromContentScroll();

	  if (this.options.usePreloader==true) {
		updatePreviews(this.content, this.options.thumbWidth);
	  }
    },

    getpos: function(){
      return this.content[this.horz?'scrollLeft':'scrollTop'];
    },

    setpos: function(position){
      this.content[this.horz?'scrollLeft':'scrollTop'] = position;
      this.updateThumbFromContentScroll();

	  if (this.options.usePreloader==true) {
		updatePreviews(this.content, this.options.thumbWidth);
	  }
    },

	forward: function(steps){
      this.scroll(steps);
    },

	back: function(steps){
      steps = steps||this.options.scrollSteps;
      this.scroll(-steps);
    },

    page: function(event){
      event = new Event(event);
      var axis = this.horz?'x':'y';
      var forward = (event.page[axis] > this.knob.getPosition()[axis]);
      this.scroll((forward?1:-1)*this.content['offset'+(this.horz?'Width':'Height')]);
      this.updateThumbFromContentScroll();
      this.fireEvent('onPage', forward);
      event.stop();
    },

	move: function(event) {
      event = new Event(event);
      var axis = this.horz?'x':'y';
      this.mouse.now = event.page[axis];
      this.track.start = this.track.getStyle(this.horz?'left':'top').toInt();
	  this.position.now = (this.mouse.now - (window.getWidth() - this.trackSize)/2) - this.knobSize/2;
	  this.updateContentFromThumbPosition();
      this.updateThumbFromContentScroll();
      event.stop();

	  if (this.options.usePreloader==true) {
		  updatePreviews(this.content, this.options.thumbWidth);
	  }

	},

    start: function(event){
      event = new Event(event);
      var axis = this.horz?'x':'y';
      this.mouse.start = event.page[axis];
      this.position.start = this.knob.getStyle(this.horz?'left':'top').toInt();

	  document.addEvent('mousemove', this.bound.drag);
      document.addEvent('mouseup', this.bound.end);

	  this.knob.addEvent('mouseup', this.bound.end);

	  if (this.options.knobclone!=null) {
		  this.knob2.addEvent('mouseup', this.bound.end);
	  }

	  event.stop();
    },

    end: function(event){
      event = new Event(event);
      document.removeEvent('mousemove', this.bound.drag);
      document.removeEvent('mouseup', this.bound.end);

	  this.knob.removeEvent('mouseup', this.bound.end);

	  if (this.options.knobclone!=null) {
		  this.knob2.removeEvent('mouseup', this.bound.end);
	  }

	  if (this.options.usePreloader==true) {
		  updatePreviews(this.content, this.options.thumbWidth);
	  }

	  event.stop();
    },

    drag: function(event){
      event = new Event(event);
      var axis = this.horz?'x':'y';
      this.mouse.now = event.page[axis];
      this.position.now = (this.position.start + (this.mouse.now - this.mouse.start)).limit(0, (this.trackSize - this.knobSize));
      this.updateContentFromThumbPosition();
      this.updateThumbFromContentScroll();
      event.stop();
    },

	left: function(){
	  this.position.now = 0;
      this.updateContentFromThumbPosition();
      this.updateThumbFromContentScroll();
    },

	right: function(){
	  this.position.now = this.trackSize - this.knobSize;
      this.updateContentFromThumbPosition();
      this.updateThumbFromContentScroll();
    }
});

MooScroller.implement(new Events);
MooScroller.implement(new Options);

MooWaiter = {
  // the script to wait this amount of msecs until it shows the loading element
  timeUntilShow: 250,

  // opacity of loading element
  opacity: 0.5,

  // Start waiting status - show loading element
  startWaiting: function(className, timeUntilShow, opacity) {
    element = this;
    className = className || 'waiting';
    timeUntilShow = timeUntilShow || MooWaiter.timeUntilShow;
    opacity = opacity || MooWaiter.opacity;
    element._waiting = true;
    if (!element._loading) {
      var e = element._loading = new Element('div', {
      	'styles': {
      		'position': 'absolute',
      		'opacity': opacity
      	}
      }).injectInside(/*element.offsetParent*/$(element).getParent() || document.body);
    }
    element._loading.className = className;
    (function() {
      if (this._waiting) {
        $(this._loading).setStyles({
          'left': this.getLeft(),
          'top': this.getTop(),
          'width': this.getSize().size.x,
          'height': this.getSize().size.y
        });
      }
    }).bind(element).delay(timeUntilShow);
    return this;
  },

  // Stop waiting status - hide loading element
  stopWaiting: function() {
    element = this;
    if (element._waiting) {
      element._waiting = false;
      //element._loading.parentNode.removeChild(element._loading);
      $(element._loading).remove();
      element._loading = null;
    }
    return this;
  }
};

if (MooTools) {
  Element.extend(MooWaiter);

  /* Extends functionality from <Waiter> into <Ajax>.

     Additional Options:
     useWaiter - (boolean) if true will automatically apply a <Waiter> to the update target; defaults to false. Note: if you do not specify a value for update option this is ignored.
     waiterOptions - (object) options value passed on to <Waiter> class.
     waiterTarget - (element) if specified, the Waiter will overlay this element, otherwise it uses the update target specified in the ajax options.
  */
  if (typeof Ajax != "undefined") {
     var Ajax = Ajax.extend({
         options: {
           useWaiter: false,
           waiterOptions: {
             className: 'waiting',
             timeUntilShow: MooWaiter.timeUntilShow,
             opacity: MooWaiter.opacity
           },
           waiterTarget: false
         },
         initialize: function(url, options) {
           this.parent(url, options);
           if (this.options.useWaiter && ($(this.options.waiterTarget) || $(this.options.update))) {
             var stop = function() {
               ($(this.options.waiterTarget) || $(this.options.update)).stopWaiting();
             }.bind(this);
             this.addEvent('onComplete', stop);
             this.addEvent('onFailure', stop);
           }
         },
         request: function(data) {
           if (this.options.useWaiter) {
             try {
               ($(this.options.waiterTarget) || $(this.options.update)).startWaiting(this.options.waiterOptions.className, this.options.waiterOptions.timeUntilShow, this.options.waiterOptions.opacity);
             } catch(e) {}
           }
           this.parent(data);
           return this;
         }
     });
  }
}

var hasFlash = function(){
  var nRequiredVersion = 9;

  if (window.ie && navigator.appVersion.indexOf("Windows") > -1) {
    document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');

    if (window.hasFlash != null) {
      return window.hasFlash;
    };
  };

  if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
     var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
     var ver = flashDescription.match(/\d{1,2}\.\d/);
     return ver ? (ver[0].toInt() >= nRequiredVersion) : false;
  };

  return false;
}();

var Blackbox = {
	init: function(options){
		this.eventPosition = this.position.bind(this);
		this.overlay = new Element('div', {'id': 'lbOverlay'}).injectInside(document.body);
		this.fx = { overlay: this.overlay.effect('opacity', {duration: 10}).hide() };
		this.position();
		this.setup(true);
		this.fx.overlay.start(0.5);
	},

	position: function(){
		var divPosition = window.ie6 ? 'absolute' : 'fixed';
		var divTop = window.ie6 ? window.getScrollTop() : 0;
		this.overlay.setStyles({'top': divTop, 'height': window.getHeight(), 'position': divPosition});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : 'visible';
		});
		if (window.ie6)
		{
			var fn = open ? 'addEvent' : 'removeEvent';
			window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		}
	},

	close: function(){
		for (var f in this.fx) this.fx[f].stop();
		this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
		return false;
	}
};

function updatePreviews(content, width) {
	var inner_box = $$('#' + content.id + ' a.innerdiv');
	var leftpos = content['scrollLeft'];
	var rightpos = leftpos + 846;

	inner_box.each(function(el, index) {
		var left = index*width;
		var right = index*width+width;

		if ((left>=leftpos && left<rightpos) || (right>leftpos && right<=rightpos)) {
			el.setStyles({
				'background-image': 'url(' + el.href + ')'
			});
		}
	});
}

function showError(text) {
	alert(text);
}

function formsubmit() {
	$('resultsform').send({
		useWaiter: true,
		evalScripts: true,
		update: 'resultsdiv'
	});
}

function dropmodels() {
	$('rmodels').selectedIndex=0;
	$('rclubs').selectedIndex=0;
}

function dropmodels2() {
	$('rmodels').selectedIndex=0;
}

function setnames(elem) {
	var pattern = new RegExp(elem.value, 'i');
	names.each(function(item, index) {
		var style = (!item.match(pattern)) ? 'none' : 'block';
		$('name' + index).setStyle('display', style);
	});
}

function updatephoto(el,id,width,height) {
	if (lastid==id)
		return;

    window.location.hash = "#p" + id

	if (lastid!=null)
		$('pre' + lastid).removeClass('pselect').addClass('preview');

	el.removeClass('preview').removeClass('phover').addClass('pselect');

	$('fulltbl').setStyles({
		'width': width,
		'margin-top': -height
	});

	$('prev').setStyles({
		'height': height,
		'display': 'none'
	});

	$('next').setStyles({
		'height': height,
		'display': 'none'
	});

	$('central').setStyle('height', height);
	$('prevlink').setStyle('margin-top', height/2-28);
	$('nextlink').setStyle('margin-top', height/2-28);
	$('central').addClass('waiting5');

	$('fullimg').src = '/files/pictures/' + id + '_0.jpg';

	lastid = id;
}

function changephoto(container, dir) {
	var width = container.options.thumbWidth;
	var len = imganchors.length;
	var key = 0;

	if (lastid!=null) {
		imganchors.each(function(item, index){
			if (item[0]==lastid) {
				key = index;
			}
		});
	}

	if (dir < 0) {
		if (key==len-1) {
			key = 0;
		} else {
			key++;
		}

		if (key>7) {
			if (!checkPosition(key)) {
				container.setpos(key*width-(width*8)+27);
			}
		} else if (key==0) {
			container.setpos(0)
		}

	} else {
		if (key==0) {
			key = len - 1;
		} else {
			key--;
		}

		if (key<len-7) {
			if (!checkPosition(key)) {
				container.setpos(key*width);
			}
		} else if (key==len-1) {
			container.setpos(len*width)
		}

	}

	updatephoto($('pre' + imganchors[key][0]),imganchors[key][0],imganchors[key][1],imganchors[key][2]);
}

function checkPosition(key) {
	var content = $('preview_box');
	var inner_box = $$('#' + content.id + ' a.innerdiv');
	var leftpos = content['scrollLeft'];
	var rightpos = leftpos + 846;
	var width = 97;

//	alert('leftpos=' + leftpos + ', rightpos=' + rightpos)

	var left = key*width;
	var right = key*width+width;

//	alert('left=' + left + ', right=' + right)

//leftpos=1226, rightpos=2072, width=97
//left=1649, right=1746

	if ((left>=leftpos && left<rightpos) 
		|| (right>leftpos && right<=rightpos))
			return true;

	return false;
}

function changeshot(el, url, time) {
	if (lastid==el.id)
		return;

	if (lastid!=null)
		$(lastid).removeClass('pselect2');

	lastid = el.id;
	$(lastid).addClass('pselect2');

	$('webcamovr').addClass('waiting2');
	$('fullwebcam').src = url;
	$('webcamtim2').innerHTML = time;
	$('fullwebcam').onload = function() {
		$('webcamovr').removeClass('waiting2');
	}

	return false;
}

function setashot(el) {
	lastid = el.id;
	$(lastid).addClass('pselect2');
	return false;
}

function viewstats(el) {
	Blackbox.init();
	new Ajax(el.href, {
		useWaiter: true,
		evalScripts: true,
		update: 'stats',
		method: 'get',
		onComplete: function() {
			$('stats').setStyles({
				'display':'block',
				'left':(calcSize().width - 418)/2
			}).setStyle('top', window.getScrollTop() + (calcSize().height - $('stats').getSize().size.y)/2);
		}
	}).request();
	return false;
}

function hidestats() {
	Blackbox.close();
	$('stats').setStyle('display', 'none');
}

function viewprops(el) {
	Blackbox.init();
	new Ajax(el.href, {
		useWaiter: true,
		evalScripts: true,
		update: 'stats',
		method: 'get',
		onComplete: function() {
			if (this.response.text!='') {
				$('stats').setStyles({
					'display':'block',
					'left':(calcSize().width - 418)/2
				}).setStyle('top', window.getScrollTop() + (calcSize().height - $('stats').getSize().size.y)/2);

				window.addEvent('domready', function() {
					var theScroll = new Fx.Scroll('wrapper1', {
						wait: false,
						duration: 1000,
						offset: {'x': 0, 'y': 0},
						transition: Fx.Transitions.linear
					});

					$('resgoup1').addEvents({
						'mousedown': function() {
							theScroll.toTop();
						},
						'mouseup': function() {
							theScroll.stop();
							checkScrollPos(theScroll);
						}
					});

					$('resgodo1').addEvents({
						'mousedown': function() {
							theScroll.toBottom();
						},
						'mouseup': function() {
							theScroll.stop();
							checkScrollPos(theScroll);
						}
					});

				});
			} else
				Blackbox.close();
		}
	}).request();
	return false;
}

function selectphoto(el, iid) {
	var id = el.id.replace(/imgs/,'');

	isrow = Math.ceil(id/3);
	inrow = 3 - (isrow*3 - id);

	if (inrow==1) {
		$('movecursor1').setStyle('visibility', 'hidden');
		$('movecursor2').setStyle('visibility', 'visible');
	} else if (inrow==2) {
		$('movecursor1').setStyle('visibility', 'visible');

		if (id==imgcnt)
			$('movecursor2').setStyle('visibility', 'hidden');
		else
			$('movecursor2').setStyle('visibility', 'visible');

	} else {
		$('movecursor1').setStyle('visibility', 'visible');
		$('movecursor2').setStyle('visibility', 'hidden');
	}

	if (lastrow!=1)
	{
		if (isrow==1) {
			$('movecursor3').setStyle('visibility', 'hidden');
			$('movecursor4').setStyle('visibility', 'visible');
		} else if (isrow==lastrow) {
			$('movecursor3').setStyle('visibility', 'visible');
			$('movecursor4').setStyle('visibility', 'hidden');
		} else {
			$('movecursor3').setStyle('visibility', 'visible');
			$('movecursor4').setStyle('visibility', 'visible');
		}
	}

	$('fullovr').addClass('waiting4');
	$('fullimg').src = '/files/vehicles/' + id + '/' + iid + '_0.jpg';

	if ($('fullimg').parentNode.href!=null)
	{
		$('fullimg').parentNode.href = '/files/vehicles/' + id + '/' + iid + '_3.jpg'
	}

	$('fullimg').onload = function() {
		$('fullovr').removeClass('waiting4');
	}

	$(lastid).removeClass('ihover');
	el.addClass('ihover');
	lastid = el.id;
}

function movecursor(dir, iid) {
	var id = lastid.replace(/imgs/,'');
	id = id.toFloat();

	var isrow = Math.ceil(id/3);
	var inrow = 3 - (isrow*3 - id);

	switch(dir) {
		case 1:
			if (inrow - 1 >= 1)
			{
				--id;
			}
		break;

		case 3:
			if (id - 3 >= 1) {
				id = id - 3;
			}
		break;

		case 2:
			if (id < imgcnt && inrow + 1 <= 3)
			{
				++id;
			}
		break;

		case 4:
			if (id + 3 <= imgcnt) {
				id = id + 3;
			}
		break;
	}

	selectphoto($('imgs' + id), iid);
}

function setCtrlKeys(id) {
	document.addEvent('keydown', function(event){
		if (event.ctrlKey) {
			switch (event.keyCode) {
				case 0x25:
					new Event(event).stop();
					movecursor(1,id);
				break;

				case 0x26:
					new Event(event).stop();
					movecursor(3,id);
				break;

				case 0x27:
					new Event(event).stop();
					movecursor(2,id);
				break;

				case 0x28:
					new Event(event).stop();
					movecursor(4,id);
				break;
			}
		}
	});
}

function startmenu() {
	window.addEvent('domready', function() {
		$('point1').addEvent('mouseenter', function(){
			this.addClass('lnkhov');
			$('submenu1').addClass('navhov');
		}).addEvent('mouseleave', function(){
			this.removeClass('lnkhov');
			$('submenu1').removeClass('navhov');
		});

		$('submenu1').addEvent('mouseenter', function(){
			$('point1').addClass('lnkhov');
			this.addClass('navhov');
		}).addEvent('mouseleave', function(){
			$('point1').removeClass('lnkhov');
			this.removeClass('navhov');
		});

		$('point3').addEvent('mouseenter', function(){
			this.addClass('lnkhov');
			$('submenu2').addClass('navhov');
		}).addEvent('mouseleave', function(){
			this.removeClass('lnkhov');
			$('submenu2').removeClass('navhov');
		});

		$('submenu2').addEvent('mouseenter', function(){
			$('point3').addClass('lnkhov');
			this.addClass('navhov');
		}).addEvent('mouseleave', function(){
			$('point3').removeClass('lnkhov');
			this.removeClass('navhov');
		});
	});
}

function detailinfo(id) {
	if (lastinfo!=null && lastinfo!=id) {
		$('info' + lastinfo).setStyle('display', 'none');
		$('info' + lastinfo).opened = false;
	}

	if ($('info' + id).opened!=true) {
		$('info' + id).setStyle('display', 'block');

		var pos = $('info' + id).getCoordinates();
		$('info' + id).setStyle('margin-top', -pos.height);

		$('info' + id).opened = true;
	} else {
		$('info' + id).setStyle('display', 'none');
		$('info' + id).opened = false;
	}

	lastinfo = id;
}

function calcSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return {'width': myWidth, 'height': myHeight}
}

function checkScrollPos(scroller) {
	var currentY1 = scroller.element.scrollTop;
	var maxw = $('resinner1').getSize().size.y;

	if (currentY1>0)
		$('bresgoup1').src = 'images/forum_up-on.gif';
	else
		$('bresgoup1').src = 'images/forum_up.gif';

	if (currentY1<maxw-438)
		$('bresgodo1').src = 'images/forum_down-on.gif';
	else
		$('bresgodo1').src = 'images/forum_down.gif';
}

function viewvideo(id) {
	Blackbox.init();

	var el = $('vid' + id);
	var vi = $('fullvideo' + id);

	vi.setStyle('display', 'block');

	var co = vi.getCoordinates();
	var left = (calcSize().width - co.width)/2;
	var top = window.getScrollTop() + (calcSize().height - co.height)/2;

	vi.setStyles({
		'left': left,
		'top': top
	});

	var closer = new Element('div', {
		'styles': {
			'top': 0,
			'left': 0,
			'width': 14,
			'height': 14,
			'z-index': 111,
			'margin-top': -20,
			'margin-left': co.width-23,
			'cursor': 'pointer',
			'position': 'absolute',
			'border': '#FFFFFF 3px solid',
			'background-image': 'url(images/close.gif)'
		  }
	}).injectInside(vi).addEvent('click', function(){
		vi.setStyle('display', 'none');
		Blackbox.close();
		this.remove();
	});

	return false;
}

function setbody(id) {
	if (id==2) {
		$('vehicle').value = 1;
	} else {
		$('vehicle').value = '';
		$('bodies').value = id;
	}
	formsubmit();
}

function showlist(id) {
	var listdiv = $('list_' + id);

	if (listdiv.getStyle('display')=='block') {
		listdiv.setStyle('display', 'none');
		$('sel' + id).removeClass('open2');
	} else {
		var c = $('sel' + id).getCoordinates();
		var top = c.top + c.height;
		var left = c.left;

		$$('#selector div.subsel').each(function(el) {
			var parent = el.parentNode;
			$(parent).removeClass('open2');
			el.setStyle('display', 'none');
		});

		listdiv.setStyles({
			'top': top,
			'left': left,
			'display': 'block'
		});

		$('sel' + id).addClass('open2');
	}
}

function setvars(name, id) {
	$('r' + name).value = id;

	if ($('rmodels')!=null && name=='brands') {
		$('rmodels').value = '';
	}

	formsubmit();
}

function switchview(type) {
	if (type==1) {
		$('detailview').setStyle('display', 'block');
		$('tableview').setStyle('display', 'none');
	} else {
		$('detailview').setStyle('display', 'none');
		$('tableview').setStyle('display', 'block');
	}
}

function authmenu() {
	var el = $('logmnu');
	if (el.getStyle('display')=='none') {
		el.setStyle('display', 'block');
	} else {
		el.setStyle('display', 'none');
	}
}

function account() {
	var el = $('account');
	if (el.getStyle('display')=='none') {
		el.setStyle('display', 'block');
	} else {
		el.setStyle('display', 'none');
	}
}

function votecomm(id, vote) {
	if ($('votetd' + id).isVoted!=true) {
		var btn = vote==1 ? 'plus' : 'minus';

		$('votetd' + id).isVoted = true;
		$(btn + id).src = '/images/b_' + btn + '2.gif';

		new Ajax('/comments.php', {
			method: 'get',
			update: $('commrate' + id),
			data: 'action=votecomm&id=' + id + '&vote=' + vote
		}).request();
	}
}

function votepost(id, vote) {
	new Ajax('/blog.php', {
		method: 'get',
		update: 'postrate',
		data: 'action=votepost&id=' + id + '&vote=' + vote
	}).request();
}

function add2friends(id) {
	$('add2friend').setStyle('display', 'none');
	new Ajax('/friends.php', {
		method: 'get',
		data: 'action=add&id=' + id
	}).request();
}

function gotopage(el) {
	new Ajax(el.href, {
		useWaiter: true,
		evalScripts: true,
		waiterOptions: { className: 'waiting2' },
		update: 'tableview',
		data: 'ajax=1'
	}).request();
	return false;
}

function ratings_on(el) {
	var rate = el.id.split('_');
	if (is_rated==null) {
		for (var i = 1; i <= 5; i++) {
			if (i <= rate[2]) {
				$('rating_' + rate[1] + '_' + i).src = '/images/star1.gif';
			} else {
				$('rating_' + rate[1] + '_' + i).src = '/images/star2.gif';
			}
		}
	}
}

function ratings_off(el, score) {
	var rate = el.id.split('_');
	if (is_rated==null) {
		for (var i = 1; i <= 5; i++) {
			if (i <= score) {
				$('rating_' + rate[1] + '_' + i).src = '/images/star1.gif';
			} else {
				$('rating_' + rate[1] + '_' + i).src = '/images/star2.gif';
			}
		}
	}
}

function rate_post(el) {
	is_rated = true;
	var rate = el.id.split('_');
	new Ajax('/blog.php', {
		method: 'get',
		data: 'action=votepost&id=' + rate[1] + '&vote=' + rate[2],
		onComplete: function() {
			$('postvotes').innerHTML = this.response.text;
		}
	}).request();
}

function setratesrc(el, url) {
	if (el.getParent().getParent().isVoted!=true) {
		el.src = url;
	}
}

function togglequick(id) {
	var el = $('quick' + id);
	if (el.opened!=true) {
		el.setStyle('display', 'block');
		el.opened = true;
	} else {
		el.setStyle('display', 'none');
		el.opened = false;
	}
}

function voteuser(id, vote) {
	new Ajax('/bloggers.php', {
		method: 'get',
		update: 'userate',
		data: 'action=voteuser&id=' + id + '&vote=' + vote
	}).request();
}
