/* надстройка к аякс */
var ie6 = jQuery.browser.msie && (parseInt(jQuery.browser.version)==6);
var imgTop;

jQuery(document).ready(function() {
    var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand;
    try{ if(!!m) { m("BackgroundImageCache", false, true) } } catch(oh){};
});


rufoxSetHomePage = function(eto){
	eto.style.behavior='url(#default#homepage)';
	if(typeof eto.setHomePage == 'undefined') 
		document.location = "http://help.rufox.ru/14/54.html";
	else
		eto.setHomePage(location.href);
}

rufoxAddToFavorites = function(){
	if(typeof window.external.AddFavorite == 'undefined')
		document.location = "http://help.rufox.ru/14/53.html";
	else
		window.external.AddFavorite(location.href, document.title); 
}

jQuery.fn.deftext = function()
{
    return this.each(
        function()
        {
            var el = $(this);
            if (el.is("input") && el.attr("defcolor") == null)
            {
				el.attr("disabled", 0);
				el.attr("defcolor",el.css("color"));
                el.css("color","silver");
                el.attr("deftext",el.val());
                el.bind("focus",$.fn.defFocus);
                el.bind("blur",$.fn.defBlur);
                
                $("form").bind("submit",
                    function(){
                        $(":text").each(function(){
                                if ($(this).val()==$(this).attr("deftext"))
                                    $(this).val("");
                            });
                    });
            }
        });
}

jQuery.fn.defFocus = function(e)
{
    var element = e.target;
    if ($(element).attr("deftext")==$(element).val())
    {
        $(element).val("");
        $(element).css("color",$(element).attr("defcolor"));
    }
}

jQuery.fn.defBlur = function(e)
{
    var element = e.target;
    if ($(element).val()=="")
    {
        $(element).val($(element).attr("deftext"));
        $(element).css("color","silver");
    }
}

jQuery.fn.otabs = function() 
{
    return this.each(
        function()
        {
            var el = $(this);
            el.html("<span>"+el.html()+"</span>");
            el.prepend("<img class='tab_left' src='/images/common/tab_left.gif'>");
            el.append("<img class='tab_right' src='/images/common/tab_right.gif'>");
            if (!el.hasClass("active")) el.css("opacity","0.55");
        });
};

jQuery.fn.goTab = function(element)
{
    var opt = jQuery.fn.rftabs.options;
    if (!$(element).is("a")) element=$(element).parent();
    var href = $(element).attr("item");
    var h1 = $(element).parent();
    var container = $(h1).parent();
    
    $("a.tab",h1).each(function()
    {
        $(this).removeClass("active");
        $(this).css("opacity","0.55");
    });
    $(element).css("opacity", "1");
    $(element).addClass("active");
    $(opt.page, container).hide();
    $(href, container).show();
    
}


jQuery.fn.rftabs = function(options) 
{
    jQuery.fn.rftabs.options = jQuery.extend(jQuery.fn.rftabs.options, options);
    var tabidx = 0;
    var rcorners = "";
    this.each(
        function()
        {
            var opt = jQuery.fn.rftabs.options;
            var el = $(this);
            var container = el.parent();
            var tabs = opt.header.start;
            var data = "";
            $(opt.tabs, this).each(function(i)
            {
                var cl = "";
                tabidx++;
                $($(this).next()).attr("id", "tab"+tabidx);
                if($(this).hasClass("active")) cl=" active";
                var item = "<a class='tab" + cl + "' item='#tab" + tabidx+"' href='#tab" + tabidx + "'>"+opt.item.start + "<span>" + $(this).text()+ "</span>" + opt.item.end  + "</a>";
                tabs = tabs + item;
            });
            tabs += opt.header.end;
            
            $(opt.tabs, container).remove();
            container.prepend(tabs);
        });
    $("a.tab").bind("click",function(e){$.fn.goTab(e.target); return false;});
    $("a.tab.active").each(function(){$.fn.goTab(this)});
};

jQuery.fn.rftabs.options = {
    header : { start :"<h1 class='title'>", end: "</h1>"},
    tabs : "dt",
    page : "dd",
    item : { start : "", end : "" }
};

jQuery.fn.inputBackground = function() {
    $("input[bgclass]").each(function(){
        $(this).bind("focus", function(e){$(e.target).removeClass($(e.target).attr("bgclass"));});
        $(this).bind("blur", function(e){
            if ($(e.target).val()=="") $(e.target).addClass($(e.target).attr("bgclass"));
        });
    });
};

jQuery.fn.region = function(options) 
{
    return this.each(function() 
    {
        this.options = new Array();
        for(var item in jQuery.fn.region.defaults)
            this.options[item] = jQuery.fn.region.defaults[item];
        this.options = jQuery.extend(this.options, options);
        this.vars = {
            WaitTimer  : null, // Таймер ожидания выборки
            KeyTimer   : null, // Таймер повтора нажатия кнопки
            KeyRepeat  : 0,
            Regions    : null, // Список полученных регионов
            Details    : null, // Список выбранных регионов
            DoBlur     : true, // Переключатель для определения необходимости скрыть список
            SavedValue : '',
            RegionId   : this.id + "Id",
            RegionList : this.id + "List",
            ie6        : jQuery.browser.msie && (parseInt(jQuery.browser.version) < 7)
        };

        if(this.options.HideInput){
            this.front = jQuery(this.options.Front).get(0);
            if(this.front){
                this.front.input = this;
                jQuery(this.front).bind("click", function(){
                    jQuery(this).hide();
                    jQuery(this.input).show();
                    jQuery(this.input).focus();
                });
            }
        }
        jQuery(this).attr("autocomplete","off");
        
        jQuery(this).bind("keypress", jQuery.fn.region.keypress);
        jQuery(this).bind("keydown", jQuery.fn.region.keydown);
        jQuery(this).bind("keyup", jQuery.fn.region.keyup);
        jQuery(this).bind("focus", function(){
            this.vars.SavedValue = this.value;
            jQuery.fn.region.GetRegions(this);
        });
        
        jQuery(document.body).append('<div id="' + this.vars.RegionList + '" class="regionList"></div>');
        this.list  = jQuery("#" + this.vars.RegionList).get(0);
        if(this.list){
            if(this.vars.ie6){
                jQuery(document.body).append('<iframe id="iFrame' + this.vars.RegionList + '" class="regionList"></iframe>');
                this.list.frame = jQuery("#iFrame" + this.vars.RegionList).get(0);
            }
            this.list.input = this;
            jQuery(this.list).bind("mouseover", function(){
                    if(this.input.options.Debug && typeof console != 'undefined') console.log('Mouse Over on List');
                    this.input.vars.DoBlur = false; 
            });
            
            jQuery(this.list).bind("mouseout", function(){
                if(this.input.options.Debug && typeof console != 'undefined') console.log('Mouse Out from List');
                this.input.vars.DoBlur = true; 
            });
        }

        if(this.options.bluring)
        {
            jQuery(this).bind("blur", function(){
                if(jQuery(this.list).css("display") != "none" && this.vars.DoBlur)
                {
                    if(this.options.Debug && typeof console != 'undefined') console.log('Bluring from input');
                    this.value = this.vars.SavedValue;
                    jQuery.fn.region.HideList(this.list);
                }
                if(this.vars.DoBlur && this.options.HideInput) 
                {
                    jQuery(document).data("Region", this);
                    jQuery.fn.region.bluringInput();
                }
                return false;
            });
        }
        else
        {
            jQuery(this).bind("blur", function(){
                jQuery(document).data("Region", this);
                if(this.vars.DoBlur){
                    if(this.vars.ie6)
                        setTimeout('jQuery("#'+this.list.frame.id+'").hide(),jQuery("#'+this.list.id+'").hide(jQuery.fn.region.bluringInput)', 100);
                    else
                        setTimeout('jQuery("#'+this.list.id+'").hide(jQuery.fn.region.bluringInput)', 100);
                }
            });
        }

        if(this.options.CityId != '') {
            jQuery(this).after('<input type="hidden" name="' + this.options.CityId + '" id="' + this.vars.RegionId + '" value="'+this.options.DefCityId+'" />');
            this.region = jQuery('#' + this.vars.RegionId).get(0);
            this.region.input = this;
        }
        else
            this.region = false;
        
    });
}

jQuery.fn.region.bluringInput = function()
{
    var input = jQuery(document).data("Region");
    if(typeof input == "undefined") return;
    if(input.options.HideInput) 
    {
        if(input.options.Debug && typeof console != 'undefined') console.log('Hide input, show Front Panel ' + input.options.Front);
        jQuery(input).hide();
        jQuery(input.options.Front).show();
    }
    if(input.options.type == "tabbed")
    {
        jQuery(input).next("input").focus();
    }

}

jQuery.fn.region.defaults = {
    url       : "/choose_city.php?like=", // url to get
    type      : "none", // none, cookie, submit, tabbed, callback
    callback  : "", //Если type = callback, то вызывает указанную функцию
    bluring   : true, // false, true
    MinLength : 3,
    Debug     : false,
    HideInput : false,
    Front     : '', 
    CityId    : "RegionId",
    DefCityId : 0,
    MinWidth  : 200,
    Text      : "Введите первые 3 буквы названия Города",
    CanZero   : false,
    callprev  : "" // указываем функцию преобразования урла
};

jQuery.fn.region.keypress = function(event){
    switch(event.keyCode){
        case 40: // down
        case 38: // up
        case 27: // esc
        case 13: // enter
            event.keyCode = 0;
            return false;
    }
}

jQuery.fn.region.keydown = function(event)
{
    if(this.options.Debug && typeof console != 'undefined') console.log('Key downing :' + event.keyCode);
    switch(event.keyCode)
    {
        case 40: // down
        case 38: // up
            jQuery.fn.region.KeyRepeat(event.keyCode - 39);
        case 27: // esc
            event.keyCode = 0;
            return false;
        case 13:
            if(this.vars.current == 0)
            {
                event.keyCode = 0;
                return false;
            }
    }
}

jQuery.fn.region.KeyRepeat = function(iDirection)
{
    var input = jQuery(document).data("Region");
    if(input.options.Debug && typeof console != 'undefined') console.log('Key repeating, direction to :' + iDirection + '\t Current position: ' + input.vars.current);
    var item = jQuery('#city' + (input.vars.current + iDirection), input.list);
    if(item.get(0) || input.vars.current + iDirection == 0)
    {
        jQuery('div.selected', input.list).removeClass('selected');
        input.vars.current += iDirection;
        item.addClass('selected');
        if(input.vars.Details.length > 10)
        {
            if(input.vars.current < 6)
            {
                input.list.scrollTop = 0;
            }
            else
            {
                input.list.scrollTop = (input.vars.current - 5) * 14;
            }
        }
    }
    if(input.vars.KeyRepeat == 0)
    {
        input.vars.KeyRepeat = iDirection;
        interval = 500;
    }
    else
        interval = 500;

    if(input.vars.KeyTimer != null) clearTimeout(input.vars.KeyTimer); 
    input.vars.KeyTimer = setTimeout('jQuery.fn.region.KeyRepeat('+iDirection+')', interval);
}

jQuery.fn.region.keyup = function(event)
{
    if(this.options.Debug && typeof console != 'undefined') console.log('Key up :' + event.keyCode);
    switch(event.keyCode)
    {
        case 40: // down
        case 38:
            this.vars.KeyRepeat = 0;
            if(this.vars.KeyTimer != null) 
            {
                clearTimeout(this.vars.KeyTimer);
                this.vars.KeyTimer = null; 
            }
            event.keyCode = 0;
            return false;
        case 27: // esc
            this.value = this.vars.SavedValue;
            jQuery.fn.region.HideList(this.list);
            if(this.options.HideInput) 
            {
                jQuery(this).hide();
                jQuery(this.front).show();
            }
            event.keyCode = 0;
            return false;
        case 13:
            if(jQuery(this.list).css("display") != "none")
            {
                var i = (this.vars.current < 0 ? 0 : this.vars.current);
                if(this.options.CanZero && this.value.length < this.options.MinLength)
                {
                    jQuery.fn.region.ChangeRegion(this, -1, "");
                }
                else
                {
                    jQuery('#city' + i, this.list).click(); 
                    event.keyCode = 0;
                }
            }
            else
            {
                if(this.options.type == "none")
                {
                    jQuery(this).parents("form").submit();
                }
                else if(this.options.type == "tabbed")
                {
                    jQuery(this).next("input").focus();
                }
            }
            return false; 
        case 46: // delete
        case 8: // backspace
            jQuery.fn.region.TryToClear(this);
            jQuery.fn.region.GetRegions(this); 
        default:
            if(event.keyCode > 46) jQuery.fn.region.GetRegions(this);
    }
}
jQuery.fn.region.TryToClear = function(el)
{
    l = el.value.length;
    if(l < el.options.MinLength || 
          (el.vars.Regions != null && 
            el.vars.Regions.length > 0 && 
            el.vars.Regions[0].name.substr(0,el.options.MinLength).toLowerCase() 
                != el.value.substr(0,el.options.MinLength).toLowerCase()))
      el.vars.Regions = null;
}

jQuery.fn.region.GetRegions = function(element)
{
    if(this.vars) element = this;
    if(element.options.Debug && typeof console != 'undefined')
    {
        if(element.vars.Regions != null)
            console.log("element.vars.Regions - is not null : " + element.vars.Regions.length + 
                ( element.vars.Regions.length > 0 ? " '" + element.vars.Regions[0].name.substr(0, element.options.MinLength).toLowerCase() + "' ? '"
            + element.value.substr(0, element.options.MinLength).toLowerCase() + "'" : "" ) );
        else
            console.log("element.vars.Regions - is null");
    }
    if((element.vars.Regions == null || 
            element.vars.Regions.length < 1 || 
            element.vars.Regions[0].name.substr(0, element.options.MinLength).toLowerCase() 
            != 
            element.value.substr(0, element.options.MinLength).toLowerCase()) 
        && element.value.length >= element.options.MinLength) 
    {
        jQuery(document).data("Region", element);

        var url = '';
        if(typeof (element.options.callprev) == 'function') 
        {
            url = element.options.callprev() + encodeURI(element.value.substr(0, element.options.MinLength).toLowerCase());
        } else {
            url = element.options.url + encodeURI(element.value.substr(0, element.options.MinLength).toLowerCase());
        }
        
        jQuery.getJSON(url, function(response, result) {
            var element = jQuery(document).data("Region");
            if(response.length > 0)
            {
                element.vars.Details = element.vars.Regions = response; 
            }
            else
            {
                element.vars.Details = element.vars.Regions = response;  
            }
            jQuery.fn.region.ShowList(element); 
        }); 
    }
    else
    {
        jQuery.fn.region.TryToClear(element);
        jQuery.fn.region.ShowList(element); 
    }
}

jQuery.fn.region.HideList = function(list)
{
    if(list.input.options.Debug && typeof console != 'undefined') console.log('Hide list');
    jQuery('div.selected', list).removeClass('selected');
    list.input.current = -1;
    jQuery(list).hide();
    if(list.input.vars.ie6) jQuery(list.frame).hide();
}

jQuery.fn.region.ShowList = function (input)
{
    if(jQuery(input).css("display") == "none") 
    {
        jQuery(input.list).hide();
        if(list.input.vars.ie6) jQuery(input.list.frame).hide();
        return; 
    }
    var i = 0;
    if(input.value != '')
    {
        jQuery(input.list).html("");
        if(input.value.length > input.options.MinLength) 
        {
            if(input.vars.Details == null || input.vars.Details.length > 0)
                input.vars.Details = new Array();
            var i = 0;
            for(var RegionObj in input.vars.Regions) 
            {
                if(input.vars.Regions[RegionObj].name.substr(0, input.value.length).toLowerCase() == input.value.toLowerCase())
                    input.vars.Details.push(input.vars.Regions[RegionObj]); 
            } 
        }
        else 
            input.vars.Details = input.vars.Regions;
        
        input.vars.current = -1;
        for(var RegionObj in input.vars.Details)
            if(RegionObj != 'in_array') 
            {
                var cityname = input.vars.Details[RegionObj].name.substr(0, input.value.length) + "</b>" + input.vars.Details[RegionObj].name.substr(input.value.length);
                jQuery(input.list).append('<div id="city'+i+'" cityid="'+input.vars.Details[RegionObj].id+'" onclick="jQuery.fn.region.ChooseIt(this);"><b>'+cityname+'</div>');
                i ++; 
            }
    }
    if(i == 0) 
    {
        jQuery(input.list).html("");
        jQuery(input.list).height("auto");
        if (input.value.length < input.options.MinLength) 
        {
            jQuery(input.list).addClass('clear');
            jQuery(input.list).append('<div class="hint">'+input.options.Text+'.</div>'); 
        }
        else 
        {
            jQuery(input.list).addClass('clear');
            jQuery(input.list).append('<div class="error">Ничего не найдено. Повторите попытку.</div>'); 
        }
    }
    else 
    {
        jQuery(input.list).removeClass('clear'); 
        if($.browser.msie)
        jQuery(input.list).height(input.vars.Details.length < 10 ? input.vars.Details.length  * 18 : 140);
        else
        jQuery(input.list).height(input.vars.Details.length < 10 ? input.vars.Details.length  * 14 : 140);
    }
        
    var offset = jQuery(input).offset();
    var InputWidth = jQuery(input).width() + 4;
    if(input.options.MinWidth>InputWidth) InputWidth = input.options.MinWidth;
    var InputHeight = jQuery(input).height() + 4;
    jQuery(input.list).css({left: offset.left, top: (offset.top + InputHeight), width: InputWidth });
    jQuery(input.list).show();

    if(input.vars.ie6) 
    {
        jQuery(input.list.frame).css({left: offset.left, top: (offset.top + InputHeight)});
        jQuery(input.list.frame).height(jQuery(input.list).height() + 4);
        jQuery(input.list.frame).width(jQuery(input.list).width() + 4);
        jQuery(input.list.frame).show();
    }
}

jQuery.fn.region.ChangeRegion = function(input, id, text)
{
    input.value = text;
    if(input.region) input.region.value = id;
    jQuery.fn.region.HideList(input.list);
    if(input.options.type == "cookie")
    {
        jQuery(input).attr("disabled","true");
        if(input.options.HideInput) 
        {
            jQuery(input).hide();
            jQuery(input.options.Front).html(text);
            jQuery(input.options.Front).show();
        }
        jQuery.cookie('rufox_region', id, {path: '/'});
        document.location.reload(1);
    }
    else
    if(input.options.type == "submit" && jQuery(input).parents("form").length > 0) 
    {
        jQuery(input).attr("disabled","true");
        jQuery(input).parents("form").submit();
    }
    else
    if(input.options.type == "callback" && typeof (input.options.callback) != 'undefined') 
    {
        jQuery(input).attr("disabled","true");
        eval(input.options.callback+'('+id+')');
    }
}

jQuery.fn.region.ChooseIt = function(region)
{
    jQuery(region).addClass('selected');
    var id = jQuery(region).attr("cityid");
    var input = region.parentNode.input;
    var text = jQuery(region).text();
    jQuery.fn.region.ChangeRegion(input, id, text);
}

jQuery.fn.picpv = function()
{
    $().mousemove(function(e){
        try{
            jQuery.fn.picpv.data.MouseX = e.pageX + 5;
            jQuery.fn.picpv.data.MouseY = e.pageY + 5;
            $("#picpvimg").css(jQuery.fn.picpv.getXY(e));
        } catch(e) {
        }
    });
    return this.each(function(){
        var element = this;
        $(element).bind("mouseover", function(e){
            var img = document.createElement("img");
            img.id = "picpvimg";
            $(img).css(jQuery.fn.picpv.getXY(e));
            $(img).attr("src",$("img", e.target).attr("src"));
            $(img).css({display: "block", position: "absolute"});
            $("body").append(img);
        });
        $(element).bind("mouseout", function(){$("#picpvimg").remove();});
    });
};

jQuery.fn.picpv.data = {
    MouseX : 0,
    MouseY : 0
};

jQuery.fn.picpv.getXY = function(e) 
{
    XY = { left: jQuery.fn.picpv.data.MouseX, top: jQuery.fn.picpv.data.MouseY };
    maxWidth  = $(document.body).width();
    maxHeight = $(document.body).height();

    if(maxWidth < XY.left + $("img", e.target).width()) XY.left = XY.left - $("img", e.target).width();
    if(maxHeight < XY.top + $("img", e.target).height()) XY.top = XY.top - $("img", e.target).height();

    return XY;
};

$.fn.disableScreen = function(notHandlerError) {
    var div = document.createElement("div");
    div.id = "blackout";
    $(div).css("opacity", 0.5).bind("click", function(){
        $().enableScreen();
    }).attr("title", "Закрыть");
    
    if(!notHandlerError){
	    $(div).ajaxError(function(event, request, settings){
	    	$().enableScreen();
	    });
    }
    
    if(ie6) {
        var hh = $("body").height();
        var wh = $("html").height();
        var tz = (document.documentElement.scrollTop||document.body.scrollTop);
        var pp = Math.round( tz * 100 / hh + wh * 50 / hh );
        $(div).css("height", hh + "px").css("background-position", "50% "+pp+"%");
    } 
    $("body").append(div);
}

$.fn.enableScreen = function() {
    $("#blackout").remove();
    $("#popupwnd").remove();
    $("#popupwndiframe").remove();
    $.fn.popuplink.started = -1;
}

$.fn.popuplink = function( imageLoad ) {
    var i_popuplinks = 0;
    var notShowError = false;
    if(imageLoad) {
    	notShowError = true;
    }
    this.each(function() {
        this.index = i_popuplinks++;
        $.fn.popuplink.img[this.index] = this;
        $(this).bind("click", function(e) {
            if($.fn.popuplink.started < 0) {
                $.fn.popuplink.started = this.index;
                $().disableScreen(notShowError);
            }

            var div = document.createElement("div");
            div.id = "popupwnd";
            $(div).attr("index", this.index).addClass("popupwnd");
            if(ie6) {
                $(div).css({position: "absolute"});
                if($("#popupwndiframe").length == 0) {
                    var ifr = document.createElement("iframe");
                    ifr.id = "popupwndiframe";
                    $(ifr).addClass("popupwnd");
                    $("body").append(ifr);
                }
            }
            $("body").append(div);

            var href  = $(this).attr("href");
            var title = $(this).attr("title");
            
            var showBlock = function(){
                // before remove all
                $("a", div).remove();
                $("div", div).remove();
                $("img", div).css({cursor: "pointer" }).attr("title", "Закрыть").bind("click", function(e){
                    $().enableScreen();
                });
                // main picture
                img = new Image();
                img.src = $("img", div).get(0).src;
                
                var res = "res.rufox.ru";
                var j = location.host.indexOf('.rufox');
                if(j > 0) {
                    res = "res" + location.host.substr(j);
                }
                // header
                var panel    = document.createElement("div");
                $(panel).addClass("header");
                $(div).prepend(panel);
                // prev
                var previmg  = document.createElement("a");
                $(previmg).addClass("browse").attr("href", "javascript:").attr("title", "Назад").html("<img class=\"png\" width=\"40\" height=\"27\" border=\"0\" src=\"http://"+res+"/img/button_prev.png\"/>").click(function(e){
                    next = Math.round($(div).attr("index")) - 1;
                    if(next < 0) next = $().popuplink.img.length - 1;

                    wait = document.createElement("div");
                    $(wait).addClass("waiting").css("height", $(div).height());
                    $(div).append(wait).attr("id", "_popupwnd").append(wait);
                    $($().popuplink.img[next]).click();
                });
                $(panel).append(previmg);
                // next
                var nextimg  = document.createElement("a");
                $(nextimg).addClass("browse").attr("href", "javascript:").attr("title", "Вперед").html("<img class=\"png\" width=\"40\" height=\"27\" border=\"0\" src=\"http://"+res+"/img/button_next.png\"/>").click(function(e){
                    next = Math.round($(div).attr("index")) + 1;
                    if(next >= $().popuplink.img.length) next = 0;
                    wait = document.createElement("div");
                    $(wait).addClass("waiting").css("height", $(div).height());
                    $(div).append(wait).attr("id", "_popupwnd").append(wait);
                    $($().popuplink.img[next]).click();
                });
                $(panel).append(nextimg);
                // label
                var labelimg = document.createElement("span");
                $(labelimg).addClass("title").text("фотография " + (Math.round($(div).attr("index")) + 1) + " из " + $().popuplink.img.length);
                $(panel).append(labelimg);
                // close
                var closelink = document.createElement("a");
                $(closelink).addClass("close").attr("href", "javascript:").text("закрыть").bind("click", function(e){
                    $().enableScreen();
                });
                $(panel).append(closelink);

                if(img.width==0) {
                    img.onload = $().popuplink.onload;
                } else {
                    $().popuplink.onload();
                }
                var p = document.createElement("p");
                $(p).html(title);
                $(div).append(p);
            };
            
            if(imageLoad) {
            	$(div).append("<img src='"+href+"'>");
            	showBlock();
            }else{
            	$(div).load(href, showBlock);
            }
            	
            return false;
        });
    });
};

$.fn.popuplink.onload = function(){
    posLeft = Math.round(($(window).width() - img.width)/2) + 20;
    posTop = document.getElementsByTagName('html')[0].clientHeight;
    posTop = Math.round((posTop - img.height)/2) - 20; 
    if(posLeft<20) posLeft = 20;
    if(posTop<10) posTop = 10;
    if(ie6) {
        posTop += (document.documentElement.scrollTop||document.body.scrollTop);
        $("#popupwndiframe").css({ top: posTop+"px", left: posLeft+"px", width: img.width });
    }
    $("#popupwnd").css({ top: posTop+"px", left: posLeft+"px", width: img.width });
    if(ie6) {
        var h = $("#popupwnd").height();
        $("#popupwndiframe").height(h);
    }
    $("#blackout").css({ cursor: "pointer" });
    $("#_popupwnd").remove();
};

$.fn.popuplink.img = new Array();
$.fn.popuplink.started = -1;

open_win_img = function(images_src, width, height, title){
	if(width > (screen.width - 100)){
		width = screen.width - 100;
	}
	if(height > (screen.height - 100)){
		height = screen.height - 100;
	}
	wtop = (screen.height-height)/2;
	wleft = (screen.width-width)/2;
	if(!title || title === ''){
		title = "Изображение в полный размер";
	}
	image_window = window.open('', 'image', 'top='+ wtop +', left='+ wleft +', height='+height+', width='+width+',resizable=no,personalbar=no,menubar=no,titlebar=no,status=no');
	image_window.document.write("<html><head><title>" + title + "</title></head>");
	image_window.document.write("<body style='margin:0; padding: 0;'><img src='" + images_src + "'></body></html>");
	image_window.document.close();
}

complaintUser = function(userid, domain, projectid, url){
	window.open('http://my.'+domain+'/complaint/?userid='+userid+'&url='+url+'&projectid='+projectid+'&rand='+Math.random(),'new_win','width=500,height=300,resizable=1,toolbar=0,location=0,status=0,menubar=0,directories=0,scrollbars=yes,top=0,left=0');
}


//Begin / Проверка версии flash-плеера
var versionFlash = 0;
var minVerFlash = 8;

if(navigator.userAgent.toLowerCase().indexOf("ie") == -1){
	var ver = "";
	for(i=0; i < navigator.plugins.length; i++){
		if( navigator.plugins[i].description.indexOf("Shockwave Flash") != -1){
			ver = navigator.plugins[i].description.replace(navigator.plugins[i].name,"");
			ver = parseInt(ver.slice(0, ver.indexOf(".")));
			if(ver >= minVerFlash){
				versionFlash = ver;
			}
			break;
		}
	}
}else{
	for (var i=20; i >= minVerFlash; i--){
		try {
			new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
			versionFlash = i;
			break;
		} catch (e) {
		}
	}
}
//End / Проверка версии flash-плеера