﻿/*
==============================
    OTHER RUGS WEBSERVICE
==============================
Created: August 2009

Description:

*/
var otherRugs_XMLDoc;
var otherRugs_XMLNodeList;
var otherRugs_Count = 0;
var otherRugs_Images = new Array();
var otherRugs_PreLoadImagesTimerID;
var otherRugs_ContentPane;
var otherRugs_RugPerPage = 0;
var otherRugs_CurrentRug = 0;

$(document).ready(function(){
    //Set some values
    otherRugs_ContentPane = "otherRugsContent";
    otherRugs_CurrentRug = 0;
    otherRugs_Images = new Array();
    otherRugs_RugPerPage = (getPageElement("ctl00_ContentPlaceHolder1_OtherRugs_Count")) ? getPageElement("ctl00_ContentPlaceHolder1_OtherRugs_Count").value : 4;
    
    //Get other rugs webservice request
    var rugsCategory = "Other";
    var rugsPerCategory = 92;
    eCarpetGallery.UI.ProductsWebService.GetOtherRugs(rugsCategory, rugsPerCategory, OtherRugs_OnGetMoreServiceCallComplete, OtherRugs_OnGetMoreServiceCallTimeOut, OtherRugs_OnGetMoreServiceCallError);    
});
    
function OtherRugs_OnGetMoreServiceCallComplete(args)
{
    otherRugs_XMLDoc = XMLparse(args);
    otherRugs_XMLNodeList = otherRugs_XMLDoc.getElementsByTagName("rug");
    otherRugs_Count = otherRugs_XMLDoc.getElementsByTagName("rug").length;    
    setInterval("OtherRugs_GetMore()", 12000);
}

function OtherRugs_GetMore()
{
    //Start Preparing output
    var otherRugs_Output = "";
    for (var counter = 0; counter < otherRugs_RugPerPage; counter++)
    {
        //Go through the rugs
        otherRugs_CurrentRug = otherRugs_CurrentRug + 1;
        if ( otherRugs_CurrentRug >= otherRugs_Count ) otherRugs_CurrentRug=0;
        
        //Get rug values
        var otherRugXML = otherRugs_XMLNodeList[otherRugs_CurrentRug];
        var otherRug_ID = otherRugXML.getElementsByTagName("item_id")[0].childNodes[0].nodeValue;
        var otherRug_Title = otherRugXML.getElementsByTagName("title")[0].childNodes[0].nodeValue;
        var otherRug_FileName = otherRugXML.getElementsByTagName("filename")[0].childNodes[0].nodeValue;;
        var otherRug_StatusID = otherRugXML.getElementsByTagName("status_id")[0].childNodes[0].nodeValue;;
        var otherRug_Price = otherRugXML.getElementsByTagName("price")[0].childNodes[0].nodeValue;;
        var otherRug_ManualPrice = otherRugXML.getElementsByTagName("man_price")[0].childNodes[0].nodeValue;
        
        //Add to output
        otherRugs_Output += OtherRugs_GetRugOutput(otherRug_ID, otherRug_Title, otherRug_FileName, otherRug_StatusID, otherRug_Price, otherRug_ManualPrice);
    }
    OtherRugs_DisplayNextBatch(otherRugs_Output);
}

function OtherRugs_DisplayNextBatch(otherRugs_Output)
{
    var elementsToFade = "#" + otherRugs_ContentPane + " img.picture, #" + otherRugs_ContentPane + " img.addToCartBig, #" + otherRugs_ContentPane + " img.cornerSticker, #" + otherRugs_ContentPane + " div.title, #" + otherRugs_ContentPane + " div.price, #" + otherRugs_ContentPane + " div.id";    
    var elementsToFadeCount = otherRugs_RugPerPage * 5;
    var elementsFaded = 0;
    $(elementsToFade).fadeOut("slow", function() {
        elementsFaded++;
        if (elementsFaded==elementsToFadeCount)
        {
            $("#" + otherRugs_ContentPane).html(otherRugs_Output);
            $(elementsToFade).fadeOut(0);
            $(elementsToFade).fadeIn("slow");
            elementsFaded=0;
        }
    }); 
}

function OtherRugs_GetRugOutput(id, title, fileName, statusId, price, manualPrice)
{
    var output = "";
    
    output += "<div class=\"otherRug\">";
    output += "<a class=\"specifics\" href=\"http://www.ecarpetgallery.com/Area-Rugs/" + fileName + "\">";
    if (statusId==29)
        output += "<img class=\"cornerSticker\" src=\"http://www.ecarpetgallery.com/App_Themes/Peyman/Images/Sale-small.gif\" alt=\"Rugs Under 100$\" />";
    else if (statusId==30)
        output += "<img class=\"cornerSticker\" src=\"http://www.ecarpetgallery.com/App_Themes/Peyman/Images/Sale-small.gif\" alt=\"Sale\" />"; 
    output += "<img class=\"picture\" src=\"https://www.ecarpetgallery.com/Thumbnail.aspx?id=" + id + "&amp;width=100\" alt=\"" + title + "\" />";
    output += "<div class=\"id\">" + id + "</div>";
    output += "<div class=\"title\">" + title + "</div>";
    output += "</a>";
    output += "<div class=\"price\" style=\"color: #990000; margin-top: 15px\">";
    if (manualPrice>0)
        output += formatCurrency(manualPrice);
    else
        output += formatCurrency(price);
    output += "</div>";
    output += "<img class=\"addToCartBig\" src=\"https://www.ecarpetgallery.com/App_Themes/Peyman/Images/Buttons/Add-to-Cart.gif\" onclick=\"javascript:AddToCart(" + id + "); return false\" />";
    output += "</div>";
    return output;
}

function OtherRugs_OnGetMoreServiceCallTimeOut(args) {
    //do nothing, just don' t change the rugs
}

function OtherRugs_OnGetMoreServiceCallError(args) {
    //do nothing, just don' t change the rugs
}


