$(document).ready(function(){

    if($("#best").length > 0) {
        var best_num = $("#scroll td").length;
        var best_current = 0;

        $("#arr_1").click(function(e){
            e.preventDefault();
            if(best_current > 0) {best_current--};
            move_best();
        });

        $("#arr_2").click(function(e){
            e.preventDefault();
            if(best_current < best_num - 2) {best_current++};
            move_best();
        });

        function move_best() {
            $("#scroll").animate({left:-305 * best_current},300,best_arrs);
        }

        function best_arrs() {
            if(best_num > 2) {
                if(best_current === 0) {
                    $("#arr_1").hide();
                    $("#arr_2").show();
                } else if(best_current === best_num - 2) {
                    $("#arr_1").show();
                    $("#arr_2").hide();
                } else {
                    $("#arr_1").show();
                    $("#arr_2").show();
                }
            } else {
                $("#arr_1").hide();
                $("#arr_2").hide();
            }
        }
        best_arrs();
    }

    // --------------------------------------------------------------------------
    // Module in Card. by IonDen. 26.08.2010

    if($("#module").length > 0) {
        var old_index = 0;
        var current_index = 0;

        function clearBG() {$("#mod_big").css("background-image","none")};
        $("#mod_big a:eq(0)").delay(1000).css("top",0).fadeIn(300,clearBG);

        $("#mod_small a").each(function(index){
            $("#mod_small a:eq("+index+")").mouseenter(function() {
                current_index = index;
                if(old_index !== current_index) {
                    $("#mod_big a:eq("+old_index+")").css("top",-1000).fadeOut(300);
                    $("#mod_big a:eq("+current_index+")").css("top",0).fadeIn(300);
                }
                old_index = index;
            });
        });

        var mod_current = 0;
        var mod_num = $("#mod_small a").length;

        $("#arr_1").click(function(e){
            e.preventDefault();
            if(mod_current > 0) {mod_current--};
            move_mod();
        });

        $("#arr_2").click(function(e){
            e.preventDefault();
            if(mod_current < mod_num - 6) {mod_current++};
            move_mod();
        });

        function move_mod() {
            $("#mod_scroll").animate({left:-90*mod_current},200,mod_arrs);
        }

        function mod_arrs() {
            if(mod_num > 6) {
                if(mod_current === 0) {
                    $("#arr_1").hide();
                    $("#arr_2").show();
                } else if(mod_current === mod_num - 6) {
                    $("#arr_1").show();
                    $("#arr_2").hide();
                } else {
                    $("#arr_1").show();
                    $("#arr_2").show();
                }
            } else {
                $("#arr_1").hide();
                $("#arr_2").hide();
            }
        }
        mod_arrs();
    }

    // --------------------------------------------------------------------------
    // Send order. by IonDen. 26.08.2010

    if($("a.send_order").length > 0) {
        $("a.send_order").click(function(e) {
            $("#popup").fadeIn(200);
            $("#p_close").click(function(e) {
                $("#popup").hide();
            });
        });
    }
});

function l( object )
{
    try
    {
        console.log( object );
    }
    catch(e)
    {
        alert( object );
    }

};
function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
};
function preg_quote( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: booeyOH
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // *     example 1: preg_quote("$40");
    // *     returns 1: '\$40'
    // *     example 2: preg_quote("*RRRING* Hello?");
    // *     returns 2: '\*RRRING\* Hello\?'
    // *     example 3: preg_quote("\\.+*?[^]$(){}=!<>|:");
    // *     returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:'

    return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
};
