function this_input(elem, text, focus) {
	if(focus) {
		if($(elem).val()==text) {
			$(elem).val('');
		}
	} else {
		if($(elem).val()=='') {
			$(elem).val(text);
		}
	}
}

$(document).ready(function() {
    $('#subscribe-input').click(function(txt){
        this_input(this, 'Адрес эл. почты', true);
    });
    $('#subscribe-input').blur(function(txt){
        this_input(this, 'Адрес эл. почты', false);
    });
    $('.mg').click(function(){
        $(this).children('ul').toggle();
        if ($(this).children('ul').css('display')!='none'){
            $(this).addClass('active');
            $(this).css('font-weight', 'normal');
        }else{
            $(this).removeClass('active');
        }
    });
    $('.itemb .photo .thumbs .mipic').unbind('click').click(function() {
        $('.itemb .photo .thumbs .active').removeClass('active');
        var src = $(this).parent('a').attr('href');
        var href = $(this).parent('a').attr('id');
        $('.mapic').attr('src', src).parent('a').attr('href', href);
        $(this).addClass('active');
        return false;
    });
});

function strpos( haystack, needle, offset){
    // Find position of first occurrence of a string
    // Original by: Kevin van Zonneveld [kevin.vanzonneveld.net]
    var i = haystack.indexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
}

function str_rpos(haystack, needle, offset) {
    // Created by Igor Ermolaev [webrica.org]
    // Find position of last occurrence of a string
    // Example. Return 8
    // str_rpos('Bla-bla-bla...', 'b', 0);
    // Example. Return null
    // str_rpos('Bla-bla-bla...', 'w', 0);
    if (offset==0)
        offset = haystack.length;
    while (offset>0){
        var index = haystack.indexOf(needle, offset);
        if (index != -1)
            return index;
        --offset;
    }
    return -1;
}

function isInt(x) {
    var y=parseInt(x);
    if (isNaN(y)) return false;
    return x==y && x.toString()==y.toString();
}
