$(document).ready(function(){

   // $('img').parent().append('<div style="z-index:13; position:absolute;">Новый элемент</div>');


   $('.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');
    });

    //$('.round').corner();

/*
    $.each($('.jwf'),function(){
        atr=$(this).attr('class');
        arc=atr.split(' ');

        alert(arc[1])
    });
*/
    $('.numeric').live('keyup', function(){
        val=$(this).val();
        val=parseInt(val.replace(/[^0-9]/g,''));
        if(!val) val=0;
        $(this).val(val);
    })


  });

$(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(){
	
	$('.time').bind('click',function(){
		$(this).select();
	});
		
	$('.time').bind('keyup',function(){
		val=$(this).val().replace(/[^0-9:]/g,'');	
		if(!val) {
			$(this).val('');
			return true;
		}
		res='';
		dt=false;
		m=val.split(':');
		res=m[0];
		if(m[0]!='') {
			if(m[0]!='00') m[0]=parseInt(m[0]);
			if(m[0]>23) m[0]='00'

			if((''+m[0]).length>1) 	{
				res=m[0]+':';
				dt=true;
			}	
		}
		if(isset(m[1])  && m[1]) {
	   	    m[1]=parseInt(m[1]);
			if(m[1]==0 || m[1]>59) {
	   			m[1]='00';
	   		}
	   		if(dt) res+=m[1];
	   		else res+=':'+m[1];
	   }
	   	   
	   $(this).val(res);
		return true;

	});

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

	$('.spoiler-title').bind('click', function(){
				if($(this).parent().find('*').size()==1) body=$(this).parent().next();
                else body=$(this).next();
                
                for(i=0;i<5;i++) {
                    if(body.is('".spoiler-body"')) break;
                    body=body.next();
                }
				
		if(body.is(':hidden')) {
			body.fadeIn(300);
		} else {
			body.fadeOut(300);
		}
	});
});




