﻿//preload
var imgs = new Array();
var x = 0;
function preloading() {
    for (x = 0; x < preloading.arguments.length; x++) {
        imgs[x] = new Image();
        imgs[x].src = preloading.arguments[x];
    }
}

preloading("/Content/img/balls/k1.jpg", "/Content/img/balls/k1h.jpg", "/Content/img/balls/k2.jpg",
    "/Content/img/balls/k2h.jpg", "/Content/img/balls/k3.jpg", "/Content/img/balls/k3h.jpg", "/Content/img/balls/k4.jpg",
    "/Content/img/balls/k4h.jpg");



$(document).ready(function() {

    $("#topMenu ul li").last().css('border', 'none');
    /* banner */
    var fo = new SWFObject("/_data/banner/banner.swf", "banner", "795", "130", "9", "#FFFFFF");
    fo.addParam("wmode", "opaque");
    fo.addParam("bgcolor", "#666666");
    fo.write("topBanner");


    /* balls */

    $("#k1").hover(function() { $(this).attr('src', '/Content/img/balls/k1h.jpg'); },
                   function() { $(this).attr('src', '/Content/img/balls/k1.jpg'); });
    $("#k2").hover(function() { $(this).attr('src', '/Content/img/balls/k2h.jpg'); },
                   function() { $(this).attr('src', '/Content/img/balls/k2.jpg'); });
    $("#k3").hover(function() { $(this).attr('src', '/Content/img/balls/k3h.jpg'); },
                   function() { $(this).attr('src', '/Content/img/balls/k3.jpg'); });



    $("#btnFilter").click(
        function() {
            $("#um").val($("#models").val());
            $("#frmFilter").submit();
        });

    $("#btnFilterOff").click(
        function() {
            $("#um").val(0);
            $("#man").val(0);
            $("#search").val();
            $("#frmFilter").submit();
        });


    /* topMenu */
    $("#topMenu ul li").hover(
        function() {
            $(this).addClass('hover');
        },
        function() {
            $(this).removeClass('hover');
        }
    );
    $("#topMenu ul li").click(
        function() {
            window.location = $(this).find("a").attr("href");
            return false;
        });

    initCategories();
    $(".products .title").vAlign();
    $(".categoryImage .title").vAlign();
    $(".categoryImage .image").vAlign();

    $("#productFilter").corner("10px");


    $("#shoppingCart").droppable({
        drop: function(e, ui) {
            var param = $(ui.draggable).find("input:hidden").get(0).value;
            $("#shoppingCart").getContent("/Ajax/setshoppingCart?i=" + param, "ajax_orange.gif");
        }
    });


    if ($("#models_man").length > 0) {
        if ($("#models_man")[0].value == "")
            $("#models").attr('disabled', true);
    }


    $("#models").change(function() {

        var val = $("#models").attr("value");
        $("#userMotorcycle").getContent("/Ajax/setUserMotorcycle/" + val, "ajax.gif");
    });

    $("#models_man").change(function() {
        strManufacturer = $(this)[0].value;
        if (strManufacturer == "") {
            $("#models").attr('disabled', true);
            //  $("#userMotorcycle").getContent("/Ajax/setUserMotorcycle/0", "ajax.gif");
            $("#models").empty();
            $("#models").append('<option value="0">Wybierz model</option>');
        }
        else {
            $("#models").attr('disabled', true);
            //$("#userMotorcycle img").attr('src', '/Content/img/ajax.gif');
            $ret = "";
            $.ajax({
                type: "GET",
                url: "/AJAX/getUserMotorcycleID",
                success: function(ret) {
                    $ret = ret;
                }
            });

            $.getJSON("/Ajax/getModels/" + strManufacturer, null, function(data) {
                $("#models").empty();
                $("#models").append('<option value="0">Wybierz model</option>');
                $.each(data, function(index, optionData) {
                    $str = '<option ';
                    if ($ret == optionData.Id) {
                        $str += 'selected="selected " ';
                        $("#userMotorcycle").getContent("/Ajax/setUserMotorcycle/" + optionData.Id, "ajax.gif");
                    }
                    $str += 'value="' + optionData.Id + '">' + optionData.name;
                    $str += "</option>";
                    $("#models").append($str);

                });
                $("#models").show();
                $("#models").removeAttr('disabled');

                $("#shoppingCart").droppable({
                    drop: function(e, ui) {

                        var param = $(ui.draggable).find("input:hidden").get(0).value;
                        $("#shoppingCart").getContent("/Ajax/setshoppingCart?i=" + param, "ajax_orange.gif");
                    }
                });


            });
        }
    });


});

