var dragSettings = {

    zIndex:     1000,

    ghosting:   true,

    opacity:    0.7,

    revert: true

}



var imageWidth = 0;

var imageHeight = 0;

var settings_maxWidth = 0;

var settings_maxHeight = 0;



$(function() {

    $("#framingBasket img").Draggable(dragSettings);



    $("#framing_area").Droppable({

        ondrop: function(drag) {

            setFramingImage($(drag).attr("src"), parseInt(drag.id));

        },

        accept: "framingBasketItem",

        tolerance: 'intersect'

    });



    $('#options_container').tabs({

        fxFade: true,

        fxSpeed: 'fast'

    });



    $("#framingBasketBin").Droppable({

        ondrop: function(drag) {

            $("#"+drag.id).remove();

            $.get("framing_basket.php",{action: 'removeFrameBasket',photoId: parseInt(drag.id)});

        },

        accept: "framingBasketItem",

        tolerance: 'intersect'

    });



    $("#matAllWidthWhole").change(function() {

        var size = $(this).val();

        $(".matWidthWholeSelector").each(function() {

            $(this).val(size);

        });

    });



    $("#matAllWidthFract").change(function() {

        var size = $(this).val();

        $(".matWidthFractSelector").each(function() {

            $(this).val(size);

        });

    });



    var aspectRatioWidth = function() {



        if($("#preserveAspectRatio").attr("value")) {

            var width = fractDec($("#photoWidthWhole").val(), $("#photoWidthFract").val());

            var newHeight = imageHeight/imageWidth * width;



            newHeight = ""+newHeight;

            var dotPos = newHeight.lastIndexOf(".");

            if(dotPos >= 0) {

                var whole = newHeight.substr(0, dotPos);

                var fract = newHeight.substr(dotPos);

            } else {

                var whole = newHeight;

                var fract = 0;

            }



            if(whole > 84) {

                //alert("You cannot select this size because it would mean that the height would be outside of the range we accomodate.  Please reduce the width.");

            } else {

                $("#photoHeightWhole").val(whole);

                var maxFract = "0/8";

                $("#photoHeightFract option").each(function(){

                    if(eval($(this).val()) <= fract) {

                        maxFract = $(this).val();

                    }

                });


                $("#photoHeightFract").val(maxFract);

            }

        }

    }



    var aspectRatioHeight = function() {



        if($("#preserveAspectRatio").attr("value")) {

            var height = fractDec($("#photoHeightWhole").val(), $("#photoHeightFract").val());

            var newWidth = imageWidth/imageHeight * height;



            newWidth = ""+newWidth;

            var dotPos = newWidth.lastIndexOf(".");

            if(dotPos >= 0) {

                var whole = newWidth.substr(0, dotPos);

                var fract = newWidth.substr(dotPos+1);

            } else {

                var whole = newWidth;

                var fract = 0;

            }



            if(whole > 40) {

                //alert("You cannot select this size because it would mean that the width would be outside of the range we accomodate.  Please reduce the height.");

            } else {

                $("#photoWidthWhole").val(whole);

                var maxFract = "0/8";

                $("#photoWidthFract option").each(function(){

                    if(eval($(this).val()) <= fract) maxFract = $(this).val();

                });

                $("#photoWidthFract").val(maxFract);

            }

        }



    }



    var settings_maxDimExec = function() {

        var widthWhole;

        var widthFract;

        var heightWhole;

        var heightFract;

        var imageID = $("#framing_image img").attr("id");



        $.get("image_dimensions.php",{id: imageID.substr(0, imageID.indexOf("fr"))}, function(data) {

            eval(data);
          /*alert(widthWhole);
          alert(widthFract);*/

            var settings_maxWidth = fractDec(widthWhole, widthFract);
            //alert(settings_maxWidth);
            var tempWidth = fractDec($("#photoWidthWhole").val(), $("#photoWidthFract").val());
            //alert(tempWidth);
            if(widthWhole > 0 && widthFract.length > 0 && tempWidth >= settings_maxWidth) {

                settings_maxWidth = ""+settings_maxWidth;



                var dotPos = settings_maxWidth.lastIndexOf(".");

                if(dotPos >= 0) {

                    var whole = settings_maxWidth.substr(0, dotPos);

                    var fract = settings_maxWidth.substr(dotPos);

                } else {

                    var whole = settings_maxWidth;

                    var fract = 0;

                }



                $("#photoWidthWhole").val(whole);
              //  alert( $("#photoWidthWhole").val());
                var maxFract = "0/8";

                $("#photoWidthFract option").each(function(){

                    if(eval($(this).val()) <= fract) maxFract = $(this).val();

                });

                $("#photoWidthFract").val(maxFract);

            }



            var settings_maxHeight = fractDec(heightWhole, heightFract);

            var tempHeight = fractDec($("#photoHeightWhole").val(), $("#photoHeightFract").val());

            if(heightWhole > 0 && heightFract.length > 0 && tempHeight >= settings_maxHeight) {

                settings_maxHeight = ""+settings_maxHeight;



                var dotPos = settings_maxHeight.lastIndexOf(".");

                if(dotPos >= 0) {

                    var whole = settings_maxHeight.substr(0, dotPos);

                    var fract = settings_maxHeight.substr(dotPos);

                } else {

                    var whole = settings_maxHeight;

                    var fract = 0;

                }



                $("#photoHeightWhole").val(whole);

                var maxFract = "0/8";

                $("#photoHeightFract option").each(function(){

                    if(eval($(this).val()) <= fract) maxFract = $(this).val();

                });

                $("#photoHeightFract").val(maxFract);

            }

        });

    }



    $("#photoWidthWhole").change(function() {

        if($("#photoWidthWhole").val() > 39) $("#photoWidthFract").val("0/8");

    });



    $("#photoWidthFract").change(function() {

        if($("#photoWidthWhole").val() > 39) $("#photoWidthFract").val("0/8");

    });



    $("#photoHeightWhole").change(function() {

        if($("#photoHeightWhole").val() > 39) $("#photoHeightFract").val("0/8");

    });



    $("#photoHeightFract").change(function() {

        if($("#photoHeightWhole").val() > 39) $("#photoHeightFract").val("0/8");

    });



    $("#photoWidthWhole").change(aspectRatioWidth);

    $("#photoWidthFract").change(aspectRatioWidth);

    $("#photoHeightWhole").change(aspectRatioHeight);

    $("#photoHeightFract").change(aspectRatioHeight);



    $("#photoWidthWhole").change(settings_maxDimExec);

    $("#photoWidthFract").change(settings_maxDimExec);

    $("#photoHeightWhole").change(settings_maxDimExec);

    $("#photoHeightFract").change(settings_maxDimExec);



    var curFrameImage = $("#framing_image img").attr("src");

    if(curFrameImage) {

        $.get("image_dimensions.php",{image: curFrameImage.substr(curFrameImage.lastIndexOf("/")+1)}, function(data) {

            eval(data);

        });

    }

});



function fractDec(whole, fract) {

    divPos = fract.lastIndexOf("/");
    //alert(divPos);
    numerator = fract.substr(0, fract.length-divPos-1);

    if(numerator.indexOf("/"))
        numerator = numerator.replace("/", "")
    //alert(numerator);
    denom = fract.substr(divPos+1);
    //alert(denom);
    return (whole/1) + (numerator/denom);

}



function setFramingImage(src, id) {

    updateFrameingImage(src, id);

    $.get("package_basket.php",{action: 'addPhoto', photoId: id}, function(data) {

        $("#packageBasketContainer").html(data);

        $.get("./frame_elements/max_image_size.php",{}, function(data) {

            $("#maxSizeNote").html(data);

        });

    });

}



function updateFrameingImage(src, id) {

    var img = src.substr(src.lastIndexOf("/")+1);

    $("#framing_image").empty();

    $("#framing_image").append("<img src='images/photos/medium/"+img+"' id='" + id + "frameingAreaImage' >");



    $.get("image_dimensions.php",{image: img}, function(data) {

        eval(data);



        /*

        if(imageWidth > imageHeight) {

            $("#framing_image img").css("width", "445px").css("height", "344px").css("margin", "50px 0 0 50px");

        } else {

            $("#framing_image img").css("width", "344px").css("height", "445px").css("margin", "0 0 0 100px");

        }

         */



        if(imageWidth > imageHeight) {

            //var tmpImgWidth = 455;

            var tmpImgWidth = 430;

            tmpImgHeight = Math.ceil((imageHeight/imageWidth) * tmpImgWidth);

        } else {

            //var tmpImgHeight = 455;

            var tmpImgHeight = 450;

            tmpImgWidth = Math.ceil((imageWidth/imageHeight) * tmpImgHeight);

        }



        var marginLeft = Math.ceil((550-tmpImgWidth)/2);

        var marginTop = Math.ceil((460-tmpImgHeight)/2);

        $("#framing_image img").css("width", tmpImgWidth+"px").css("height", tmpImgHeight+"px").css("margin", marginTop+"px 0 0 "+marginLeft+"px");

        //$("#framing_image img").css("margin", marginTop+"px 0 0 "+marginLeft+"px");

        //$("#framing_image img").css("width", (imageWidth *0.6)+"px").css("height", (imageHeight*0.6) +"px").css("margin", "50px 0 0 50px");



    });

}



function selectFrameCategory(frameCategoryId) {

    $.get("frame_elements/frame_select_frame.php",{frameCategoryId: frameCategoryId}, function(data) {

        $("#frameOptions").html(data);

    });

}



function resetFrameSelection() {

    $.get("frame_elements/frame_select_category.php",{}, function(data) {

        $("#frameOptions").html(data);

    });

}



function selectFrame(frameId) {

    $.get("package_basket.php",{action: 'addFrame', frameId: frameId}, function(data) {

        $("#packageBasketContainer").html(data);

        updateImage();

        updatePrice();

    });

}



function removeFrame() {

    $.get("package_basket.php",{action: 'removeFrame'}, function(data) {

        $("#packageBasketContainer").html(data);

        updateImage();

        updatePrice();

    });

}



function selectMat(matColorId) {

    $.get("./package_basket.php",{

        action: 'addMat',

        //matColorId: $("#matColor").val(),

        matColorId: matColorId,

        topWidthWhole: $("#matTopWidthWhole").val(),

        topWidthFract: $("#matTopWidthFract").val(),

        bottomWidthWhole: $("#matBottomWidthWhole").val(),

        bottomWidthFract: $("#matBottomWidthFract").val(),

        leftWidthWhole: $("#matLeftWidthWhole").val(),

        leftWidthFract: $("#matLeftWidthFract").val(),

        rightWidthWhole: $("#matRightWidthWhole").val(),

        rightWidthFract: $("#matRightWidthFract").val()

    },

    function(data) {

        $("#packageBasketContainer").html(data);

        updateImage();

        updatePrice();

        //matColorsWin.close();

    });



    $.get("../package_basket.php",{

        action: 'addMat',

        //matColorId: $("#matColor").val(),

        matColorId: matColorId,

        topWidthWhole: $("#matTopWidthWhole").val(),

        topWidthFract: $("#matTopWidthFract").val(),

        bottomWidthWhole: $("#matBottomWidthWhole").val(),

        bottomWidthFract: $("#matBottomWidthFract").val(),

        leftWidthWhole: $("#matLeftWidthWhole").val(),

        leftWidthFract: $("#matLeftWidthFract").val(),

        rightWidthWhole: $("#matRightWidthWhole").val(),

        rightWidthFract: $("#matRightWidthFract").val()

    },

    function(data) {

        $("#packageBasketContainer").html(data);

        updateImage();

        updatePrice();

        //matColorsWin.close();

    });

}



function removeMat() {

    $.get("package_basket.php",{action: 'removeMat'}, function(data) {

        $("#packageBasketContainer").html(data);

        updateImage();

        updatePrice();

    });

}



function selectTopMat(matColorId) {

    $.get("./package_basket.php",{

        action: 'addTopMat',

        //topMatColorId: $("#topMatColor").val(),

        topMatColorId: matColorId,

        topWidthWhole: $("#matOffsetWidthWhole").val(),

        topWidthFract: $("#matOffsetWidthFract").val()

    },

    function(data) {

        $("#packageBasketContainer").html(data);

        updateImage();

        updatePrice();

        //topMatColorsWin.close();

    });



    $.get("../package_basket.php",{

        action: 'addTopMat',

        //topMatColorId: $("#topMatColor").val(),

        topMatColorId: matColorId,

        topWidthWhole: $("#matOffsetWidthWhole").val(),

        topWidthFract: $("#matOffsetWidthFract").val()

    },

    function(data) {

        $("#packageBasketContainer").html(data);

        updateImage();
		updatePrice();
        //topMatColorsWin.close();

    });

}



function removeTopMat() {

    $.get("package_basket.php",{action: 'removeTopMat'}, function(data) {

        $("#packageBasketContainer").html(data);

        updateImage();

        updatePrice();

    });

}



function selectPhotoSize() {

    $.get("package_basket.php",{

        action: 'addPhotoSize',

        widthWhole: $("#photoWidthWhole").val(),

        widthFract: $("#photoWidthFract").val(),

        heightWhole: $("#photoHeightWhole").val(),

        heightFract: $("#photoHeightFract").val()

    },

    function(data) {

        $("#packageBasketContainer").html(data);

        updatePrice();

    });

}



function removePhotoSize() {

    $.get("package_basket.php",{action: 'removePhotoSize'}, function(data) {

        $("#packageBasketContainer").html(data);

    });

}



function selectPaperType(id, type) {

    /*

    $(document).ajaxError(function(x,r,e) {

        for (var prop in x) {

            alert(prop+":"+x[prop])

        }

    });

     */

    //window.location = "package_basket.php?action=addPaperType&paperTypeId="+id;



    if(type == "canvas") {

        $("#canvasOptions").show();

    } else {

        $("#canvasOptions").hide();

        $("#galleryWrapOptions").hide();

    }





    $.get("package_basket.php",{

        action: 'addPaperType',

        paperTypeId: id

    },

    function(data) {

        $("#packageBasketContainer").html(data);

        updatePrice();

    });

}



function selectCanvasType(type) {

    if(type == "Stretch Mount") {

        $("#galleryWrapOptions").hide();

        $.get("package_basket.php",{

            action: 'addFinishingKit',

            finishingKitId: 2

        },

        function(data) {

            $("#packageBasketContainer").html(data);

            updatePrice();

        });

    } else {

        $("#galleryWrapOptions").show();

    }

}



function selectBorderType(type) {

    if(type == "Solid Black") finishingKitId = 3

    if(type == "Solid White") finishingKitId = 4

    if(type == "Continuous Mirrored Image") finishingKitId = 5



    $.get("package_basket.php",{

        action: 'addFinishingKit',

        finishingKitId: finishingKitId

    },

    function(data) {

        $("#packageBasketContainer").html(data);

        updatePrice();

    });

}



function choosePaperType(sku, id) {

    $("#"+sku).attr("checked", true);

    selectPaperType(id);

}



function removePaperType() {

    $.get("package_basket.php",{action: 'removePaperType'}, function(data) {

        $("#packageBasketContainer").html(data);

        updatePrice();

    });

}



function updatePrice() {

    $.get("package_basket.php",{action: 'updatePrice'}, function(data) {

        $("#packageBasketContainer").html(data);

        $("#you_may_begin").empty();

        update_descCol();

    });



}



function update_descCol() {

    var elements = document.getElementsByTagName("td");

    var retVal = new Array();

    for(var i = 0;i < elements.length;i++) {

        if(elements[i].className == 'descCol' || elements[i].className == 'price' || elements[i].className == 'removeBut') retVal.push(elements[i]);

    }

    if(retVal.length > 0) {

        //for(i in retVal) {

        for(i=0; i<retVal.length;i++) {

            if(i % 2) {

                //alert(retVal[j].className);

                retVal[i].style.backgroundColor = '#eeeeee';

                retVal[i-1].style.backgroundColor = '#eeeeee';

                retVal[i+1].style.backgroundColor = '#eeeeee';

                i = i+4;

            }

        }

    }

}



function refreshPackage() {

    $.get("package_basket.php",{action: 'refresh'}, function(data) {

        $("#packageBasketContainer").html(data);

        $("#framing_image").empty();

    });

}



function addOrder(id) {

    $.get("frame_elements/validate_package_basket.php",{}, function(data) {

        if(data != "valid") {

            alert(data);

        } else {

            $.get("order_controller.php",{action: "addPackageBasket", packageBasketId: + id}, function(data) {

                //alert(data)

                if(confirm("Package added to order.  Press 'OK' to view the cart and proceed with the purchase or press 'Cancel' to continue shopping.")) {

                    window.open('https://www.lenscapesllc.com/framing_interface/order_controller.php', 'viewOrder');

                }

            });

        }

    });



    //window.open('order_controller.php?action=addPackageBasket&packageBasketId='+id, 'viewOrder', 'width=600,height=635');

}



function viewOrders() {

    window.open('http://www.lenscapesllc.com/framing_interface/order_controller.php', 'viewOrder');

}



var chartWindow;

function openWallColor() {

    chartWindow = window.open('frame_elements/wall_color.php', 'wallColor', 'width=600,height=635, top=20,left=650');

}

/*
	Start Cookie Functions Added by Thomas Forrester
*/
function getMyCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setMyCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkMyCookie(cname)
{
/*
	username=getCookie('username');
	if (username!=null && username!="")
	  {
	  alert('Welcome again '+username+'!');
	  }
	  else
	  {
	  username=prompt('Please enter your name:',"");
	  if (username!=null && username!="")
		{
		setCookie('username',username,365);
		}
	 }
*/
}

function setWallColor_pageloaded(){

	var WallColor = getMyCookie('WallColor');
	if (WallColor != null){
		$("#framing_area").css("background-color",WallColor);
	}
	
}

/*
	End Cookie Functions Added by Thomas Forrester
*/

function setFrameBackground(bgColor, close) {

    $("#framing_area").css("background-color",bgColor);
	setMyCookie('WallColor',bgColor,365);
    if(close) chartWindow.close();

}

function getFrameBackground() {

    return $("#framing_area").css("background-color");

}



var matColorsWin;

function openMatColors() {

    matColorsWin=window.open('frame_elements/mat_colors.php?mat=bottom', 'matColors', 'width=450, height=800, scrollbars, top=20,left=650');

}



var topMatColorsWin;

function openTopMatColors() {

    topMatColorsWin=window.open('frame_elements/mat_colors.php?mat=top', 'topMatColors', 'width=450, height=800, scrollbars, top=20,left=650');

}



function openPaperLearn(sku) {

    var paperURL = (sku) ? "paper.php#"+sku : "paper.php";

    window.open(paperURL, 'paperLearn', 'width=450, scrollbars');

}



function searchFrame() {

    $.get("frame_elements/select_frame.php",{

        action: 'displayFrames',

        frameType: $("#frameType").val(),

        frameWidth: $("#frameWidth").val(),

        frameRabbet: $("#frameRabbet").val(),

        frameColor: $("#frameColor").val(),

        frameStyle: $("#frameStyle").val()

    },

    function(data) {

        $("#selectFrameContainer").html(data);

        $(".frameImage").hover(function() { $(this).css("cursor", "pointer");}, function() {});

    });

}



function profileFrame(url) {

    window.open(url, "profileFrame", 'width=250,height=130');

}



function largeFrame(url) {

    //window.open(url, url, 'width=510,height=510');

    window.open(url, "largeFrame", 'width=510,height=510');

}



function uploadImage() {

    var imageName = $("#uploadPhoto").val();

    if(imageName) {

        var imageExt = imageName.substr(imageName.lastIndexOf(".")).toLowerCase();

        if(imageExt != ".jpg") {

            alert("You are only allowed to upload jpg images.")

            return;

        }



        $("#uploadExt").val(imageExt);

        $("#imageUploadForm").ajaxSubmit(function(data) {

            eval(data);

            var found = false;

            var itemCount = 0;

            $("#framingBasket img").each(function() { if(this.src == drag.src) found=true; itemCount++; } )


/*
            if(itemCount >= 8) {

                alert("Only 8 photos are allowed in the cart at one time.  Please remove some before trying again.");
				auto_add_photos_clear(); //Added by Thomas Forrester
                return;

            }
*/


            if(!found) {

                $.get("framing_basket.php",{action: 'addFrameBasket',photoId: drag.id, addFrameLink: false}, function(data) {

                    var tmpItem = document.createElement("div");

                    tmpItem.innerHTML = data;

                    $("#framingBasket").empty();

                    $("#framingBasket").append($("#framingBasket",tmpItem).html());

                    $("#framingBasket img").Draggable(dragSettings);

                });

            }

        });

    }

}



function updateImage() {



        if(imageWidth > imageHeight) {

            var frameImageWidth = 460;

            frameImageHeight = Math.ceil((imageHeight/imageWidth) * frameImageWidth);

            //alert(frameImageHeight)

        } else {

            var frameImageHeight = 450;

            frameImageWidth = Math.ceil((imageWidth/imageHeight) * frameImageHeight);

        }

//alert(frameImageWidth+":"+frameImageHeight);

//alert(imageWidth+":"+imageHeight);

        var marginLeft = Math.ceil((550-frameImageWidth)/2);

        var marginTop = Math.ceil((460-frameImageHeight)/2);

    if(imageWidth) {

        $.get("framing_area.php",{action: 'updateImage', width: frameImageWidth, height: frameImageHeight}, function(data) {

            var id = $("#framing_image img").attr("id");

            var dimension;



            dimension = data.substring(data.indexOf("maxH")+5,data.indexOf("&com."));

            if(dimension > 400) dimension = 400;

            dimension = " height:"+dimension+"px;";



            var imageName = id.substr(0,id.lastIndexOf("frameing"))+"userPhoto.jpg";

            $("#framing_image").empty();

            $("#framing_image").html("<img src='"+data+"' id='"+id+"' title='"+imageName+"' style='"+dimension+" margin-left:"+marginLeft+"; margin-top:"+marginTop+";' />");

        });

    }

}



function enlargeImage() {

    if(imageWidth > imageHeight) {

        var largePhotoWin = window.open("larger_view.php", "largePhoto", 'width=1000,height=800');

    } else {

        var largePhotoWin = window.open("larger_view.php", "largePhoto", 'width=800,height=1000');

    }

}



function editImage() {



    /*var src = $("#framing_image img").attr("src");

    src = src.substr(src.lastIndexOf("/")+1);*/

    var imageName = $("#framing_image img").attr("title");

    var id = parseInt($("#framing_image img").attr("id"));



    //var ff_image_url = "http://www.lenscapesllc.com/framing_interface/web/images/photos/large/" + src;

    //var ff_callback_url = "http://www.lenscapesllc.com/framing_interface/web/fhotoflexerCallback.php?photoId="+id;

    //var ff_logo_url = "http://www.lenscapesllc.com/framing_interface/web/images/LenscapesLogoFhotoFlexer.png";

    var ff_image_url = "http://www.jessevista.com/~lenscapes/images/photos/large/" + imageName;

    var ff_callback_url = "http://www.jessevista.com/~lenscapes/fhotoflexerCallback.php?photoId="+id;

    var ff_logo_url = "http://www.jessevista.com/~lenscapes/images/LenscapesLogoFhotoFlexer.png";

    window.location="http://fotoflexer.com/API/API_Loader.php?ff_image_url="+ff_image_url+"&ff_callback_url="+ff_callback_url+"&ff_logo_url="+ff_logo_url;

}



function showMaxImageSize() {

    window.open("./frame_elements/max_image_size.php", "maxImageSize", 'width=250,height=200');

}



function openHelp(anch) {

    window.open("./help.html#"+ anch);

}



function disableMat(handle) {

    obj = document.forms["select_mat"].elements;

    msg = document.getElementById("mat_message");



    for(i=0;i<obj.length;i++) {

        obj[i].disabled = handle;

    }

    if(handle) {

        $.get("package_basket.php",{action: 'removeMat'}, function(data) {

            $("#packageBasketContainer").html(data);

        });



        $.get("package_basket.php",{action: 'removeTopMat'}, function(data) {

            $("#packageBasketContainer").html(data);

            updateImage();

            updatePrice();

        });

        $("#mat_message").html("You cannot select a Matting because you have chosen a canvas paper.");

        $("#mat_message").show();

    } else {

        $("#mat_message").html("");

        $("#mat_message").hide();

    }



}



function removeFramingBasket(id) {

    $("#remove_"+id).remove();

    $.get("framing_basket.php",{action: 'removeFrameBasket',photoId: id});

}



function addFramingBasket(id) {

    var found = false;

    var itemCount = 0;

    var drag = document.createElement('img');



    $.get("framing_basket.php",{action: 'getImageName',photoId: id}, function(data) {

        drag.src='../'+data;

        drag.id=id;

    })



    $("#framingBasket img").each(function() { if(this.src == drag.src) found=true; itemCount++; } )


/*
    if(itemCount >= 8) {

        alert("Only 8 photos are allowed in the cart at one time.  Please remove some before trying again.");
		auto_add_photos_clear(); //Added by Thomas Forrester
        return;

    }
*/

    if(!found) {

        $.get("framing_basket.php",{action: 'addFrameBasket',photoId: id, addFrameLink: false}, function(data) {

            var tmpItem = document.createElement("div");

            tmpItem.innerHTML = data;

            $("#framingBasket").empty();

            $("#framingBasket").append($("#framingBasket",tmpItem).html());

            $("#framingBasket img").Draggable(dragSettings);

            remove_from_frame_list(id);

        });

    }

}

/* Added by Thomas Forrester */

function getObject(oID){
    if (document.getElementById || document.all)
    {
        var obj = document.getElementById? document.getElementById(oID): document.all[oID];
        return obj;
    }
	return new Object(); //Don't fail if used
}

function setFramingImageOnClick(oID){
    
   var myObj = getObject(oID);
   setFramingImage($(myObj).attr("src"), parseInt(myObj.id));
   selectPhotoSize();
}