﻿//Find Query String Params
var urlQueryParam = self.location.search;

//POV
/*var flashvars = {};
flashvars.name = "pID=02_SCB_10872_InClubsNow&rootDir=InClubsNow";

var params = {};
params.quality = "high";
params.wmode = "opaque";
params.allowScriptAccess = "always";

var attributes = {};
attributes.id = "icnPOV";
attributes.name = "icnPOV";

swfobject.embedSWF("/Global/flash/InClubsNow_POV.swf", "pov", "710", "270", "9.0.0", "expressInstall.swf", flashvars, params, attributes);*/

//Now Playing - Video
/*var params = {};
params.quality = "high";
params.wmode = "transparent";

var attributes = {};
attributes.id = "icnVid";
attributes.name = "icnVid";

swfobject.embedSWF("/inclubsnow/Media/flash/InClubsNow_VID.swf", "icnVideo", "400", "219", "9.0.0", "expressInstall.swf", params, attributes);
*/

//Article AJAX Call
function ajaxCall() {
    //Articles
    $.ajax({
        type: "GET",
        url: "/InClubsNow/Media/xml/icnArticles.xml",
        dataType: "xml",
        success: function (xml) {

            var findArticle = $(xml).find('Articles');
            findArticle.children().each(function (i) {

                var articleSourceLoc = $(xml).find('Source').eq(i).text();
                var articleSourceLinkLoc = $(xml).find('SourceLink').eq(i).text();
                var articleHeadlineLoc = $(xml).find('Headline').eq(i).text();
                var articleCopyLoc = $(xml).find('Copy').eq(i).text();
                var articleReadOnCTALoc = $(xml).find('CTA').eq(i).text();
                var articleReadOnLinkLoc = $(xml).find('ArticleLink').eq(i).text();
                var articleSourceTag = $(xml).find('OmnitureSourceTag').eq(i).text();
                var articleTag = $(xml).find('OmnitureArticleTag').eq(i).text();

                var articleHolder = $('div.articleBlock');
                articleHolder.eq(i).append('<h1><a></a></h1><h2><a></a></h2><p><a></a></p><a class="readOn"></a>');

                var articleSource = $('div.articleBlock h1 a');
                var articleHeadline = $('div.articleBlock h2 a');
                var articleCopy = $('div.articleBlock p');
                var articleReadOn = $('div.articleBlock a.readOn');

                articleSource.eq(i).text(articleSourceLoc);
                articleSource.eq(i).click(function () {
                    Omniture_TrackInternalLink(articleSourceTag);
                });
                articleSource.eq(i).attr('href', articleSourceLinkLoc);

                articleHeadline.eq(i).text(articleHeadlineLoc);
                articleHeadline.eq(i).click(function () {
                    Omniture_TrackInternalLink(articleTag);
                });
                articleHeadline.eq(i).attr('href', articleReadOnLinkLoc);
                articleCopy.eq(i).text(articleCopyLoc);

                articleReadOn.eq(i).text(articleReadOnCTALoc);
                articleReadOn.eq(i).click(function () {
                    Omniture_TrackInternalLink(articleTag);
                });
                articleReadOn.eq(i).attr('href', articleReadOnLinkLoc);

            });

        }
    });

    //Find pPhoto Height
    $.ajax({
        type: "GET",
        url: "/InClubsNow/Media/xml/productSpotlight.xml",
        dataType: "xml",
        success: function (xml) {

            var findProduct = $(xml).find('Product');
            findProduct.each(function (i) {

                // if (i == 1) {
                var domSeeAllProds = $('a.prodSeeAllLink');
                if (urlQueryParam.length) {
                    domSeeAllProds.attr('href', '/InClubsNow/seeallbrands.html' + urlQueryParam + '?iframe=true&width=710&height=' + (i + 5) * 23);
                } else {
                    domSeeAllProds.attr('href', '/InClubsNow/seeallbrands.html?iframe=true&width=710&height=' + (i + 5) * 23);
                }
                //} 
            });
        }
    });

    //Featured Partners
    $.ajax({
        type: "GET",
        url: "/InClubsNow/Media/xml/featuredPartners.xml",
        dataType: "xml",
        success: function (xml) {

            var findPartner = $(xml).find('Partner');
            findPartner.each(function (i) {

                var partnerNameLoc = $(xml).find('Name').eq(i).text();
                var partnerImageLoc = $(xml).find('ImagePath').eq(i).text();
                var partnerLinkLoc = $(xml).find('LinkPath').eq(i).text();
                var omnitureTagLoc = $(xml).find('OmnitureTag').eq(i).text();

                var featPartnerSrc = $('div.featuredPartners ul');
                featPartnerSrc.append('<li><a><img width="142" height="77" /></a></li>');

                featPartnerSrc.children('li').children('a').eq(i).attr('href', partnerLinkLoc);
                featPartnerSrc.children('li').children('a').eq(i).click(function () {
                    Omniture_TrackInternalLink(omnitureTagLoc);
                });
				featPartnerSrc.children('li').children('a').children('img').eq(i).attr('src', partnerImageLoc);
                featPartnerSrc.children('li').children('a').children('img').eq(i).attr('alt', partnerNameLoc);
                featPartnerSrc.children('li').shuffle();

            });

            $('div.featuredPartners ul li').each(function (i) {
                if (i >= 5) {
                    i = 5;
                    $('div.featuredPartners ul li').eq(i).remove();
                }

            });
        }
    });

    
}

$(document).ready(function () {
    $("a[rel^='prettyPhoto']").prettyPhoto({
        allow_resize: false
    });

    ajaxCall();

    $('a.prodSeeAllLink').css('position', 'absolute');

    //Featured Article Cycle
    $('div.articles').cycle({
        fx: 'fade',
        timeout: 6000,
        pager: 'div.articleNav',
        updateActivePagerLink: function (pager, z) {
            var articleNavActiveArray = ['activeSlide0', 'activeSlide1', 'activeSlide2', 'activeSlide3', 'activeSlide4']
            $.each(articleNavActiveArray, function (i, articleNavActiveClass) {

                if (i == z) {
                    $(pager).find('a:eq(' + z + ')').addClass('activeSlide' + i);
                    $('a.activeSlide' + i).css('opacity', '0');
                    $('a.activeSlide' + i).stop(true, true).animate({ opacity: 1 }, 350);
                } else {
                    $('a.activeSlide' + i).stop(true, true).animate({ opacity: 0 }, 350);
                    $('a.activeSlide' + i).stop(true, true).animate({ opacity: 1 }, 350);
                    $(pager).find('a:eq(' + z + ')').siblings().removeClass('activeSlide' + i);
                }

                $('a.activeSlide' + i).click(function () {
                    $(this).css('opacity', '1');
                });

                $('a.activeSlide' + i).hover(function () {
                    $(this).css('opacity', '1');
                });

            });
        }
    });

    var articleNavArray = ['one', 'two', 'three', 'four', 'five'];

    $.each(articleNavArray, function (i, articleNavClass) {
        var articleNavLink = $('div.articleNav a');
        var articleNavActive = $('div.articleNav a.activeSlide');
        var articleNavPosition = 0 - 160 * i;

        articleNavLink.eq(i).addClass(articleNavClass);
    });

    //Pause Tips on Nav Click
    $('div.articleNav a').click(function () {
        $('div.articles').cycle('pause');
    });

    //.............find club location Zip Form validation ........................//
    var zipValue = $("div.zipInput input").val('Enter Zip Code');

    $('div.zipInput input').focus(function () {
        $('div.zipInput input').val('');
    });
    $('div.zipInput input').blur(function () {
        var zipValue = $('div.zipInput input').val();
        if (zipValue == '') {
            zipValue = $('div.zipInput input').val('Enter Zip Code');
        }
    });

    //this portion loads website on click of button
    $('div.findClubBtn a').click(function () {
        var zipValue = $('div.zipInput input').val();
        if (zipValue == '' || zipValue.length != '5' || isNaN(zipValue)) {
            zipValue = $('div.zipInput input').val('Enter Valid Zip*');
            $('div.zipInput input').css("color", "red");
            return false;
        }
        else {

            $('div.findClubBtn a').attr('href', 'http://www3.samsclub.com/clublocator/' + 'club_listing.aspx?mySearch=zip&myZip=' + zipValue);
        }
    });

    //this portion loads site on enter 
    $('div.zipInput input').keypress(function (event) {
        var zipValue = $('div.zipInput input').val();
        if (zipValue == '' && event.keyCode == 13) {
            return false;
        }
        else if (zipValue.length != '5' && event.keyCode == 13) {
            zipValue = $('div.zipInput input').val('Enter Valid Zip*');
            $('div.zipInput input').css("color", "red");
            return false;
        }
        else if (isNaN(zipValue) && event.keyCode == 13) {
            zipValue = $('div.zipInput input').val('Enter Valid Zip*');
            $('div.zipInput input').css("color", "red");
            return false;
        }
        else if (event.keyCode == 13) {
            window.location = ('href', 'http://www3.samsclub.com/clublocator/' + 'club_listing.aspx?mySearch=zip&myZip=' + zipValue);
            return true;
        }
    });

    //.............end find club location Zip Form validation ........................//


    //Initiate Skin
  /* $('body').skin({
       imgPath: "/InClubsNow/Media/images/skin/02_MPC_31216_MarsPetPhas1_BG-Skin-1400x400.jpg",
       trackInternalTag: "02_MPC_31216_MarsPetPhas1_SKIN_BTN_Click_MarsPetPhas1_US_ENG_01",
        skinCTA: "Shop Now",
        url: "/Showcase/Mars-Showcase.aspx"
    });*/
    
//Initiates the roadBlock
 /* if (document.cookie.indexOf('visited=true') === -1) {
    var expires = new Date();
    expires.setTime(expires.getTime()+(1000*60*60*4));
    document.cookie = "visited=true; expires="+expires.toUTCString();

   $('body').roadBlock( {  
      cnt:5,  
      //cntTextPre: 'in ',  
      //cntTextSub: 'seconds',  
      //fadeOutSpeed: 'slow',
      //intervalTime: 1000'
      imgWidth:"600",
      imgHeight:"340",
      urlLink: "/Showcase/Mars-Showcase.aspx",
      converge: "02_MPC_31216_MarsPetPhas1", // converge of the page it resides on
      trackingDescription: "Mars",  // who the road block is for
      imgLocation: "/InClubsNow/Media/images/roadBlock/02_MPC_31216_MarsPetPhas1_Roadblock_600x340.jpg" 
    });

   }*/

   
});


