/*
 *	20.06.2005 17:27
 *	InputPlaceholder Class v 0.1a
 *
 *	30.06.2005 20:36
 *	InputPlaceholder Class v 0.1b
 *
 *	01.07.2005 18:30
 *	InputPlaceholder Class v 0.1c
 */

/*	Методы:
 *		отсутствуют
 *
 *	Свойства
 *		Input			Элемент формы, с которым работаем
 *		Value			Значение надписи по умолчанию
 *		CssFilled		Имя css-класса для отображения заполненого поля
 *		CssEmpty		Имя css-класса для отображения пустого поля
 */

/*	Конструктор
 *	Параметры:
 *		input			Элемент формы ( input[@type='text'] ), с которым работаем
 *		value			Значение надписи по умолчанию, т. е. тот самый placeholder
 *		cssFilled		Имя css-класса для отображения заполненого поля (применяется к input)
 *		cssEmpty		Имя css-класса для отображения пустого поля (применяется к input)
 */
/*
	Я не машина, я просто читаю исходники.
*/
function InputPlaceholder (input, value, cssFilled, cssEmpty)
{
	var thisCopy = this
	
	this.Input = input
	this.Value = value
	this.SaveOriginal = (input.value == value)
	this.CssFilled = cssFilled
	this.CssEmpty = cssEmpty

	this.setupEvent (this.Input, 'focus', function() {return thisCopy.onFocus()})
	this.setupEvent (this.Input, 'blur',  function() {return thisCopy.onBlur()})
	this.setupEvent (this.Input, 'keydown', function() {return thisCopy.onKeyDown()})

	if (input.value == '') this.onBlur();

	return this
}

InputPlaceholder.prototype.setupEvent = function (elem, eventType, handler)
{
	if (elem.attachEvent)
	{
		elem.attachEvent ('on' + eventType, handler)
	}

	if (elem.addEventListener)
	{
		elem.addEventListener (eventType, handler, false)
	}
}

InputPlaceholder.prototype.onFocus = function()
{
	if (!this.SaveOriginal &&  this.Input.value == this.Value)
	{
		this.Input.value = ''
	}
	else
	{
			this.Input.className = ''
	}
}

InputPlaceholder.prototype.onKeyDown = function()
{
	this.Input.className = ''
}

InputPlaceholder.prototype.onBlur = function()
{
	if (this.Input.value == '' || this.Input.value == this.Value)
	{
		this.Input.value = this.Value
		this.Input.className = this.CssEmpty
	}
	else
	{
		this.Input.className = this.CssFilled
	}
}


$.noConflict();

jQuery(function(){
	jQuery('.img-sm').click(function(){
		jQuery('.catalog-page .left').find('.img-sm').removeClass('active');
		jQuery(this).addClass('active');
        
        var current = $(this).find('img').attr('src');
        jQuery('.left .img').find('img:first').remove();
        jQuery('.left .img').append('<img src="' + current.replace('-sm', '') + '" alt="" />');
    });
	
	
	
	jQuery("a.in-reg").fancybox({
        titleShow     : false,
        easingIn      : 'easeOutBack',
        easingOut     : 'easeInBack',
        autoScale       : false,
        scrolling       : 'no'
        // centerOnScroll  : true
    });
	
	jQuery("a.item-quest").fancybox({
        titleShow     : false,
        easingIn      : 'easeOutBack',
        easingOut     : 'easeInBack',
        autoScale       : false,
        scrolling       : 'no'
        // centerOnScroll  : true
    });
	
	init_signup_form();
	init_catalog_form();
	
});

function init_signup_form(){
	
	jQuery('#firm').bind('submit', function() {

		jQuery.ajax({
            type    : 'POST',
            cache   : false,
            url     : '/user/signup/',
            data    : jQuery(this).serializeArray(),
            context : this,
            success : function(data) {
			jQuery('#hide-form').html(data);
              jQuery.fancybox.resize();
            }
        });

        return false;
    });
}

function init_catalog_form(){
	
	jQuery('#catalog_item').bind('submit', function() {

		jQuery.ajax({
            type    : 'POST',
            cache   : false,
            url     : '/CUCatalogPublic/question/',
            data    : jQuery(this).serializeArray(),
            context : this,
            success : function(data) {
			jQuery('#item-quest-form').html(data);
              jQuery.fancybox.resize();
            }
        });

        return false;
    });
}

function reloadCaptcha(elem)
{
	
	var img = jQuery('img', jQuery(elem).parent());
	var src = img.attr('src');

	img.removeAttr('src').attr('src', src);
	
	return false;
	
}


