var toggleSpeed = "fast";
var blue = "#3300ff";
var red = "#cc3333";
var black = "#000000";
var isTShirt = false;
var isPOD = false;
var tShirt_NewAPNum = '';
var bSeeAllActive = false;
var CONST_CAROUSEL_NUM_ITEMS_VISIBLE = 2;
var carouselObjectArray = new Array();
var ci = 0;
var bIsZoomOpen = false;
var clickCount = 0;
var selectedAPNum = 0;
var PODConfigID = 0;
var $parentPODContainer;
var parentPODContainerIndex;

var DLEParentTitleheader;
var varMultiDLEString;
var DLEframeBlock;
var DLEframeBlocks;
var DLEcanFrame;
                
$(document).ready(function() {

    formatMainImage();

    $('.RecentlyViewedInner ul li').css('color', blue);
    $('.RecentlyViewedInner ul li').css('text-decoration', 'underline');

    $('.sizeOptionBlock .sizePriceDetails').hide();
    $('.sizeOptionBlock .price .saveAmount').hide();
    sizeOptionBlockSelected_price_bold = $('.sizeOptionBlockSelected .price .bold');
    sizeOptionBlockSelected_price_bold.addClass('size');
    sizeOptionBlockSelected_price_bold.addClass('txtRed');

    // If it is POD Item, get PODApnum , PODConfig ID and session Info
    selectedAPNum = $(this).find('.PODApnum').text();
    if (selectedAPNum > 0)
    {        
        PODConfigID = $(".sizeOptionBlockSelected").attr('id');        
        
               
        DLEframeBlock = $(".sizeOptionBlockSelected").find('.CanFrame').text();

        DLEframeBlocks = DLEframeBlock.split('@');
        DLEcanFrame = DLEframeBlocks[0];
        
        setDLEPODParameters(PODConfigID,selectedAPNum,DLEcanFrame,false);
        
        
    }
    
    sessionInfo = $(this).find('.SessionInfo').text();

    $('.sizeOptionBlock').live("click", function() {

        if ($(this).parent().hasClass('tShirtContainer')) {
            isTShirt = true;
            $('#tShirtError').hide();
        }
        if ($(this).parents().hasClass('PODContainer')) {
            isPOD = true;
        }

        $(".sizeOptionBlockSelected .sizePriceDetails").toggle(toggleSpeed);
        $(".sizeOptionBlockSelected .price .saveAmount").toggle();
        $(".sizeOptionBlockSelected .price .bold").removeClass('size');
        $(".sizeOptionBlockSelected .price .bold").css('color', black);
        $(".sizeOptionBlockSelected .details .bold").removeClass('size');
        $(".sizeOptionBlockSelected").addClass('sizeOptionBlock').removeClass('sizeOptionBlockSelected');
        /*if (isPOD)
        {
        // alert($(".sizeOptionBlockSelected").html());
        }*/
        $(this).removeClass("sizeOptionBlock");
        $(this).addClass("sizeOptionBlockSelected");
        $(".sizeOptionBlockSelected .price .bold").addClass('size');
        $(".sizeOptionBlockSelected .price .bold").css('color', red);
        $(".sizeOptionBlockSelected .details .bold").addClass('size');
        $(".sizeOptionBlockSelected .sizePriceDetails").toggle(toggleSpeed);
        $(".sizeOptionBlockSelected .price .saveAmount").toggle();


        if (!isTShirt) {
            if (isPOD) {
                //Show or hide CustomeFrame button and tab

                sessionInfos = sessionInfo.split('@');
                ZoneID = sessionInfos[0];
                CurrencyCode = sessionInfos[1];

                //selectedAPNum = $(this).parent('.PODApnum').text(); TO DO
                $parentPODContainer = $(this).parent('.PODContentBox');
                parentPODContainerIndex = $parentPODContainer.children(':first').attr('id');

                //Collapse all module except the one that has selected item
                $('.PODContentBox').each(function(i) {
                    var thisChild = $(this).children(':first').attr('id');
                    if (thisChild != parentPODContainerIndex)
                        $(this).hide();
                });

                //get the PODConfig of selected item
                PODConfigID = $(this).attr('id');
                selectedAPNum = $(this).find('.apnum').text();
                $('.PODApnum').text(selectedAPNum);
                //swap main image and hires image of the selected iPOD item
                $('#mainImage').attr('src', $(this).find('.PODImagePath').text());
                $('#hiResHref').text($(this).find('.PODHiresImagePath').text());

		
                //ApplyDropShadow
                CanCanvasStretch = $(this).find('.CanCanvasStretch').text()
                ApplyDropShadow($(this).find('.ApplyDropShadow').text(), CanCanvasStretch, ZoneID)

                //Show or hide CustomeFrame button and tab
                frameBlock = $(this).find('.CanFrame').text();

                frameBlocks = frameBlock.split('@');
                canFrame = frameBlocks[0];
                canPreFrame = frameBlocks[1];
                
                
                /*DLE Code Start*/
                setDLEPODParameters(PODConfigID,selectedAPNum,canFrame,true);
                /*DLE Code End*/
                
                
                // IF the POD item is Canvas item then do not show CanFrame even the flag is True in db
                if (CanCanvasStretch == "True") {
                    $('.outerCustomFrame').hide();
                    canFrame = 'False';
                }
                if (canPreFrame == 'True') {
                    if (canFrame == 'False') {
                        $('.outerCustomFrame').hide(); //button
                        $('#PreCustomFrame').hide();  //PreCustom Frame block
                        $('#CustomFrame').hide();    //PreCustom Frame block
                        
                        /* Changes Done for ASAP -APC Custom  Frame It Button */
                        
                        $('#cf_FrameContainerPortrait').hide();    //PreCustom Frame block
                        $('#cf_FrameContainerLandscape').hide();    //PreCustom Frame block
                        
                        /* END OF: Changes Done for ASAP -APC Custom  Frame It Button */
                        
                        
                        $('#PreFrame').show();      //PreCustom Frame block
                        $('.preFrameBlock').show();
                        $('.customFrameBlock').hide();
                    }
                    else {
                        $('.outerCustomFrame').show();
                        $('.PreCutomFrameOuter').show();
                        $('#PreCustomFrame').show();
                        $('#CustomFrame').hide();

                        /* Changes Done for ASAP -APC Custom  Frame It Button */
                        
                        $('#cf_FrameContainerPortrait').show();
                        $('#cf_FrameContainerLandscape').show();

                        /* END OF: Changes Done for ASAP -APC Custom  Frame It Button */
                        $('#PreFrame').hide();
                        $('.preFrameBlock').show();
                        $('.customFrameBlock').show();
                    }
                }
                else {
                    if (canFrame == 'False') {
                        $('.PreCutomFrameOuter').hide();
                        $('.outerCustomFrame').hide();
                        $('.preFrameBlock').hide();
                        $('.customFrameBlock').hide();
                    }
                    else {
                        $('.PreCutomFrameOuter').show();
                        $('.outerCustomFrame').show();
                        $('#PreCustomFrame').hide();
                        $('#PreFrame').hide();
                        $('.preFrameBlock').hide();
                        $('.customFrameBlock').show();
                    }
                }
                if (canFrame == 'True') {
                    //modify the framing link to pass the selected APNum and POD ConfigID.
                    newString = 'apnum=' + selectedAPNum;
                    newPODString = 'PODConfigID=' + PODConfigID;

                    strAPNumToBeReplaced = GetAPNumToBeReplaced($('.CustomeFrameButtonBlock').html(), 'apnum=');
                    strPODConfigIDToBeReplaced = GetAPNumToBeReplaced($('.CustomeFrameButtonBlock').html(), 'PODConfigID=');
                    ReplaceJSAPNumInURL(strAPNumToBeReplaced, newString);
                    ReplaceJSAPNumInURL(strPODConfigIDToBeReplaced, newPODString);
                }

                canECard = $(this).find('.CanECard').text();
                if (canECard == 'False') {
                    $('.ShareBlock').hide();
                }
                else {
                    $('.ShareBlock').show();
                }

                //Service Option Block
                DisplayOtherServiceOptions(selectedAPNum, PODConfigID, ZoneID, CurrencyCode);

                //Swap IncludedText for PODItem
                $('#ProductContent .IncludedText').html($(this).find('.IncludedText').html());

                //Swap APNUM and PODCOnfigID for Favorites
                // alert($('#mygalleryblock').html());
                /* newString = 'mgapnum=' + selectedAPNum;
                newPODString = 'mgpodconfigid=' + PODConfigID;
                strAPNumToBeReplaced = GetAPNumToBeReplaced($('#mygalleryblock').html(), 'mgapnum=');
                alert(strAPNumToBeReplaced);
                strPODConfigIDToBeReplaced = GetAPNumToBeReplaced($('#mygalleryblock').html(), 'mgpodconfigid=');
                alert(strPODConfigIDToBeReplaced);

                ReplaceFavoriteAPNumInURL(strAPNumToBeReplaced, newString);
                ReplaceFavoriteAPNumInURL(strPODConfigIDToBeReplaced, newPODString);*/


            }
            else {
                selectedAPNum = $(this).find('.apnum').text();
                //alert(selectedAPNum);
                theURL = location.href;
                var theURLCopy = theURL.toLowerCase();
                newString = 'apnum=' + selectedAPNum;
                var loc1 = theURLCopy.indexOf('apnum=');
                if (loc1 > 0)
                    var loc2 = theURL.indexOf('&', loc1);
                else {
                    newString = '_i' + selectedAPNum;
                    loc1 = theURLCopy.indexOf('_i');
                    var loc2 = theURL.indexOf('_', loc1 + 1);
                }
                var sub1 = theURL.substring(loc1, loc2);
                theURL = theURL.replace(sub1, newString);
                window.location = theURL;
            }
        }
        else {
            tShirt_NewAPNum = $(this).attr('id');
        }


    })


    

    $parentPODContainer = $('.sizeOptionBlockSelected').parent();

    parentPODContainerIndex = $parentPODContainer.children(':first').attr('id');

    $('.PODContentBox').each(function(i) {

        var thisChild = $(this).children(':first').attr('id');
        if (thisChild != parentPODContainerIndex)
            $(this).hide();

    });

    $(".sizeOptionBlock").live("mouseover", function() {
        //$(this).css('color', red);	
        $('> * .bold', this).css('color', red);
    });

    $(".sizeOptionBlock").live("mouseout", function() {
        $('> * .bold', this).css('color', black);
    });

    $(".sizeOptionBlockSelected").live("mouseover", function() {
        $('> .details .bold', this).css('color', black);
    });

    $(".sizeOptionBlockSelected").live("mouseout", function() {
        $('> .details .bold', this).css('color', black);
    });


    $('#ArtistName').hover(
      function() {
          $(this).css('text-decoration', 'underline');
      },
      function() {
          $(this).css('text-decoration', 'none');
      }
    );

    /*
    //hide secondary actions block if no content below it
    $("#ServiceAndShareContainer .secondaryActions").each(function(i){								 
    var x = $(this).find("li").length;	
    if (x == 0)
    $(this).hide();
    });
    */
    var x = $("#ProductContent").find("p").length;
    if (x == 0)
        $("#ProductContentContainer").hide();

    $("#AddToCart").hover(function() {
        $("#AddToCart, #AddToCart *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/.gif/i, '_hover.gif');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#AddToCart, #AddToCart *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/_hover.gif/i, '.gif');
            $(this).css('backgroundImage', str);
        });
    });

    /* Changes Done for ASAP -APC Custom  Frame It Button */
    if ($('#cf_FrameContainerLandscape').length > 0) {
        $('#cf_tableland').css('width', $('#cf_FrameContainerLandscape').width());
    }
    if ($('#cf_FrameContainerPortrait').length > 0) {
        $('#cf_tableport').css('width', $('#cf_FrameContainerPortrait').width());
    }

    $("#cf_FrameContainerPortrait").hover(function() {
        $("#cf_FrameContainerPortrait, #cf_FrameContainerPortrait *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/1.png/i, '2.png');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#cf_FrameContainerPortrait, #cf_FrameContainerPortrait *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/2.png/i, '1.png');
            $(this).css('backgroundImage', str);
        });
    });

    $("#cf_FrameContainerLandscape").hover(function() {
        $("#cf_FrameContainerLandscape, #cf_FrameContainerLandscape *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/1.png/i, '2.png');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#cf_FrameContainerLandscape, #cf_FrameContainerLandscape *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/2.png/i, '1.png');
            $(this).css('backgroundImage', str);
        });
    });


    $("#CustomFrame").hover(function() {
        $("#CustomFrame, #CustomFrame *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/.gif/i, '_hover.gif');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#CustomFrame, #CustomFrame *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/_hover.gif/i, '.gif');
            $(this).css('backgroundImage', str);
        });
    });

    $("#CustomFrameInModule").hover(function() {
        $("#CustomFrameInModule, #CustomFrameInModule *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/.gif/i, '_hover.gif');
            $(this).css('backgroundImage', str);
        });
    }, function() {
        $("#CustomFrameInModule, #CustomFrameInModule *").each(function(i) {
            var str = $(this).css('backgroundImage');
            str = str.replace(/_hover.gif/i, '.gif');
            $(this).css('backgroundImage', str);
        });
    });
    /* END OF: Changes Done for ASAP -APC Custom  Frame It Button */

    //hide all contentBoxes that aren't first
    $('.contentBox + .contentBox').hide();


    //legacy add to favorites code positioning
    //add to favorites is in getPosterNew.asp
    var favoritesLi = $('#Favorites');
    var saveFavoritesObj = $('#saveFavoritesContent').find('#add_to_gallery').parent();
    if (saveFavoritesObj.length == 0)
        var saveFavoritesObj = $('#saveFavoritesContent').find('#add_item').parent();
    var saveFavoritesContents = saveFavoritesObj.html();
    //var saveFavoritesOnClick = saveFavoritesObj.attr('onclick');
    favoritesLi.html(saveFavoritesContents);
    favoritesLi.click(function() {
        saveFavoritesObj.click();
    });

    $('#add_item1').live("click", function() {
        var apnumparam = '&mgapnum=' + selectedAPNum + '&mgpodconfigid=' + PODConfigID + '&';
        doGalleryPopUP(this, 'add_item', apnumparam, '', '');
    });
    
    //tab wrapping
    //for each set of tabs in contentBoxHeaderTab

    $('div.contentBoxHeaderTab').each(function(i) {
        var setOfChildTabs, firstItem, secondItem;
        setOfChildTabs = $(this).find('li');
        containerWidth = $(this).width();
        containerWidth = containerWidth - 30;

        firstItem = setOfChildTabs[0];
        secondItem = setOfChildTabs[1];

        firstItemWidth = $(firstItem).width();
        secondItemWidth = $(secondItem).width();
        firstItemHeight = $(firstItem).height();
        secondItemHeight = $(secondItem).height();


        if (firstItemWidth + secondItemWidth > containerWidth) {
            if (firstItemWidth < containerWidth / 2)
                $(secondItem).css('width', containerWidth - firstItemWidth - 20);
            else if (secondItemWidth < containerWidth / 2)
                $(firstItem).css('width', containerWidth - secondItemWidth - 20);
            else {
                $(firstItem).css('width', containerWidth / 2 - 10);
                $(secondItem).css('width', containerWidth / 2 - 10);
            }

            firstItemHeight = $(firstItem).height();
            secondItemHeight = $(secondItem).height();
        }

        if (firstItemHeight > secondItemHeight) {
            $(secondItem).height(firstItemHeight);
            //alert('first ' + firstItemHeight + ' ' + $(secondItem).height() );
        }
        else if (secondItemHeight > firstItemHeight) {
            $(firstItem).height(secondItemHeight);
            //alert('second ' + secondItemHeight + ' ' + $(firstItem).height() );
        }
    });

    $(".contentBoxHeaderTab li.tabDefault").live("click", function() {
        var parentContainer = $(this).parents(".contentBoxOuter");
        //var tabIndex = $('.contentBoxHeaderTab li').index(this);
        var tabIndex = $(parentContainer).find('.contentBoxHeaderTab li').index(this);
        $(this).siblings('li').removeClass('tabSelected').addClass('tabDefault');
        $(this).removeClass('tabDefault').addClass('tabSelected');
        $(this).css('color', black);
        var parentContainer = $(this).parents(".contentBoxOuter");
        //$(parentContainer).find("div.contentBox").toggle("fast");
        $(parentContainer).find("div.contentBox").hide();
        $(parentContainer).find("div.contentBox:eq(" + tabIndex + ")").fadeIn('normal');
        //alert( 'hi ' + carouselObjectArray[0]);
        var i = 0;
        var j = 0;
        if (bSeeAllActive)
            j = 1;
        for (i = j; i < ci; i++)
            carouselObjectArray[i].reload();
        //Changes done for - ASAP APC Shopping Cart Redesign
        fnAlignImage();        
    });
    
    function fnAlignImage() {
    $('#items_Related').find('img.vAlign').each(function(i) {
        var ah = $(this).height();
        var ph = $(this).parent().height();
        var mh = (ph - ah) / 2;
        $(this).css('margin-top', mh);
    });
       
    }
    

    $(".contentBoxHeaderTab li.tabDefault").live("mouseover", function() {
        $(this).css('color', red);
    });
    $(".contentBoxHeaderTab li").mouseout(function() {
        $(this).css('color', black);
    });

    $(".slidingModule").each(function(i) {
        var thisCarousel = $(this);
        //ie fix: make each li element the same height as the tallest element\
        //loop through all li elements, note tallest
        var thisHeight;
        var theTallest = 0;
        $(this).find("li div.equalHeight").each(function(i) {
            thisHeight = $(this).height();
            //alert('thisheight ' + thisHeight);
            if (thisHeight > theTallest) {
                theTallest = thisHeight + 4;
                //alert('tallest ' + theTallest);
            }

        });
        //alert(theTallest);
        $(this).find("li div.equalHeight").each(function(i) {
            $(this).css('height', theTallest);
        });

        $(this).jcarousel({
            scroll: getWidthOfCarousel(thisCarousel),
            initCallback: mycarousel_initCallback,
            itemFirstInCallback: mycarousel_itemFirstInCallback,
            wrap: "both",
            size: getNumberOfCarouselItems(thisCarousel),
            visible: getWidthOfCarousel(thisCarousel),
            itemVisibleOutCallback: mycarousel_loadImages
        });
        
        //Changes for Shopping Cart Redesign
	    fnAlignCarousel(thisCarousel);       
    });
    
    function fnAlignCarousel(carousel){
        if ( $(carousel).hasClass("BestSellers") )
        {
            $(carousel).find(".jcarousel-clip").attr({ 
		            style: "#margin-left:20px;#width:615px;"
	            });
        }    
    }
    $('.vAlign').vAlign();
    
    $(".jcarousel-next-horizontal").mouseover(function() {
        $(this).addClass("jcarousel-next-horizontal-hover");
    }).mouseout(function() {
        $(this).removeClass("jcarousel-next-horizontal-hover");
    });

    $(".jcarousel-prev-horizontal").mouseover(function() {
        $(this).addClass("jcarousel-prev-horizontal-hover");
    }).mouseout(function() {
        $(this).removeClass("jcarousel-prev-horizontal-hover");
    });

    $('.link, .standardLink, .standardLinkNoUnderline, #add_to_gallery, #add_item').live('mouseover', function() {
        $(this).css('color', red);
        $(this).css('text-decoration', 'underline');
    });
    $('.link').bind('mouseout', function() {
        $(this).css('color', black);
        $(this).css('text-decoration', 'none');
    });

    $('.standardLink').live('mouseout', function() {
        $(this).css('color', blue);
        $(this).css('text-decoration', 'underline');
    });

    $('.standardLinkNoUnderline, #add_to_gallery, #add_item').live('mouseout', function() {
        $(this).css('color', blue);
        $(this).css('text-decoration', 'none');
    });



    $('.codeBox').bind('click', function() {
        this.focus();
        this.select();
    });

    $('.blogHeader').hover(function() {
        $(this).css('color', red);
        $(this).css('text-decoration', 'underline');
    }, function() {
        $(this).css('color', '#768193');
        $(this).css('text-decoration', 'none');
    });

    $('.blogHeader, .closeBlog').click(function() {
        $('.blogContentBox').toggle();
    });

    $('.PODHeader').bind('click', function() {
        if ($(this).next('.PODContentBox').is(':visible')) {
            $(this).find('h3').removeClass('Expandopen');
            $(this).find('h3').addClass('Expandclose');
        }
        else {
            $(this).find('h3').removeClass('Expandclose');
            $(this).find('h3').addClass('Expandopen');
        }
        $(this).next('.PODContentBox').toggle('normal');
    });

    var $PODHeader = $('.PODHeader');
    var $sizeOptionPODExpand = $('.sizeOptionPOD');
    var headerLength = $PODHeader.length;
    if (headerLength < 2) {
        $sizeOptionPODExpand.css('background-image', 'none');
        $PODHeader.unbind('click');
    }


    $(document).bind('click', function(e) {
        if (bIsZoomOpen) {
            if (clickCount > 0) {
                $('.hiResView').click();
                bIsZoomOpen = false;
                clickCount = 0;
            }
            else
                clickCount = 1;
        }
    });

    $('.enlarge, .hasZoom').live('click', function() {

        buildEnlargeImage();
    });

    $('.hiResView').live('click', function() {
        $(this).hide();
        bIsZoomOpen = false;
        clickCount = 0;
    });



    var contentBoxSets = $('.contentBoxSets');
    var setSize = contentBoxSets.attr('id');
    $('.setSize').append(setSize);
    if (setSize > 2) //set height to the height of the first two items
        contentBoxSets.addClass('contentBoxSetsHeight');
    $('.seeSetDetails').bind('click', function() {
        var offset = $('.contentBoxSets').offset();
        var scrollAmount = offset.top - 20;
        $(document).scrollTop(scrollAmount);
    });
    //t-shirt logic
	
	//if item is already in cart then select it
	var tShirt_selectedAPNum = '';
	tShirt_selectedAPNum = $('#tShirtSelectedAPNum').text(); //this is only set if iid <> ''
	if (tShirt_selectedAPNum != '')
	{
		tShirt_selectedOption = '#' + tShirt_selectedAPNum + ':visible';
		$(tShirt_selectedOption).click();
	}

    $('select#tColor').change(function() {
        var currentColor = $('select#tColor option:selected').attr('value');
        var currentColorDiv = '#' + currentColor;
        sizeOptionBlock = $('.sizeOptionBlock');

        sizeOptionBlock.hide();
        if (tShirt_NewAPNum != '') //a size has been selected
        {
            var currentSelectedTShirt = '#' + tShirt_NewAPNum;
            $(currentSelectedTShirt).removeClass('sizeOptionBlockSelected');
            $(currentSelectedTShirt).addClass('sizeOptionBlock');
            $(currentSelectedTShirt).find('.sizePriceDetails').hide();
            $(currentSelectedTShirt).find('.saveAmount').hide();
            $(currentSelectedTShirt).hide();
            tShirt_NewAPNum = '';

        }
        sizeOptionBlock.each(function(i) {

            if ($(this).hasClass(currentColor))
                $(this).show();
        });

        newImageURL = $(currentColorDiv).text();
        newImageURLs = newImageURL.split('@');
        $('#mainImage').attr('src', newImageURLs[0]);
        $('#hiResHref').text(newImageURLs[1]);


    });

    $('#scrollControlSeeAllID').live("click", function() {
        notifyTealeaf('see_all_link');
    });

    $('#customFramingTab').bind('click', function() {
        notifyTealeaf('custom_framing_tab');
    });

    $('.jcarousel-prev').bind('click', function() {
		arrowClickCount = $(this).data('arrowClickCount');
		if (arrowClickCount != parseInt(arrowClickCount))
			arrowClickCount = 1;
		else
			arrowClickCount  = arrowClickCount+1;
		$(this).data('arrowClickCount', arrowClickCount);
		notifyTealeaf('left_arrow_'+arrowClickCount);	
	});
	
	$('.jcarousel-next').bind('click', function() {
		arrowClickCount  = $(this).data('arrowClickCount');
		if (arrowClickCount != parseInt(arrowClickCount))
			arrowClickCount = 1;
		else
			arrowClickCount = arrowClickCount+1;
		$(this).data('arrowClickCount', arrowClickCount);
		notifyTealeaf('right_arrow_'+arrowClickCount);	
	});

   $('#items_DesignerRec li, #items_Sets li').bind('click', function() {
		notifyTealeaf('upsell_item');
	});


    $('#itemNotAvailable .SectionTable').width('395px');
	var $popupContainer = $('#inPageFS');
	var gCloseText = 'close';
	$popupContainer.dialog({ modal: true, autoOpen:false, width:'900'});
	$popupContainer.dialog('option', 'height', '725');
	$popupContainer.dialog('option', 'title', gCloseText);
	$popupContainer.dialog('option', 'position', ['center','top']);
	$popupContainer.dialog('open');
	$('.ui-widget').css('margin-top','10px');
	$('.ui-dialog-content').css("min-height", "0");
	$('.ui-widget').css('height','725px');
	$('.ui-dialog-titlebar').live('click',function(){
		$('#inPageFS').dialog( 'close' );
	});
	
	//Rolling Stone
	var $includedText = $('#ProductContent .IncludedText');
	includedText = $includedText.text().toLowerCase();
	//if product content contains 'rolling stone' and 'subscription' then add a link to popup the details
	if (includedText.indexOf('rolling stone') > 1 && includedText.indexOf('subscription') > 1 ){
		var rsClickEvent = "RollingStoneDetailsWindow('12','$6.48')";
		rollingStoneOfferLink = '<div class="standardLink" onclick="'+rsClickEvent+'">Offer and rebate details</div>';
		$includedText.append(rollingStoneOfferLink);
	}
});



function formatMainImage()
{
	var iw = $("#mainImage").attr('width');
	var cw = $("#MainImageContainer").width();
	var mw = (cw - iw)/2 + 5;
	var mainImageContainer = $("#MainImageContainer");
	mainImageContainer.css('margin-left',mw);
	mainImageContainer.css('width','');
	if ( $('#dleIcon').length == 0)
		$('.enlarge').css('width',(iw/2)+28);
	else {		
		var newEnlargePosition = $('#A1').position().left;
		$('.enlarge').css('position','absolute');
		$('.enlarge').css('left',newEnlargePosition);
		$('.enlarge').css('width','100px');
	}
}

(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);

function buildEnlargeImage()
{
	//get Image src and image size
	var imageSrc = $("#hiResHref").text();
	var hw = $("#hiResHref").attr('className');
	var aHeightWidth = hw.split("_");
	var theHeight = aHeightWidth[0];
	var theWidth = aHeightWidth[1];
	//add background image to imageContainer
	$('.hiResImageContainer').css('background-image','url('+imageSrc+')');
	//set width of imageContainer
	$('.hiResImageContainer').css('height',theHeight);
	$('.hiResImageContainer').css('width',theWidth);
	$('.hiResView').show();
	bIsZoomOpen = true;
}

function linkForm(action)
{
	document.getElementById('globalLinkForm').action = action;
	document.getElementById('globalLinkForm').submit();
}

function newWindow(action, name, width, height)
{
	var newWin = window.open(action,name,'width=' + width + ',height=' + height + ',status=no,toolbar=no,scrollbars=yes,resizable=yes,left=1,top=1');
}

function addToCart(action, thisObject)
{
	if ($(thisObject).hasClass('tShirtAddToCart'))
	{
		if (tShirt_NewAPNum != '')
			action = replaceAPNumInURL(action, tShirt_NewAPNum);
		else{
			$('#tShirtError').fadeOut('fast');
			$('#tShirtError').fadeIn('normal');
			return false;
		}
	}
	if ($(thisObject).hasClass('PODItem'))
	{
	    if (PODConfigID != 0)
	    {
			action = replaceAPNumInURL(action, selectedAPNum);
			action = replacePODConfigIDInURL(action, PODConfigID);
	    }
	}
	linkForm(action);
}

function taf(localCID, lAPNum) { 
  
    if (selectedAPNum != 0)
        lAPNum = selectedAPNum

	winPop = window.open("/taf.asp?CID="+localCID + "&apnum="+lAPNum+ "&PODConfigID="+PODConfigID,"TellAFriend",'status=no,toolbar=no,scrollbars=no,resizable=no,width=400,height=400,left=1,top=1')
	if (window.focus) 
		 winPop.focus()
}

function ecard(action, thisObject)
{
	if ($(thisObject).hasClass('ecard'))
	{
	    if (selectedAPNum != 0)
	        action = replaceAPNumInURL(action, selectedAPNum);
	    if (PODConfigID != 0)
			action = replacePODConfigIDInURL(action, PODConfigID);
	}
	linkForm(action);
}

function replaceAPNumInURL(theURL, selectedAPNum)
{
	var theNewURL = '';
	var theURLCopy = theURL.toLowerCase();
	var newString = 'apnum=' + selectedAPNum;
	var loc1 = theURLCopy.indexOf('apnum=');
	var loc2 = theURL.indexOf('&',loc1);
	var sub1 = theURL.substring(loc1,loc2);
	theNewURL = theURL.replace(sub1,newString);
	return theNewURL;		
}

function replacePODConfigIDInURL(theURL, selectedAPNum)
{
	var theNewURL = '';
	var theURLCopy = theURL;
	var newString = 'PODConfigID=' + selectedAPNum;
	var loc1 = theURLCopy.indexOf('PODConfigID=');
	var loc2 = theURL.indexOf('&',loc1);
	var sub1 = theURL.substring(loc1,loc2);
	theNewURL = theURL.replace(sub1,newString);
	return theNewURL;		
}

 function ReplaceJSAPNumInURL(strAPNumToBeReplaced,strCurrentAPNum)
  {
    $('#CallToActionContainer').html($('#CallToActionContainer').html().replace(strAPNumToBeReplaced , strCurrentAPNum));   //AddToCart Button
    $('.CustomeFrameButtonBlock').html($('.CustomeFrameButtonBlock').html().replace(strAPNumToBeReplaced , strCurrentAPNum));         //CustomFrame Button
    $('.customFramingInnerText').html($('.customFramingInnerText').html().replace(strAPNumToBeReplaced , strCurrentAPNum)); //CustomFrame in Resigner module
  }

  function ReplaceFavoriteAPNumInURL(strAPNumToBeReplaced, strCurrentAPNum) 
  {
      $('#mygalleryblock').html($('#mygalleryblock').html().replace(strAPNumToBeReplaced, strCurrentAPNum));   //Save To Your Gallery
  }
   
 function GetAPNumToBeReplaced(strHTML, value)
  {
	var HTML = strHTML;
	var loc1 = HTML.indexOf(value);
	var loc2 = HTML.indexOf('&',loc1);
	var sub1 = HTML.substring(loc1,loc2);
	return sub1
  }
  

 function ApplyDropShadow(applyShadow,CanCanvasStretch, ZoneID)
  {
        //Apply Canvas drop shadow for canvas Item
        if (CanCanvasStretch == "True" && (ZoneID == "1" || ZoneID == "5"))
        {
            $("#dropShadow1").removeClass('wrap1');
            $("#dropShadow2").removeClass('wrap2');
            $("#dropShadow3").removeClass('wrap3');
            $("#dropShadow1").removeClass('canvaswhitewrap1');
            $("#dropShadow2").removeClass('canvaswhitewrap2');
            $("#dropShadow3").removeClass('canvaswhitewrap3');
            $("#dropShadow1").addClass('canvaswrap1');
            $("#dropShadow2").addClass('canvaswrap2');
            $("#dropShadow3").addClass('canvaswrap3');
        }
        else if (CanCanvasStretch == "True" && ZoneID == "2")
        {
            $("#dropShadow1").removeClass('wrap1');
            $("#dropShadow2").removeClass('wrap2');
            $("#dropShadow3").removeClass('wrap3');
            $("#dropShadow1").removeClass('canvaswrap1');
            $("#dropShadow2").removeClass('canvaswrap2');
            $("#dropShadow3").removeClass('canvaswrap3');
            $("#dropShadow1").addClass('canvaswhitewrap1');
            $("#dropShadow2").addClass('canvaswhitewrap2');
            $("#dropShadow3").addClass('canvaswhitewrap3');
        }
        else
        {
            // Apply regular drop shadow
            if(applyShadow == "1")
            {
                $("#dropShadow1").removeClass('canvaswhitewrap1');
                $("#dropShadow2").removeClass('canvaswhitewrap2');
                $("#dropShadow3").removeClass('canvaswhitewrap3');
                $("#dropShadow1").removeClass('canvaswrap1');
                $("#dropShadow2").removeClass('canvaswrap2');
                $("#dropShadow3").removeClass('canvaswrap3');
                $("#dropShadow1").addClass('wrap1');
                $("#dropShadow2").addClass('wrap2');
                $("#dropShadow3").addClass('wrap3');
            }
            else  // Remove all shadow
            {
                $("#dropShadow1").removeClass('canvaswhitewrap1');
                $("#dropShadow2").removeClass('canvaswhitewrap2');
                $("#dropShadow3").removeClass('canvaswhitewrap3');
                $("#dropShadow1").removeClass('canvaswrap1');
                $("#dropShadow2").removeClass('canvaswrap2');
                $("#dropShadow3").removeClass('canvaswrap3');
                $("#dropShadow1").removeClass('wrap1');
                $("#dropShadow2").removeClass('wrap2');
                $("#dropShadow3").removeClass('wrap3');
            }
        }
 }

function rebindAll(){
	$("#AddToCart").hover(function() {
		$("#AddToCart, #AddToCart *").each(function(i){
			var str = $(this).css('backgroundImage');
			str = str.replace(/.gif/i, '_hover.gif');
			$(this).css('backgroundImage', str);
		});
	}, function(){
		$("#AddToCart, #AddToCart *").each(function(i){
			var str = $(this).css('backgroundImage');
			str = str.replace(/_hover.gif/i, '.gif');
			$(this).css('backgroundImage', str);
		});
	});	
	
}

function mycarousel_initCallback(carousel) {
	carouselObjectArray[ci] = carousel;
	ci = ci+1;
	var currentDiv;
	var carouselContainer = '#' + carousel.container[0].id;
	var paginationID = $(carouselContainer).find('div.jcarousel-control').attr('id');
	var paginationContainer = '#' + paginationID;
	var numItemsVisible = carousel.options.scroll;
	//create pagination: get all li elements and build squares
	var n = $(carouselContainer).find('ul.jcarousel-list li').length;
	//add dummy items to create equal # of items on all pages
	var nCount = n;
	var numPages = n / numItemsVisible;
	numPages = Math.ceil(numPages);
	var numDummyItems = (numPages * numItemsVisible) - n;
	for (i=0;i<numDummyItems;i++){
			carousel.add(nCount+1, "");
			nCount = nCount+1;
	}	
	var j = 1;
	i=0;
	var textToAppend = '';
	for (i=0;i<numPages;i++){
		divName = j + '_' + paginationID;
		//currentDiv = $('#'+divName);
		pageNumber = i+1;
		textToAppend = textToAppend + '<div thePage="'+j+'" id="'+divName+'" title="page '+pageNumber +'" class="scrollControl scrollControlInactive"></div>';
		//currentDiv.data('pagination', j);
		
		//currentDiv.attr('title','page ' + pageNumber);
		j = j + numItemsVisible;
	}
	if ( $(carouselContainer).hasClass('addSeeAllOption') ){
		textToAppend = textToAppend + '<div id="scrollControlSeeAllID" class="scrollControlSeeAll floatLeft link">';
		seeAllTextStr = $('#seeAllText').text();	
		textToAppend = textToAppend + seeAllTextStr + ' ('+n+')</div><div class="clear"></div>';
	}
	
	if (textToAppend.length)
		$(paginationContainer).append(textToAppend);
	
	if (numPages == 1) //there is only one page so don't show arrows or pagination
		carouselShowAll(carouselContainer,paginationContainer);
	
	$(carouselContainer).find('div.jcarousel-control div.scrollControlSeeAll').bind('click', function() {
		carouselShowAll(carouselContainer,paginationContainer);
	});
	
	$(carouselContainer).find('div.jcarousel-control div.scrollControl').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('thePage')));
	});
};
		
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	var numItemsVisible = carousel.options.scroll;
	var activeBoxID = idx;
	if  ((activeBoxID % numItemsVisible == 0) && numItemsVisible > 1)
		activeBoxID = ++activeBoxID;
	globalActiveBoxID = activeBoxID;
	var carouselContainer = '#' + carousel.container[0].id;
	var carouselControl = $(carouselContainer).find('div.jcarousel-control');
	var paginationID = carouselControl.attr('id');
	var theDiv = activeBoxID + '_' + paginationID; //for example, 1_carouselPage-designer
	var currentBlock = carouselControl.find('#'+theDiv);
	var allOthers = carouselControl.find('div.scrollControl').not(currentBlock);
	allOthers.removeClass('scrollControlActive').removeClass('scrollControlActive-hover').addClass('scrollControlInactive');
	currentBlock.removeClass('scrollControlInactive').removeClass('scrollControlInactive-hover').addClass('scrollControlActive');
	allOthers.mouseover(function(){
		$(this).removeClass("scrollControlActive-hover").addClass("scrollControlInactive-hover");
		}).mouseout(function(){
		$(this).removeClass("scrollControlInactive-hover");		
	});
	currentBlock.mouseover(function(){
		$(this).removeClass("scrollControlInactive-hover").addClass("scrollControlActive-hover");
		}).mouseout(function(){
		$(this).removeClass("scrollControlActive-hover");		
	});	
};
		
function mycarousel_loadImages(carousel, item, idx, state){
	
	var listID = '#' + carousel.list[0].id;
	if ($(listID).data('imagesLoaded') != 'yes'){
		var nextImages = $(listID).find('li * img');
		nextImages.each(function(i){
			var theSRC = '';
			theSRC = $(this).attr('src');
			if (theSRC == '' || theSRC == undefined)
				$(this).attr('src', $(this).attr('id'));
				$(this).css('visibility','visible');
		});
		//alert('images now loaded');
		$(listID).data('imagesLoaded', 'yes');
	}			
};
		
function carouselShowAll(carouselContainer,paginationContainer){
	$(carouselContainer).find(".jcarousel-clip").css('max-height','none');
	$(carouselContainer).find(".jcarousel-clip").css('overflow','visible');
	
	$(carouselContainer).find(".jcarousel-clip").attr({ 
		style: "#margin-left:5px;#margin-right:5px;#width:400px;"
	});
	
	$(carouselContainer).find(".jcarousel-list").attr({ 
		style: "width:366px; left:0;#width:400px;"
	});
	$(carouselContainer).find(".jcarousel-prev").hide();
	$(carouselContainer).find(".jcarousel-next").hide();
	$(paginationContainer).hide();
	mycarousel_loadImages(carouselObjectArray[0], '','','');
	bSeeAllActive = true;
}

function getNumberOfCarouselItems(carousel){ 
	var numItems = 0;
	var numItemsVisible = getWidthOfCarousel(carousel);
	var n = $(carousel).find("li").length;
	var numPages = n / numItemsVisible;
	numPages = Math.ceil(numPages);
	var numItems = (numPages * numItemsVisible);
	return numItems;
}
			
function getWidthOfCarousel(carousel){
	var numItems = 2;
	if ( $(carousel).hasClass("threeItems") )
		numItems = 3;
	else if ( $(carousel).hasClass("oneItem") )
		numItems = 1;
    //Changes done for - ASAP APC Shopping Cart Redesign
    else if ( $(carousel).hasClass("fouritems") )
        numItems = 4;
	return numItems;
}

function notifyTealeaf(actionName)
{
	var sendString;
	sendString = "elementID=productPage&theAction=" + actionName;
	$.get("/tealeaf/notify.asp", { elementID: "productPage", theAction: actionName } );
}

function DisplayOtherServiceOptions(APNum, PODConfigID, ZoneID, CurrencyCode)
{
    var output; 
    $.ajax
    ({
        type:"POST",
        url: "/includes/valueaddedserviceshelper.asp",
        dataType: "application/x-www-form-urlencoded",
        data: "PODAPNum=" + APNum + "&ZoneID=" + ZoneID + "&ISOCurrencyCode=" + CurrencyCode + "&PODConfigAPNum=" + PODConfigID + "&isAjax=Y",
        async: false,
        success: function(msg){output = msg;}
    })
    FetchServiceOptionValues(output, APNum, PODConfigID)
}

function FetchServiceOptionValues(output, APNum, PODConfigID)
{
    var serviceOptions,canCanvasTransfer,canMount,canLaminate,aServiceOptions
    serviceOptions = output;
    //Service options are in the following format.
    //canvastransfer@canmount@canLaminate.
    aServiceOptions = serviceOptions.split("@");
    canCanvasTransfer = aServiceOptions[0];
    canMount = aServiceOptions[1];
    canLaminate = aServiceOptions[2];

    //Hide or display based on the availability of the flags.
    showHideServiceOptions(canCanvasTransfer, canMount, canLaminate, APNum, PODConfigID)
}

function showHideServiceOptions(canCanvasTransfer, canMount, canLaminate, APNum, PODConfigID)
{
    if ((canCanvasTransfer == "1") || (canMount == "1") || (canLaminate == "1"))
    {
         $('.ServiceBlock').show();
         
         newString = 'apnum=' + APNum;
         newPODString = 'PODConfigID=' + PODConfigID;
        
         strAPNumToBeReplaced = GetAPNumToBeReplaced($('.ServiceBlock').html(),'apnum=');
         strPODConfigIDToBeReplaced = GetAPNumToBeReplaced($('.ServiceBlock').html(),'PODConfigID=');
         
         var regex = new RegExp(strAPNumToBeReplaced, "g");
         $('.ServiceBlock').html($('.ServiceBlock').html().replace(regex , newString)); //
          var regex1 = new RegExp(strPODConfigIDToBeReplaced, "g");
         $('.ServiceBlock').html($('.ServiceBlock').html().replace(regex1 , newPODString)); //
    }
    else
         $('.ServiceBlock').hide();
    if (canCanvasTransfer == "1")
         $('#Canvas').show();
    else
        $('#Canvas').hide();
    if (canMount == "1")
         $('#Mounted').show();
    else
         $('#Mounted').hide();
    if (canLaminate == "1")
         $('#Laminated').show();
    else
         $('#Laminated').hide();
}


function setDLEPODParameters(PODConfigID,DLEApnum,FramingFlag,IsPODSelectionChanged)
{
    var varDLEPopUpParametsId;
        var finalString;
        var DLEframeBlock;
        var DLEframeBlocks;
        var DLEcanFrame;
        
        DLEParentTitleheader =$(".sizeOptionBlockSelected").parents('.PODProductType').find('.PODHeader h3').text();
        varMultiDLEString  = $().find('.MultiplePODDLE').text();
        varDLEPopUpParametsId = $().find('.DLEPopUpParametsId').text()
         var stringtoFind = "currentItemType="+DLEParentTitleheader+",";
         
         var intIndexPOD = 0;
          var intIndexPODto = 0;
         
        intIndexPOD = varMultiDLEString.indexOf(stringtoFind);
        
         intIndexPODto = varMultiDLEString.indexOf("currentItemType=",(intIndexPOD+stringtoFind.length));
         if (intIndexPODto == -1)
         {
            finalString = varMultiDLEString.substring((intIndexPOD+stringtoFind.length),varMultiDLEString.length);
         }
         else
         {
            finalString = varMultiDLEString.substring((intIndexPOD+stringtoFind.length),intIndexPODto);
         }
        
         if (finalString.indexOf("PODConfigId="+PODConfigID+",") > 0)
         {
   
            var stringDefaultDLEImage;
            var stringReplaceDefaultDLEImage;
            if (PODConfigID>0)
            {
                stringDefaultDLEImage = ",isDefaultImage=False,PODConfigId="+PODConfigID+",";
                stringReplaceDefaultDLEImage = ",isDefaultImage=True,PODConfigId="+PODConfigID+",";
             }
             else
             {
                finalString = finalString.replace( "isDefaultImage=True", "isDefaultImage=False");
                
                var apnumindex = finalString.indexOf("ImageAPNUM="+DLEApnum+",")
                var apnumindexto = finalString.indexOf(",isDefaultImage=",apnumindex);
                stringDefaultDLEImage = finalString.substring(apnumindex,apnumindexto)+",isDefaultImage=False";
                stringReplaceDefaultDLEImage = finalString.substring(apnumindex,apnumindexto)+",isDefaultImage=True";
                
                
                
             }
              finalString = finalString.replace( stringDefaultDLEImage, stringReplaceDefaultDLEImage);
                      
             var varpopdlefunctionString;
             
            var intDLEStrIndex  =0;
            var intDLEStrNewIndex  =0;
            
             intDLEStrIndex = varDLEPopUpParametsId.indexOf(",");
             var varDLECID =  varDLEPopUpParametsId.substring(0,intDLEStrIndex);  
             
             
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1);         
             var varDLEImageDir =  varDLEPopUpParametsId.substring(intDLEStrIndex+1,intDLEStrNewIndex);
             
             intDLEStrIndex = intDLEStrNewIndex+1;
             
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
//             var varDLEAPNum =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
var varDLEAPNum =  DLEApnum;
             
             intDLEStrIndex = intDLEStrNewIndex+1;
             
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varDLETrackingPath =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
             intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varDLEImageId =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);

            intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varDFLEDomainURL =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);

             intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varDLECountryCode =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
             intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varDLEFramingServicePath =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
             intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varCustomerZoneid =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
              intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varLanguageId =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
              intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varCurrencyId =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
              intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varCurrencyCode =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
              intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var varUnitofMeasure =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
             intDLEStrIndex = intDLEStrNewIndex+1;
             intDLEStrNewIndex = varDLEPopUpParametsId.indexOf(",",intDLEStrIndex+1); 
             var vardefaultframedetail =  varDLEPopUpParametsId.substring(intDLEStrIndex,intDLEStrNewIndex);
             
             intDLEStrIndex = intDLEStrNewIndex+1;
             var varDLECurrencyDisplaySymbol =  varDLEPopUpParametsId.substring(intDLEStrIndex,varDLEPopUpParametsId.length);
             
             
             
 if (FramingFlag == 'True') 
              {
             $('#dleIcon').show();
             $('#A1').css('display', 'block');
	     }
             else
             {
                $('#dleIcon').hide();
                $('#A1').css('display', 'none');
             }
             if (IsPODSelectionChanged == true)
             {
                $('#DLELink').unbind('click');
                $('#DLELink1').unbind('click');
                $('#A1').unbind('click');
             }
              
               
             $('#DLELink').bind('click',function(){
                      javascript:popDLE(finalString,varDLECID,varDLEImageDir,varDLEAPNum,varDLETrackingPath,varDLEImageId,varDFLEDomainURL,varDLECountryCode,varDLEFramingServicePath,varCustomerZoneid,varLanguageId,varCurrencyId,varCurrencyCode,varUnitofMeasure,vardefaultframedetail,varDLECurrencyDisplaySymbol);
                       });
                       
             $('#DLELink1').bind('click',function(){
                      javascript:popDLE(finalString,varDLECID,varDLEImageDir,varDLEAPNum,varDLETrackingPath,varDLEImageId,varDFLEDomainURL,varDLECountryCode,varDLEFramingServicePath,varCustomerZoneid,varLanguageId,varCurrencyId,varCurrencyCode,varUnitofMeasure,vardefaultframedetail,varDLECurrencyDisplaySymbol);
                       });
                       
            $('#A1').bind('click',function(){
                      javascript:popDLE(finalString,varDLECID,varDLEImageDir,varDLEAPNum,varDLETrackingPath,varDLEImageId,varDFLEDomainURL,varDLECountryCode,varDLEFramingServicePath,varCustomerZoneid,varLanguageId,varCurrencyId,varCurrencyCode,varUnitofMeasure,vardefaultframedetail,varDLECurrencyDisplaySymbol);
                       });
          
         }
         else
         {
            $('#dleIcon').hide();
            $('#A1').css('display', 'none');
         }
         
         
        if ( (!($('#dleIcon').is(':visible') )) || FramingFlag == 'False')
        {
		    var DLEiw = $("#mainImage").attr('width');
		   
		     $('.enlarge').css('width',(DLEiw/2)+28);
		     $('.enlarge').css('position','static');
		}
		else 
		{		 
		    var newEnlargePosition = $('#A1').position().left;
		    $('.enlarge').css('position','absolute');
		    $('.enlarge').css('left',newEnlargePosition);
		    $('.enlarge').css('width','100px');
	    }
                   
}

//Rolling Stone
function RollingStoneDetailsWindow(numIssues,value) 
{
	if (numIssues == '')
		numIssues = '12';
	if (value == '')
		value = '$6.48';
	StonesWindow=window.open('','RollingStoneOffer','height=400,width=450,resizable=yes,top=100,left=100');
	var tmp = StonesWindow.document;
	tmp.write('<html><head><title>Allposters.com</title>');
	tmp.write('</head><body><p style=\"font-family:Verdana;font-size:12px;\"><b>Your Rolling Stone Authentic cover reprint comes with a '+numIssues+'-issue subscription to Rolling Stone. That\'s a '+value+' value already covered in your purchase price!</b></p>');
	tmp.write('<p style=\"font-family:Verdana;font-size:12px;\">For new subscribers (only) this means '+numIssues+' issues to see why Rolling Stone Magazine has been the official Rock and Roll chronicler for over 4 decades.</p>');
    tmp.write('<p style=\"font-family:Verdana;font-size:12px;\">If at anytime within thirty days of this purchase you want to cancel Rolling Stone and get a rebate for this year\'s subscription allocation, you must print, fill out, and mail in this form with a copy of your Rolling Stone Authentic receipt to: Rolling Stone Refund, PO Box 8243, Red Oak, IA 51591. The subscription allocation on this purchase is '+value+'. Fill out the below if you do NOT want your subscription:</p>');
    tmp.write('Name_________________________________<br>');
    tmp.write('Address_______________________________<br>');
    tmp.write('City, State, ZIP___________________________<br>');
    tmp.write('<p style=\"font-family:Verdana;font-size:12px;\">Limit one per household. Offer will be valid for new Rolling Stone subscribers residing in the US only.</p>');
	tmp.write('</body></html>');
	tmp.close();
}