if (!console) {
    var console = {
        log: function(){},
        debug: function(){},
        dir: function(){},
        firebug: null
    }
}

$(document).ready(
				function(){
					$('#headerImg').innerfade({
						speed: 1000,
						timeout: 5000,
						type: 'sequence',
						containerheight: '222px'
					});
					
			});

(function($) {

	jQuery.extend({
	    
	    jsHttpRequest: function(options)
	    {
	        var options = jQuery.extend({
	            url:     '/',
	            data:    {},
	            onReady: function(){},
	            cache:   false
	        }, options);
	        
	       // Tools.showStatus(Tools.LOADER);
	        var uid = Tools._statusUid;
	        
	        JsHttpRequest.query(
	            options.url,
	            options.data,
	            function(result, text) {
	
	                if (typeof(result._debug) != 'undefined') {
	                    console.log(result._debug);
	                }
	                
	                if (typeof(result._trace) != 'undefined') {
	                    $.each(result._trace, function(i, message) {
	                        console.log(message);   
	                    });
	                }
	                
	                if (typeof(options.onReady) == 'function') {
	                    options.onReady(result, text);
	                }
	                
	                //if (Tools._statusUid == uid) {
	                //    Tools.hideStatus();
	                //}
	            },
	            !options.cache
	        );
	    }
	});
	
	jQuery.fn.extend({
	    
	    serializeHash: function()
	    {
	        var hash = {};
	        $.each(this.serializeArray(), function(i, el) {
	            el.name = el.name.replace(/\[\]$/, '');
	            
	            if (typeof(hash[el.name]) == 'undefined')
	                return hash[el.name] = el.value; 
	            
	            if (!hash[el.name].push)
	                hash[el.name] = [hash[el.name]];
	            
	            hash[el.name].push(el.value);
	        });
	        return hash;
	    },
	    
	    red: function()
	    {
	        return $(this).css('border', 'red 1px solid');
	    },
	    
	    removeSlow: function()
	    {
	        return $(this).animate({ opacity: 'hide', height: 'hide' }, 'slow', null, function(){ $(this).remove(); });
	    }
	});

})(jQuery);


function setClassStyle(sheet_index, classname, class_style, style_value){
	var style_sheet=document.styleSheets[sheet_index];
	if(!style_sheet){return;}
	var sRules = style_sheet.cssRules || style_sheet.rules;
	for (var j=sRules.length-1;j>=0;j--){
		var sS=sRules[j];
		var class_name=sS.selectorText.replace(/\./g,'');
		if(class_name==classname){
			sS.style[class_style]=style_value;
			break;
		}
	}
}


function menuUp(e, index){
	var tt = e.src;
	tt = tt.replace(/\_up/g, "_dwn");
	e.src = tt;
}
function menuDown(e){
	var tt = e.src;
	tt = tt.replace(/\_dwn/g, "_up");
	e.src = tt;
}

function menuUpEn(e, index){
	var tt = e.src;
	tt = tt.replace(/\.jpg/g, "-o.jpg");
	e.src = tt;
}

var Tools = {
    
    goDropdown: function()
    {
        if(!$('#regiondropdown').val()) return;
        window.location.href = "/shop/" + $('#regiondropdown').val();
    }
}

var Catalog = {
    search: function(){
        var searchStr = $('#srct').val().replace(/[^0-9]/g, '');
        var catalog = searchStr.substr(3,2);
        catalog = '35';
        window.location.href = '/catalog/'+catalog+ '/' + searchStr + '/';
    }
}

var FAQ = {

    init: function()
    {
        $('#FAQForm').show();
        $('#loader').hide();
        $('#statusmessage').hide();
    },

    sendMessage: function()
    {
        if(FAQ.checkForm())return;
        FAQ.init();
        $('#FAQForm').hide();
        $('#loader').show();
        console.log($('#FAQForm').serialize());
        $.jsHttpRequest({
             url: '/ajax.php',
             data: $('#FAQForm').serializeHash(),
             onReady: function(result, text) {
	            if(text){
	                $('#faq_form').html("<p align=center><b>" + text + "</b></p>");
	            }
	            if(result.imageerror){
	                FAQ.init();
	                $('#statusmessage').html(result.imageerror);
	                $('#statusmessage').show();
	                return;
	            }
             }
         });         
    },

    showForm: function()
    {
       $('#faq_form').show('slow');
    },

    checkForm: function()
    {
        var errorStatus = false;
    
    	$('.activefield').each(
    	    function(x){
    	    	$(this).css('background-color', '#FFFFFF');
				if(!$(this).val()){
	                $(this).css('background-color', '#FFDDDD');
	                errorStatus = true;
	                $('#statusmessage').html('Вы не заполнили необходимые поля');
	                $('#statusmessage').show();
	            }    	        
    	    }
    	);	

        return errorStatus;
    }
}