﻿function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){

					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

addEvent(window,'unload',EventCache.flush);

jQuery.fn.validForm = function(userOptions) {

    var options = {
    	errorContainer: "#errorList",
    	errorContainerCssClass: {
    		'text-color': "#F00"
    	}
    }

    $.extend(options, userOptions);

    $('head').append("<style>.inputError{border: 1px solid #F00!important; background: #FAA;}</style>");

    $(this).each( function() {
    	var id = "#" + $(this).attr('id');
        if ($(id + " input").length > 0) {
            Validate(id);
        } else {
        	return false;
        }
    });
    function Validate(form) {

        $(form + " input[type=submit]").click(function() {
        var errorAmount = 0;
        var collection = $(form + " input[type=text].required")
            .add(form +" input[type=password].required")
            .add(form +" input[type=file].required")
            .add(form +" textarea.required")
            .add(form +" select.required");
        collection.each(function() {
         	    var element = $(this);
         		var length = $.trim(element.attr('value'));

         		if (!length) {
         			element.addClass('inputError');
         			errorAmount++;
         		}
         		else {
                    element.removeClass('inputError');
         		}
     	});
     	collection.keypress( function (){
            $(this).removeClass('inputError');
            if ($(options.errorContainer).is(':visible')) {
        	$(options.errorContainer).hide();
            }
        });
        collection.change( function() {
            if (($(this).attr('value')).length < 1) {
                $(this).addClass('inputError');
            }
            else {
            	$(this).removeClass('inputError');
            }
        });

        if (errorAmount) {
        	$(options.errorContainer).html('Пожалуйста, заполните все обязательные поля');
        	$(options.errorContainer).show();
            return false;
        } else {
        	$(options.errorContainer).hide();
        }
        });
    }

}

$(document).ready(function(){
	
	if (!($.browser.msie)) {
        	$(".navBlock .hover").show().css({
            		"opacity": 0
        	});
        	$(".navBlock a").not(".active").hover(function () {
            		$(this).find(".hover").stop().animate({
                		"opacity": 1
            		}, 120);
        	}, function () {
            		$(this).find(".hover").stop().animate({
                		"opacity": 0
            		}, 100);
        	});
	}

	if ( $.browser.msie && $.browser.version == 6.0 ){
		$(".navBlock a").not(".active").hover(function () {
			$(this).find(".hover").show();
		}, function () {
			$(this).find(".hover").hide();
		});
	}

	$("a[rel*='external']").click(function () {
		this.target = "_blank";
	});
	
	if (!$.browser.webkit) {
		
		$('INPUT[placeholder], TEXTAREA[placeholder]').blur(function(){ 
			
			if ($(this).val()=='') {
				$(this).val($(this).attr('placeholder'));
				$(this).addClass('placeholder');
			}
			
		}).focus(function(){
			
			$(this).removeClass('placeholder');
			if ($(this).val()==$(this).attr('placeholder'))
				$(this).val('');
			
		}).each(function(){
			
			if ( ($(this).val()=='') || ($(this).val()==$(this).attr('placeholder')) ) {
				$(this).val( $(this).attr('placeholder') );
				$(this).addClass('placeholder');
			}
			
			var form = $(this).closest('FORM');
			if (form.length)
				form.submit(function(){
					if ($(this).val()==$(this).attr('placeholder'))
						$(this).val('');
				});
			
		});
		
	}
	
});

$(document).ready(function(){
	var link = document.location.href;
	$(".zoom_testim_rez").click (function(obj){
				$("#BigImage").attr({
					style: 'max-height: 560px'
				});
		$("#BigImage img").attr({
		src: this.href
		});
		$("#show").show();
		
		return false;
	});
	$(".BigImageClose").click (function(){
		$("#show").hide();		
		$("#BigImage img").removeAttr("src");
		$("#BigImage").removeAttr("style");
	});
	
	$(".zoom").click (function(obj){
		$("#BigImage img").attr({
		src: this.href
		});
		$("#show").show();
		
		return false;
	});
	$(".BigImageClose").click (function(){
		$("#show").hide();		
		$("#BigImage img").removeAttr("src");
	});
});


$(document).ready(function() {

	/* This is basic - uses default settings */
	
	$("a.single_image").fancybox();
	
	/* Using custom settings */
	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	/* Apply fancybox to multiple items */
	
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	$("a.grouped_elements").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
									 });
});

$(document).ready(function() {
	$(function() {
    	$(".carusel").jCarouselLite({
        	btnNext: ".next",
        	btnPrev: ".prev",
			visible: 4,
			circular: false,
			mouseWheel: true
    	});
	});
});
$(document).ready(function() {
	$(function() {
    	$(".carusel1").jCarouselLite({
        	btnNext: ".next1",
        	btnPrev: ".prev1",
			visible: 4,
			circular: false,
			mouseWheel: true
    	});
	});
});
