  document.observe('dom:loaded',  function() {

				   $$('.hover-element').each( function(element){
                                     element.observe('mouseover', function() {
				                                     this.addClassName('hover');
							                        });
				                     element.observe('mouseout', function() {
				                                      this.removeClassName('hover');
                                                      });
									})

				   });

function expressOrderClass(){
	this.url = '/express.php';
	
	this.div = new Element('div', {id: 'expressOrderDiv'});
	
	this.open = function(){
		if(typeof expressOrderDiv == 'object'){
			this.close();
		}

		var	cWidth = 550;
		var cHeight = 350;
		var oLeft = parseInt((document.body.clientWidth - cWidth) / 2);
		var oTop = parseInt((document.body.clientHeight - cHeight) / 2);

		this.div.setStyle({'top': oTop + 'px', 'left': oLeft + 'px', width: cWidth + 'px', height: cHeight + 'px'});

		new Ajax.Request(this.url, {
			method: 'POST',
			parameters: {},
			onSuccess: function(transport){
				this.div.insert({top: transport.responseText}).hide();
			}.bind(this),
			onComplete: function(){
				this.div.show();
			}.bind(this),
			onException: function(a, b){
				alert('express order error: #' + b.message);
			}
		});

		$$('body')[0].insert({top: this.div});
	}

	this.send = function(){
		if($F('order[name]').blank() || $F('order[email]').blank() || $F('order[phone]').blank() || $F('order[text]').blank()){
			alert('Вы должны заполнить все поля.');
			return;
		}

		new Ajax.Request(this.url, {
			method: 'POST',
			parameters: $('expressForm').serialize(),
			onSuccess: function(transport){
				this.div.innerHTML = transport.responseText;
			}.bind(this),
			onComplete: function(){
				this.close();
			}.bind(this),
			onException: function(a, b){
				alert('express order error: #' + b.message);
			}
		});
	}
	
	this.close = function(){
		$('expressOrderDiv').descendants().invoke('remove');
		$('expressOrderDiv').remove();
	}
}

//------------------------------------------------------------------------------

function orderFormClass(url){
	this.url = url || '/?module=shop&media=ajax';

	this.validate = function(flag){
		var form = $('userOrderForm');
		form.formIsValid.value = 0;

		if(flag){
			var result = true;

			$w('user_data_name1 user_data_name2 user_data_phone user_data_address user_data_email').reverse().each(function(el){
				if($(el) != null){
					if($F(el).blank()){
						$(el).addClassName('empty_field').focus();
						result = false;
					}
					else{
						$(el).removeClassName('empty_field');
					}
				}
			});

			if(result){
				form.formIsValid.value = 1;
				form.submit();
			}
		}
		else{
			$w('user_data_name1 user_data_name2 user_data_phone user_data_address user_data_email').each(function(el){
				$(el).removeClassName('empty_field');
			});
		}

		return false;
	}
}

//------------------------------------------------------------------------------

function shopBasketClass(url){
	this.url = url || '/?module=shop&media=ajax';

	this.add = function(gid, count){
		new Ajax.Request(this.url, {
			method: 'GET',
			parameters: {action: 'add', gid: gid, count: count},
			onSuccess: function(transport){
				if(transport.responseText.length > 0){
					alert(transport.responseText);
				}
			},
			onComplete: function(){
				this.updateCart();
			}.bind(this),
			onException: function(a, b){
				alert('AddCart error: #' + b.message);
			}
		});
	}

	this.updateCart = function(){
		if($('shopbasket_goods') && $('shopbasket_price')){
			new Ajax.Request(this.url, {
				method: 'GET',
				parameters: {action: 'update'},
				onSuccess: function(transport){
					if(transport.responseText.length && transport.responseText.isJSON() == true){
						var result = transport.responseText.evalJSON();
						$('shopbasket_goods').update(result.total);
						$('shopbasket_price').update(result.price);
					}
					else if(transport.responseText.length){
						alert(transport.responseText);
					}
				},
				onException: function(a, b){
					alert('UpdateCart error: #' + b.message);
				}
			});
		}
	}
}

//------------------------------------------------------------------------------

function zoomImageClass(){
	this.iddle = true;
	this.div = new Element('div', {id: 'zoomImageDiv'});
	this.close = new Element('img', {src: '/images/close.gif', width: 16, height: 16, title: 'close'}).addClassName('close');
	this.img = null
	
	this.zoom = function(src){
		if(this.iddle == false) return;
		this.iddle = false;

		this.img = new Element('img');
		this.img.observe('load', this.onload.bindAsEventListener(this));
		this.img.observe('click', this.onclose.bindAsEventListener(this));
		this.img.src = src;
	}
	
	this.onload = function(e){
		var oLeft = parseInt((document.body.clientWidth - this.img.width) / 2);
		var oTop = parseInt((document.body.clientHeight - this.img.height) / 2);

		this.div.setStyle({'top': oTop + 'px', 'left': oLeft + 'px', width: this.img.width + 'px', height: this.img.height + 'px'});
		this.div.insert({top: this.img}).insert({top: this.close}).hide();

		$$('body')[0].insert({top: this.div});
		$('zoomImageDiv').show();
	}
	
	this.onclose = function(e){
		$('zoomImageDiv').descendants().invoke('remove');
		$('zoomImageDiv').remove();
		this.img = null;
		this.iddle = true;
	}

	this.close.observe('click', this.onclose.bindAsEventListener(this));
}

//------------------------------------------------------------------------------

Event.observe(window, 'load', function(e){
	var hover = false;
	var els = [];
	var src = [];
	$$('img[rel*="vstar"]').each(function(el, i){
		els[i] = el;
		src[i] = [el.src, el.src.substring(0, el.src.length - 4) + '_a' + el.src.substring(el.src.length - 4)];
		el.observe('mouseover', function(e, i){
			hover = true;
			for(var j = 0; j < els.length; j++){
				els[j].src = j <= i ? src[j][1] : src[j][0];
			}
		}.bindAsEventListener(this, i));
		el.observe('mouseout', function(e){
			hover = false;
			(function(){
				if(hover == false){
					for(var j = 0; j < els.length; j++){
						els[j].src = src[j][0];
					}
				}
			}).delay(.1);
		});
	});
});

//------------------------------------------------------------------------------

Event.observe(window, 'load', function(e){
	$$('img[rel="hover"]').each(function(el, i){
	    if (el.tagName.match(/img/i) && el.src != '') {   
	        defsrc = el.src;   
			hovsrc = el.src.substring(0, el.src.length - 4) + '_a' + el.src.substring(el.src.length - 4);
	        (function(defsrc, hovsrc) {   
	            el.onmouseover = function(){
	                if (this.src == defsrc) this.src = hovsrc;
	            }   
	            el.onmouseout = function(){   
	                if (this.src == hovsrc) this.src = defsrc;
	            }   
	        })(defsrc, hovsrc);   
	    }   
	});
});

//------------------------------------------------------------------------------

Event.observe(document, 'dom:loaded', function(e){
	$$('img[rel="hover"]').each(function(el, i){
	    if (el.tagName.match(/img/i) && el.src != '') {   
	        defsrc = el.src;   
			hovsrc = el.src.substring(0, el.src.length - 4) + '_a' + el.src.substring(el.src.length - 4);
	        (function(defsrc, hovsrc) {   
	            el.onmouseover = function(){
	                if (this.src == defsrc) this.src = hovsrc;
	            }   
	            el.onmouseout = function(){   
	                if (this.src == hovsrc) this.src = defsrc;
	            }   
	        })(defsrc, hovsrc);   
	    }   
	});

	$$('input[rel="clear"]').each(function(el, i){
		if(el.type == 'text' && el.value != ""){
			el.setStyle({color: '#999'});
			var defValue = el.value;
			(function(defValue){
				el.observe('focus', function(e){
					if(this.value == defValue) this.value = "";
					el.setStyle({color: '#000'});
				});
				el.observe('blur', function(e){
					if(this.value == "") this.setStyle({color: '#999'}).value = defValue;
				});
			})(defValue);
		}
	});
});
