jQuery(function($) {
    var categoryName = $("xml").find("categoryname").text();
    var sarray = new Array();
    sarray = categoryName.split('>');

    $("#divCategoryName").text('Other Models');
    $("#divCategoryNameUP").text(categoryName);
    $("xml").find("product").each(function(i) {
        var product = $(this);
		var modeNum = $(this).find("modenum").text();
        var fullProductName = $(this).find("productname").text();
		var productName = fullProductName.substring(0,fullProductName.indexOf('&'));
        var image = $(product).find("installationimage")[0];
        var smallimageurl = '../images/small/' + $.trim($(image).text()) + '.gif'
        var html = '<div class="small_txt"><img class="smallImage" index="' + i + '" src="../js/' + smallimageurl + '" />'+'<div class="s_img">'+productName+'<span class="modenum">'+modeNum+'</span>'+'</div>'+'</div>'
        $("#divSmall").append(html);
    });
    $(".smallImage").click(function() {
        LoadProductInfo($(this).attr("index"));
        $(".smallImage").removeClass("dn");
        $(this).addClass("dn");
    });
    $(".smallImage").hover(function() {
        $(this).addClass("dd");
    }, function() {
        $(this).removeClass("dd");
    });

    LoadProductInfo(0);
    $(".smallImage:first").addClass("dn");

    function LoadProductInfo(ProductIndex) {
        LoadInstallationInfo(ProductIndex, 0)
        var product = $("xml").find("product")[ProductIndex];
        var productTitle = $(product).find("producttitle").text();
        var productName = $(product).find("productname").text();
		var comingSoon = $(product).find("comingsoon").text();
		var inter = $(product).find("inter").text();
		var remark = $(product).find("remark").text();
		var modeNum = $(product).find("modenum").text();
        var productDescription = $(product).find("productdescription").text();
        var Specifications = $(product).find("specifications").text();
        var Print = $(product).find("print").text();
        var Instructions = $(product).find("instructions").text();
        $("#divProductTitle").html(productTitle);
		$("#divComingSoon").html(comingSoon);
		$("#divInter").html(inter);
		$("#divRemark").html(remark);
<!--		$("#divModeNum").html(modeNum);-->
        $("#divProductName").html(productName);
        $("#divProductDescription").html(productDescription);
        $("#linkSpecifications").attr("href", Specifications);
        $("#linkPrint").attr("href", Print);
		if(Instructions == ''){
				$("#linkInstructions").attr("style", "cursor:text; color:#D4421D"); 
				$("#linkInstructions").attr("href", "#");
				$("#linkInstructions").attr("target", "_self");
			}else
			{
				$("#linkInstructions").attr("style", ""); 
        		$("#linkInstructions").attr("href", Instructions);
				$("#linkInstructions").attr("target", "_blank");
			}

        
        $("#divInstallation").empty();
        $(product).find("installationimage").each(function(i) {
            var installationimage = $(this);
            var smallimageurl = '../images/small/' + $.trim($(installationimage).text()) + '.gif'
            var html = '<img class="installationImage" index="' + i + '" src="../js/' + smallimageurl + '" />'
            $("#divInstallation").append(html);
        });
        $(".installationImage").click(function() {
            LoadInstallationInfo(ProductIndex, $(this).attr("index"));
            $(".installationImage").removeClass("dn");
            $(this).addClass("dn");
        });
        $(".installationImage").hover(function() {
            $(this).addClass("dd");
        }, function() {
            $(this).removeClass("dd");
        });
        $(".installationImage:first").addClass("dn");
    }

    function LoadInstallationInfo(ProductIndex, InstallationIndex) {
        var _product = $("xml").find("product")[ProductIndex];
        var _bigImage = $(_product).find("installationimage")[InstallationIndex];
        var bigimageurl = '../images/big/' + $(_bigImage).text() + '.jpg';
        $("#bigImage").attr({ src: bigimageurl });
        var installationDescription = $(_product).find("installationdescription")[InstallationIndex];
        $("#divInstallationDescription").html($(installationDescription).text());
        $(".onload").hide();
    }
});
