var tt;
function loadPic(ele, type) {
    $(ele + " a").each(function() {
        var a = $(this); 
        var id = a.attr("href").split("_")[1].split(".")[0];
        setPic(id, a, type);
    });
}

function setPic(i, a, t) {
    $.ajax({
        url:"GetPic.aspx",
        type:"post",
        data:"id=" + i + "&type=" + t,
        timeout:3000,
        error:function() {
            a[0].id = i;
            a.parent().html("load image error,<br /><a href='javascript:' id='" + a[0].id + "'>Reload</a>");
            reloadPic(a[0].id, t);
        },
        success:function(data) {
            var align = "";
            data = data.split("|");
            var image = new Image();
            image.src = data;
            if(data[1] == "118") {
            align = "center 50%";
            } else {
             align = "center top";
            }
            $(a.find("img")[0]).css({
                "width":t == "pic" ? "157px" : "280px",
                "height":t == "pic" ? "188px" : "330px"
            });
            a.parent().attr("style", "background:url('" + data[0] + "') no-repeat " + align);
        }
    });
}

function reloadPic(id, t) {
    $.ajax({
        url:"GetPic.aspx",
        type:"post",
        data:"id=" + id + "&type=" + t,
        timeout: 3000,
        error:function() {
            $("#" + id).parent().html("load image error,<br /><a href='javascript:' onclick='reloadPic(\"" + id + "\", \"" + t + "\")' id='" + id + "'>Reload</a>");
        },
        success:function(data) {
            $("#" + id).parent().html("<a href='Product_" + id + ".html' target='_blank'><img src='" + (t == "pic" ? data.split("|")[0] : data) + "' border='0' /></a>");
        }
    });
}

function ShowPhoto(photoUrl, img) {
    new Ext.ToolTip({
        target: img.id,
        html: '<img src=' + photoUrl + ' />'
    });
}

$(function () {
    //$(".slideshow").cycle();
//    $("#divMenu").scrollFollow( {
//     speed: 1000,
//     offset: 200,
//     container: $(document)[0].body.id
//    } );
    $("#jCarouselLite").jCarouselLite({
        btnNext: "#btn1",
        btnPrev: "#btn2",
        auto: 3000,
        speed: 500,
        visible: 1
    });
} );

Ext.onReady(function() {
    var page = Ext.select('.pageText');
    if(page)
    {
        var p = Ext.query('.pageText');
        var go = Ext.select('.goBtn');
        page.on('keyup', function(e) { for(var i = 0; i < p.length; i++) { p[i].value = e.getTarget().value; } });
        go.on('click', function() { location.href = href + '_' + p[0].value + ".html"; });
    }
    var setSearchKey = new function () {
        var searchKey = Ext.fly("searchkey");
        searchKey.dom.value = "Watch Item";
        searchKey.on("focus", function () { 
            this.dom.value = "";
        });
    }
});