﻿var url = 'includes/isstaXMLData.xml';
//var url = 'data.xml';
function parseRssFeed() {
    //clear the content in the div for the next feed.
    $("#feedContent").empty();

    //use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
    $.get(url, function(d) {

        //find each 'item' in the file and parse it
        $(d).find('Deals').each(function(i, elem) {

            //name the current found item this for this particular loop run
            var $item = $(this);
            // grab the post title
            var title = $item.find('title').text();
            // grab the post's URL
            var link = $item.find('url').text();
            // next, the description
            var description = $item.find('description1').text();
            //don't forget the pubdate
            var pubDate = $item.find('product_todate').text();
            var image = $item.find('image').text();
            var linkJson = {
                title: title,
                description1: $item.find('description1').text(),
                description2: $item.find('description2').text(),
                image: image,
                url: link,
                price_prefix: $item.find('price_prefix').text(),
                price_currency: $item.find('price_currency').text(),
                price_actual: $item.find('price_actual').text(),
                product_fromdate: $item.find('product_fromdate').text(),
                product_todate: $item.find('product_todate').text(),
                final_price: $item.find('price_prefix').text() + '-' + $item.find('price_currency').text() + $item.find('price_actual').text()
            }


            var a = '<a title="' + linkJson.description1 + '" href="' + link + '" target="_blank">';
            a += '<img alt="' + title + ' - ' + linkJson.description1 + '" title="' + title + ' - ' + linkJson.description1 + '" index="' + i + '" border="0" align="absmiddle" src="' + image + '" />';
            a += '<span>' + title + '<br><strong>' + linkJson.final_price + '</strong><Br>יציאה: ' + linkJson.product_fromdate + '</span>';
            a += '</a>';

            // now create a var 'html' to store the markup we're using to output the feed to the browser window
            var list = new String();
            list += '<li></li>';

            var linkObj = $(a);
            linkObj.linkJson = linkJson;

            //put that feed content on the screen!
            $('#feedContent').append($(list).append(linkObj));

            linkObj.click(function() {
                var jObj = linkObj.linkJson;
                $('.promotion-popup-panel .header strong').text(jObj.title);
                var price = jObj.final_price;
                $('.promotion-popup-panel .header span').text(price)
                $('.promotion-popup-panel .body .title span').text(jObj.description1)
                $('.promotion-popup-panel .body .content .img').empty();
                $('.promotion-popup-panel .body .content .img').append('<img src="' + jObj.image + '" width="100%" height="100%"/>')
                $('.promotion-popup-panel .body .content .text span em').text(jObj.description2);
                $('.promotion-popup-panel .body .content .text a').attr('href', jObj.url + "&wsId=Rrdsc97VAMmdTuc_YtfFcyYm2ZdcekC_TsRrdsc97VAMmdTuctS");
                
                $('.promotion-popup-panel .body .content .text a').attr('title', 'לחץ לקבלת פרטים נוספים והזמנה');
                $('.promotion-popup-panel .body .content .text a').attr('target', '_blank');
                
                $('.promotion-popup-panel .footer .out em').text(jObj.product_fromdate)
                $('.promotion-popup-panel .footer .in em').text(jObj.product_todate)
                //alert(linkObj.linkJson.image);
                return false;
            });

        });

        $('#promotionDialog').jqm({
            trigger: "#feedContent a",
            onShow: promotionDialogOpen
        });

        function promotionDialogOpen(sender) {
            var offsetLeft = $('.body .content .player').offset().left + "px";
            $('.promotion-popup-panel').css({ position: "absolute", top: "135px", left: offsetLeft });
            sender.w.show();
        }

        autoSCroll = 8000;
        jCarouselLiteObj = $("#promotionsFeedContetnt").jCarouselLite({
            vertical: false,
            scroll: 5,
            auto: autoSCroll,
            visible: 5,
            speed: 1000,
            btnNext: ".pr-thePrev",
            btnPrev: ".pr-theNext"
        });
    });
};