$(document).ready(function(){


   $('.hover').hover(
    function () {
        $(this).css('background-position','0 -'+parseInt($(this).css('width'))+'px');

    },
    function () {
        $(this).css('background-position','0px 0px');
    });

    $('.hover24').hover(

    function () {
        $(this).css('background-position','0 -24px');
        
    },
    function () {
        $(this).css('background-position','0px 0px');
    });


    $('.numeric').live('keyup', function(){
        val=$(this).val();
        val=conv_numeric(val)
        $(this).val(val);
    })



        $('.mainmenu li a').hover(
        function () {
            //$(this).parents('.mainmenu').find('li').removeClass('onmouse');
            $(this).parents('li').addClass('onmouse');
        },
        function () {
            $(this).parents('li').removeClass('onmouse');
        });


});



$(document).ajaxComplete(function(){
    $('.hover24').hover(
    function () {
        $(this).css('background-position','0 -24px');

    },
    function () {
        $(this).css('background-position','0px 0px');
    });

});

window.isset = function (){
	 if (arguments.length===0) return false;
	 var buff=arguments[0];
	 for (var i=0; i<arguments.length; i++){
	  if (typeof(buff)==='undefined') return false;
	  buff = buff[arguments[i+1]];
	 }
	 return true;
	}


$.extend($.expr[":"], {
    "containsFind": function(elem, i, match, array) {
        return (elem.textContent || elem.innerText || "").toLowerCase
().indexOf((match[3] || "").toLowerCase()) >= 0;
    }
});

$(document).ajaxComplete(function(){



$('.selectfinder').bind('keyup',function(){

    token=$(this).val();
    match=$(this).attr('name').match(/\[(.*?)\]/);
    if(!match) return;
    select_id=match[1];
    select=$('select#'+select_id);

    select.css('border','1px solid #555');
    select.css('height', ($("select#"+select_id).height()+2)+'px');
    


    if(token!='') {
    res= $("select#"+select_id+" > option:containsFind(" + token + ")");
    if( res.size() == 0 ) {
        $("select#"+select_id+" > option:first").attr("selected", "selected");
        $("select#"+select_id).css('background-color','#f99');
    } else {
        $("select#"+select_id).css('background-color','#fff');
    }

       $("select#"+select_id+" > option").css('background-color','#eee').css('color','#ccc');
       res.css('background-color','#fff').css('color','#000');
       $("select#"+select_id+" > option:containsFind(" + token + "):first").attr("selected", "selected");
        $(this).css({'border':'1px solid #498'});
    } else {
        $("select#"+select_id).css('background-color','#fff');
        $("select#"+select_id+" > option").css('background-color','#fff');
        $("select#"+select_id+" > option:first").attr("selected", "selected");
        $("select#"+select_id+" > option").attr('style','');
         $(this).css({'border':'1px solid #000'});
    }


});
});

var userAgent = navigator.userAgent.toLowerCase();
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	chrome: /chrome/.test( userAgent ),
	safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
//input[name='имя']

function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
        // Alternatively you could use:
        // (new Image()).src = this;
    });
} 


function strip_quote( str ){
    str=str.replace(/(\n|\r)/gi, '');
    return strip_tags(str.replace(/<div.*?\/div>/gi, ''));
}

function strip_tags (string) { 
 return string.replace(/<\/?[^>]+>/gi, '');
}



function print_r(arr, level) {
    var print_red_text = "";
    if(!level) level = 0;
    var level_padding = "";
    for(var j=0; j<level+1; j++) level_padding += "    ";
    if(typeof(arr) == 'object') {
        for(var item in arr) {
            var value = arr[item];
            if(typeof(value) == 'object') {
                print_red_text += level_padding + "'" + item + "' :\n";
                print_red_text += print_r(value,level+1);
		}
            else
                print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
        }
    }

    else  print_red_text = "===>"+arr+"<===("+typeof(arr)+")";
    return print_red_text;
}

 function in_array(what, where) {
    for(var i=0; i<where.length; i++)
        if(what == where[i])
            return true;
    return false;
}


$(document).ready(function(){


    $('.spoiler-title').hover(
    function () {
        $(this).addClass('spoiler-title-active');
    },
    function () {
        $(this).removeClass('spoiler-title-active');
    });

	$('.spoiler-title').bind('click', function(){
                body=$(this);
                for(i=0;i<5;i++) {
                    body=body.next();
                    if(body.is('".spoiler-body"')) break;
                }

		if(body.is(':hidden')) {
			body.fadeIn(300);
		} else {
			body.fadeOut(300);
		}
	});
});



function conv_numeric(val) {
     val=parseInt(val.replace(/[^0-9]/g,''));
     if(!val) val=0;
     return val;
}
