(function (e) { e.fn.orbit = function (a) { a = e.extend({ animation: "horizontal-push", animationSpeed: 600, timer: true, advanceSpeed: 4E3, pauseOnHover: false, startClockOnMouseOut: false, startClockOnMouseOutAfter: 1E3, directionalNav: true, captions: true, captionAnimation: "fade", captionAnimationSpeed: 600, bullets: false, bulletThumbs: false, bulletThumbLocation: "", afterSlideChange: function () { } }, a); return this.each(function () { function t() { if (!a.timer || a.timer == "false") return false; else if (u.is(":hidden")) v = setInterval(function () { o("next") }, a.advanceSpeed); else { r = true; A.removeClass("active"); v = setInterval(function () { var d = "rotate(" + p + "deg)"; p += 2; w.css({ "-webkit-transform": d, "-moz-transform": d, "-o-transform": d }); if (p > 180) { w.addClass("move"); B.addClass("move") } if (p > 360) { w.removeClass("move"); B.removeClass("move"); p = 0; o("next") } }, a.advanceSpeed / 180) } } function q() { if (!a.timer || a.timer == "false") return false; else { r = false; clearInterval(v); A.addClass("active") } } function C() { if (!a.captions || a.captions == "false") return false; else { var d = c.eq(b).data("caption"); if (_captionHTML = e(d).html()) { l.attr("id", d).html(_captionHTML); a.captionAnimation == "none" && l.show(); a.captionAnimation == "fade" && l.fadeIn(a.captionAnimationSpeed); a.captionAnimation == "slideOpen" && l.slideDown(a.captionAnimationSpeed) } else { a.captionAnimation == "none" && l.hide(); a.captionAnimation == "fade" && l.fadeOut(a.captionAnimationSpeed); a.captionAnimation == "slideOpen" && l.slideUp(a.captionAnimationSpeed) } } } function D() { if (a.bullets) F.children("li").removeClass("active").eq(b).addClass("active"); else return false } function o(d) { function g() { c.eq(m).css({ "z-index": 1 }); x = false; a.afterSlideChange.call(this) } var m = b, h = d; if (m == h) return false; if (c.length == "1") return false; if (!x) { x = true; if (d == "next") { b++; if (b == s) b = 0 } else if (d == "prev") { b--; if (b < 0) b = s - 1 } else { b = d; if (m < b) h = "next"; else if (m > b) h = "prev" } D(); c.eq(m).css({ "z-index": 2 }); a.animation == "fade" && c.eq(b).css({ opacity: 0, "z-index": 3 }).animate({ opacity: 1 }, a.animationSpeed, g); if (a.animation == "horizontal-slide") { h == "next" && c.eq(b).css({ left: k, "z-index": 3 }).animate({ left: 0 }, a.animationSpeed, g); h == "prev" && c.eq(b).css({ left: -k, "z-index": 3 }).animate({ left: 0 }, a.animationSpeed, g) } if (a.animation == "vertical-slide") { h == "prev" && c.eq(b).css({ top: y, "z-index": 3 }).animate({ top: 0 }, a.animationSpeed, g); h == "next" && c.eq(b).css({ top: -y, "z-index": 3 }).animate({ top: 0 }, a.animationSpeed, g) } if (a.animation == "horizontal-push") { if (h == "next") { c.eq(b).css({ left: k, "z-index": 3 }).animate({ left: 0 }, a.animationSpeed, g); c.eq(m).animate({ left: -k }, a.animationSpeed) } if (h == "prev") { c.eq(b).css({ left: -k, "z-index": 3 }).animate({ left: 0 }, a.animationSpeed, g); c.eq(m).animate({ left: k }, a.animationSpeed) } } C() } } var b = 0, s = 0, k, y, x, j = e(this).addClass("orbit"), f = j.wrap('<div class="orbit-wrapper" />').parent(); j.add(k).width("1px").height("1px"); var c = j.children("img, a img, div"); c.each(function () { var d = e(this), g = d.width(); d = d.height(); if (g > j.width()) { j.add(f).width(g); k = j.width() } if (d > j.height()) { j.add(f).height(d); y = j.height() } s++ }); if (c.length == 1) { a.directionalNav = false; a.timer = false; a.bullets = false } c.eq(b).css({ "z-index": 3 }).fadeIn(function () { c.css({ display: "block" }) }); if (a.timer) { f.append('<div class="timer"><span class="mask"><span class="rotator"></span></span><span class="pause"></span></div>'); var u = e("div.timer"), r; if (u.length != 0) { var w = e("div.timer span.rotator"), B = e("div.timer span.mask"), A = e("div.timer span.pause"), p = 0, v; t(); u.click(function () { r ? q() : t() }); if (a.startClockOnMouseOut) { var E; f.mouseleave(function () { E = setTimeout(function () { r || t() }, a.startClockOnMouseOutAfter) }); f.mouseenter(function () { clearTimeout(E) }) } } } a.pauseOnHover && f.mouseenter(function () { q() }); if (a.captions) { f.append('<div class="orbit-caption"></div>'); var l = f.children(".orbit-caption"); C() } if (a.directionalNav) { if (a.directionalNav == "false") return false; f.append('<div class="slider-nav"><span class="right">Right</span><span class="left">Left</span></div>'); var n = f.children("div.slider-nav").children("span.left"), z = f.children("div.slider-nav").children("span.right"); n.click(function () { q(); o("prev") }); z.click(function () { q(); o("next") }) } if (a.bullets) { f.append('<ul class="orbit-bullets"></ul>'); var F = e("ul.orbit-bullets"); for (i = 0; i < s; i++) { n = e("<li>" + (i + 1) + "</li>"); if (a.bulletThumbs) if (z = c.eq(i).data("thumb")) { n = e('<li class="has-thumb">' + i + "</li>"); n.css({ background: "url(" + a.bulletThumbLocation + z + ") no-repeat" }) } e("ul.orbit-bullets").append(n); n.data("index", i); n.click(function () { q(); o(e(this).data("index")) }) } D() } }) } })(jQuery);
function getE(name) {
    if (document.getElementById)
        var elem = document.getElementById(name);
    else if (document.all)
        var elem = document.all[name];
    else if (document.layers)
        var elem = document.layers[name];
    return elem;
}

function OpenWindow(query, w, h, scroll) {
    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;

    winprops = 'resizable=0, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
    if (scroll) winprops += ',scrollbars=1';
    var f = window.open(query, "_blank", winprops);
}

$(document).ready(function () {

    // Category Listing Popups
    var timeout;
    $(".product-item").hover(function () {
        var t = $(this), p = $(".previewwindow", this);
        t.css({ "border-color": "#7e7262" });
        timeout = setTimeout(function () {
            p.css({ top: -(p.outerHeight() - t.outerHeight()) / 2 + "px", left: -(p.outerWidth(true) - t.outerWidth(true)) / 2 + "px" })
                    .fadeIn();
        }, 800);

    }, function () {
        clearTimeout(timeout);
        $(this).css({ "border-color": "transparent" });
        $(".previewwindow", this).hide();
    });

    // Setup Popup Images
    if ($(".explore-button").length) {
        $(".explore-button").colorbox({ inline: true, href: "#exploreImage" });
    }

    if ($(".explore-button2").length) {
        $(".explore-button2").colorbox({ maxHeight: "90%", showTitle: false });
    }

    // Move Filters to the left
    var filters = $(".product-filters");
    if (filters.length > 0) {
        $(".master-wrapper-leftside-3").append(filters);
    }

    // Move Print Customization
    var custom = $(".product-print-essential");
    if (custom.length > 0) {
        $(".master-wrapper-leftside-3").prepend(custom);
    }
    var item;
    // Move Home page Featured
    var banner = $(".homepage-banner");
    if (banner.length > 0) {
        $(".master-wrapper-content").prepend(banner);
    }

    var virtualRoom;
    if ($(".virtual-room").length > 0)
        virtualRoom = $(".virtual-room").virtualroom();
        
    var compareRoom;
    if ($(".compare-products").length > 0)
        compareRoom = $(".compare-products").compare();
});

jQuery.extend({
    random: function(X) {
        return Math.floor(X * (Math.random() % 1));
    },
    randomBetween: function(MinV, MaxV) {
        return MinV + jQuery.random(MaxV - MinV + 1);
    }
});

jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"], {
    random: function (a, i, m, r) {
        if (i == 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == jQuery.jQueryRandom;
    }
});

(function($) {
    $.fn.extend({
        compare: function(options) {
            var defaults = {};
            var options = $.extend(defaults, options);
            var o = options;
            obj = $(this);
            var LEFT = $(".compare-item-01", obj);
            var RIGHT = $(".compare-item-02", obj);
            var fw;
            var moveTo = {
                left: function()
                {
                    //LEFT.html('');
                    var img = $("img", $(this).parent()).attr("src");
                    var newImg = $(".room-image-holder img", LEFT).attr('src', img);
                    //center($(".virtual-room-large", LEFT));
                    adjust();
                },

                right:function()
                {
                    var c = $(this);
                    //RIGHT.html('');
                    var img = $("img", $(this).parent()).attr("src");
                    var newImg = $(".room-image-holder img", RIGHT).attr('src', img);
                    //center($(".virtual-room-large", RIGHT));
                    adjust();
                }
            };
            var adjust = function()
            {
                $(".virtual-room-large").each(function(){
                    var i = $("img", this);
                    if(i.width() > i.height())
                    {
                        $(i, $(this)).css({width: util.pixelsPerInch(36), height:'auto'});
                        $(this).css({width: util.pixelsPerInch(36), height:'auto'});
                        $(".room-image-outer", $(this)).css({width: util.pixelsPerInch(36), height:i.outerHeight()});
                    }
                    else
                    {
                        $(i, $(this)).css({height: util.pixelsPerInch(36), width:'auto'});
                        $(this).css({height: util.pixelsPerInch(36), width:'auto'});
                        $(".room-image-outer", $(this)).css({width: i.outerWidth(), height:util.pixelsPerInch(36)});
                    }
                    center($(this));
                });
            };

            var frame = {
                change: function()
                {
                    var n = $(this);
                    var p = n.closest("div.compare-box");
                    var b = $("img", n);
                    var i = $(".virtual-room-large img");
                    $(".virtual-room-large .room-image-outer", p).children().css({backgroundImage: "url("+b.attr("src")+")"});
                    adjust();

                    fw = $(".productWidth", n).text().replace(/\$/g,'');
                    frame.adjust(p);
                    center($(".virtual-room-large", p));
                },

                adjust: function(p)
                {
                    var f = $(".virtual-room-large", p);
                    var fe = $(".room-image-outer", f).children();
                    for (var i = 0; i < fe.length; i++)
                    {
                        var e = $(fe[i])
                        var c = e.attr("class");
                        switch(c)
                        {
                            case "room-image-top-left":
                                e.css({
                                    left: -util.pixelsPerInch(fw)+"px", 
                                    width: util.pixelsPerInch(fw)+"px", 
                                    top: -util.pixelsPerInch(fw)+"px", 
                                    height: util.pixelsPerInch(fw)+"px"
                                });
                            break;
                            case "room-image-left":
                                e.css({left: -util.pixelsPerInch(fw)+"px", width: util.pixelsPerInch(fw)+"px"});
                            break;
                            case "room-image-bottom-left":
                                e.css({
                                    left: -util.pixelsPerInch(fw)+"px", 
                                    width: util.pixelsPerInch(fw)+"px", 
                                    bottom: -util.pixelsPerInch(fw)+"px", 
                                    height: util.pixelsPerInch(fw)+"px"
                                });
                            break;

                            case "room-image-top":
                                e.css({top: -util.pixelsPerInch(fw)+"px", height: util.pixelsPerInch(fw)+"px"});
                            break;

                            case "room-image-top-right":
                                e.css({
                                    right: -util.pixelsPerInch(fw)+"px", 
                                    width: util.pixelsPerInch(fw)+"px", 
                                    top: -util.pixelsPerInch(fw)+"px", 
                                    height: util.pixelsPerInch(fw)+"px"
                                });
                            break;

                            case "room-image-right":
                                e.css({right: -util.pixelsPerInch(fw)+"px", width: util.pixelsPerInch(fw)+"px"});
                            break;

                            case "room-image-bottom-right":
                                e.css({
                                    right: -util.pixelsPerInch(fw)+"px", 
                                    width: util.pixelsPerInch(fw)+"px", 
                                    bottom: -util.pixelsPerInch(fw)+"px", 
                                    height: util.pixelsPerInch(fw)+"px"
                                });
                            break;

                            case "room-image-bottom":
                                e.css({bottom: -util.pixelsPerInch(fw)+"px", height: util.pixelsPerInch(fw)+"px"});
                            break;
                        }
                    }
                }
            };

            var center = function(img)
            {
                img.css({top: (img.parent().height() - img.height()) /2, left: (img.parent().outerWidth() - img.outerWidth()) / 2});
            }

            var util = {
                pixelsPerInch: function(i)
                {
                    return Math.round(i * 8);
                }
            }

            var toggle = {
                left: function()
                {
                    $(this).css({ backgroundPosition: "0 0" });
                },
                right: function()
                {
                    $(this).css({ backgroundPosition: "100% 0" });
                },
                none: function()
                {
                    $(this).css({ backgroundPosition: "-1000px" });
                },
                show: function()
                {
                    $(".remove-button", this).show();
                },
                hide: function()
                {
                    $(".remove-button", this).hide();
                }
            }

            var setup = function()
            {
                
            };

            setup();
            // Compare Remove Button
            $(".compare-item", obj).hover(toggle.show,toggle.hide);
            $(".compare-item .compare-right", obj).hover(toggle.right,toggle.none);
            $(".compare-item .compare-right", obj).click(moveTo.right);
            $(".compare-item .compare-left", obj).hover(toggle.left,toggle.none);
            $(".compare-item .compare-left", obj).click(moveTo.left);
            $(".compare-item-01 .product-frame-item, .compare-item-02 .product-frame-item").live("click", frame.change);
            $(".compare-item-01 .product-frame-item:first, .compare-item-02 .product-frame-item:first").trigger("click");
            $(".compare-item img", obj).each(function()
            {
                var a = $(this);
                a.css({top: (a.closest("td.compare-item").outerHeight() - a.outerHeight()) /2 + "px"});
            });
            setTimeout(adjust, 1000);
            adjust();
            return this;
        }
    });
})(jQuery);

// Dynamic Virtual Room Functions
(function ($) {
    $.fn.extend({
        //pass the options variable to the function
        virtualroom: function (options) {

            //Set the default values, use comma to separate the settings, example:
            var defaults = {
                frame:          null,
                orientation:    "horz",
                eyelevel:       222,
                defaultSize:    "16x20",
                // framed, gallery, mounted, loose
                type:           134,
                mouseOutColor:  '#ffffff'
            }

            var fp, //frame price
                fw, //frame width
                fc, //frame total cost
                tf, //total frame in feet
                tp, //total price for full print
                ph, //print height
                pw, //print width
                phl,
                pwl,
                sq, //total square inches
                pc, //cost for print alone
                fl; //frame name
            var obj;
            var ach, acw;
            var printType = $(".attribute-style select");
            var printSize = $(".attribute-size select");
            var viewer;
            var zoomed = false;
            var additionalPrice = 0;
            
            var utils = {
                withFrame: function()
                {
                    if(o.orientation == "horz")
                    {
                        return " w/ frame: " + (parseFloat(fw * 2) + parseFloat(ph/4))+"x"+(parseFloat(fw * 2) + parseFloat(pw/4));
                    }
                    else
                    {
                        return " w/ frame: " + (parseFloat(fw * 2) + parseFloat(pw/4))+"x"+(parseFloat(fw * 2) + parseFloat(ph/4));
                    }
                    return "";
                },
                setTotalCost: function()
                {
                    utils.setFrameCost();
                    utils.setPrintCost();

                    $(".final-type .final-value").text(printType.find(" option:selected").text());
                    $(".attribute-type input").val(printType.find(" option:selected").text());
                    
                    var with_frame = "";
                    if(o.type == "framed")
                    {
                        with_frame = utils.withFrame();
                    }

                    $(".final-size .final-value").text(printSize.find(" option:selected").text() + with_frame);
                    $(".attribute-size input").val(printSize.find(" option:selected").text() + with_frame);

                    $(".final-frame .final-value").text(fl);
                    if(o.type == "framed")
                    {
                        $(".attribute-frame input").val(fl);
                    }
                    else
                    {
                        $(".attribute-frame input").val("None");
                    }
                    
                    $(".final-total .final-total-value").text("$"+(parseFloat(tf) + parseFloat(pc) + parseFloat(additionalPrice)).toFixed(2));
                    $(".one-variant-price .textBox").val((parseFloat(tf) + parseFloat(pc) + parseFloat(additionalPrice)).toFixed(2));
                },

                setFrameCost: function()
                {
                    if(o.type == "framed")
                    {
                       // alert(ach + " + ("+fw + " * 2)) * 2)");
                        var sides = (parseFloat(ach) + parseFloat(fw * 2)) * 2;
                        var top =   (parseFloat(acw) + parseFloat(fw * 2)) * 2;
                        tf = ((sides + top) / 12).toFixed(2);
                        //( + ) / 12);
                    }
                    else
                    {
                        tf = 0;
                    }
                    tf = Math.round(tf * fp);
                },

                setPrintCost: function()
                {
                    pc = (eval("PERSQUAREINCHCCOST_"+o.type) * (sq)).toFixed(2);
                    pc = Math.round(pc);
                }
            };

            var zoom = {
                IN: function()
                {
                    if(!zoomed)
                    {
                        zoomed = true;
                        personal.toggle();
                        personal.determine(position);
                        o.eye = ($(".padder", obj).height() / 4);
                        $(".room-padder", obj).toggleClass("virtual-room-large").removeAttr("style");
                        o.changeThickness();
                        o.center();
                        o.resize($("option:selected", printSize).text().split(' ')[0], false);
                        $(".room-black").fadeIn();
                        o.frame.css({zIndex: 1000});
                    }
                },
                OUT: function()
                {
                    if(zoomed)
                    {
                        zoomed = false;
                        personal.toggle();
                        personal.determine(position);
                        o.eye = 222
                        $(".room-padder", obj).toggleClass("virtual-room-large").removeAttr("style");
                        o.changeThickness();
                        o.center();
                        o.resize($("option:selected", printSize).text().split(' ')[0], false);
                        $(".room-black").fadeOut();
                        o.frame.css({zIndex: 1000});
                    }
                }
            };

            var pixel = {
                small: function(i)
                {
                    // pixels per inch
                    return Math.round(i * 4);
                },

                large: function(i)
                {
                    // pixels per inch
                    return Math.round(i * 8);
                },

                fromSmall: function(i)
                {
                    return Math.round(i / 4);
                }
            };

            var padding = 3;
            var position = "top_left";
            var personalization_image = $(".personalization-text-image").show();
            var personal = {
                position : {
                    top_left:function() {
                        personalization_image.css({ left:padding, right:'auto', top:padding, bottom:'auto', margin:0}).blink();
                        position = "top_left";
                        personalText.validate();
                    },
                    top:function() {
                        personalization_image.css({ left:'50%', right:'auto', top:padding, bottom:'auto', 
                                                    margin:0, marginLeft:-(personalization_image.width() / 2)}).blink();
                        position = "top";
                        personalText.validate();
                    },
                    top_right:function() {
                        personalization_image.css({ left: 'auto', right:padding, top:padding, bottom:'auto', margin:0}).blink();
                        position = "top_right";
                        personalText.validate();
                    },
                    left:function() {
                        personalization_image.css({ left:padding, right:'auto', top:'50%', bottom:'auto', 
                                                    margin:0, marginTop:-(personalization_image.height() / 2)}).blink();
                        position = "left";
                        personalText.validate();
                    },
                    middle:function() {
                        personalization_image.blink();
                    },
                    right:function() {
                        personalization_image.css({ left:'auto', right:padding, top:'50%', bottom:'auto', 
                                                    margin:0, marginTop:-(personalization_image.height() / 2)}).blink();
                        position = "right";
                        personalText.validate();
                    },
                    bottom_left:function() {
                        personalization_image.css({ left:padding, right:'auto', top:'auto', bottom:padding, margin:0}).blink();
                        position = "bottom_left";
                        personalText.validate();
                    },
                    bottom:function() {
                        personalization_image.css({ left:'50%', right:'auto', top:'auto', bottom:padding, 
                                                    margin:0, marginLeft:-(personalization_image.width() / 2)}).blink();
                        position = "bottom";
                        personalText.validate();
                    },
                    bottom_right:function() {
                        personalization_image.css({ left: 'auto', right:padding, top:'auto', bottom:padding, margin:0}).blink();
                        position = "bottom_right";
                        personalText.validate();
                    }
                },
                toggle: function()
                {
                    var p = personalization_image;
                    if(p.hasClass("personalize-small"))
                    {
                        p.removeClass("personalize-small").addClass("personalize-large");
                    }
                    else
                    {
                        p.removeClass("personalize-large").addClass("personalize-small");
                    }
                },

                determine:function(trig)
                {
                    var trig = trig.toString().replace("_", "-");
                    var elem = $(".personalize-placement a[class="+trig+"]")
                        
                    switch(trig)
                    {
                        case "top_left":       elem.trigger("click");    break;
                        case "top":            elem.trigger("click");    break;
                        case "top_right":      elem.trigger("click");    break;

                        case "left":           elem.trigger("click");    break;
                        case "middle":         elem.trigger("click");    break;
                        case "right":          elem.trigger("click");    break;

                        case "bottom_left":    elem.trigger("click");    break;
                        case "bottom":         elem.trigger("click");    break;
                        case "bottom_right":   elem.trigger("click");    break;
                            
                    }
                }
            };

            var personalEnabled = false;
            var personalText = {
                text1:"",
                text2:"",
                text3:"",
                pos1:"print",
                pos2:"cursive",
                pos3:"print",
                toggle:function()
                {
                    $(".attribute-personalize-options").is(":visible")? personalEnabled = false : personalEnabled = true;
                    $(".attribute-personalize-options").toggle();
                    personalText.validate();
                },
                validate:function()
                {
                    if(personalEnabled)
                    {
                        personalization_image.show();
                        additionalPrice = 10;
                        utils.setTotalCost();
                        var filter = "";
                        if(position != "")
                        {
                            filter += "Position:"+position+";";
                        }
                        else
                        {
                            
                            message.error("Please choose a position");
                            this.place("");
                            return false;
                        }
                    
                        if(personalText.text1 != "")
                        {
                            filter += "Text1:"+personalText.text1+";";
                        }
                        else
                        {
                            message.error("Please enter first line of text");
                            this.place("");
                            return false;
                        }

                        if(personalText.pos1 != "")
                        {
                            filter += "Style1:"+personalText.pos1+";";
                        }
                        else 
                        {
                            message.error("Please select cursive or print");
                            this.place("");
                            return false;
                        }

                        if(personalText.text2 != "")
                        {
                            filter += "Text2:"+personalText.text2+";";
                        }
                        else
                        {
                            message.error("Please enter second line of text");
                            this.place("");
                            return false;
                        }

                        if(personalText.pos2 != "")
                        {
                            filter += "Style2:"+personalText.pos2+";";
                        }
                        else 
                        {
                            message.error("Please select cursive or print");
                            this.place("");
                            return false;
                        }

                        if(personalText.text3 != "")
                        {
                            filter += "Text3:"+personalText.text3+";";
                        }
                        else
                        {
                            message.error("Please enter third line of text");
                            this.place("");
                            return false;
                        }

                        if(personalText.pos3 != "") 
                        {
                            filter += "Style3:"+personalText.pos3+";";
                        }
                        else 
                        {
                            message.error("Please select cursive or print");
                            this.place("");
                            return false;
                        }
                        this.place(filter);
                    }
                    else
                    {
                        personalization_image.hide();
                        additionalPrice = 0;
                        this.place("None");
                        utils.setTotalCost();
                    }
                    
                },
                place:function(text)
                {
                   $(".attribute-personalize textarea").val(text);
                },
                print_cursive:function()
                {
                    var e = $(this);
                    e.parent("label").find("a").each(function(){ $(this).removeClass('attribute-personalize-active');});
                    e.addClass('attribute-personalize-active');
                    var num = e.attr("class").replace(/[^0-9]/g, "");
                    var typ = e.attr("class").match(/print/);
                    switch(num)
                    {
                        case '1':
                            personalText.text1 = e.parent("label").find("input[type=text]").val();
                            typ == "print"? personalText.pos1 = 'print':personalText.pos1 = 'cursive';
                        break;
                        case '2':
                            personalText.text2 = e.parent("label").find("input[type=text]").val();
                            typ == "print"? personalText.pos2 = 'print':personalText.pos2 = 'cursive';
                        break;
                        case '3':
                            personalText.text3 = e.parent("label").find("input[type=text]").val();
                            typ == "print"? personalText.pos3 = 'print':personalText.pos3 = 'cursive';
                        break;
                    }
                    personalText.validate();
                },
                addText:function()
                {
                    var e = $(this);
                    var num = e.attr("class").replace(/[^0-9]/g, "");
                   
                    switch(num)
                    {
                        case '1':
                            personalText.text1 = e.val();
                        break;
                        case '2':
                            personalText.text2 = e.val();
                        break;
                        case '3':
                            personalText.text3 = e.val();
                        break;
                    }
                    personalText.validate();
                }
            };

            var message = {
                error:function(msg)
                {
                    var div = $("<div class='message message-error' />").text(msg);
                    this.display(div);
                },
                warning:function()
                {
                    var div = $("<div class='message message-warning' />").text(msg);
                    this.display(div);
                },
                display:function(div)
                {
                    $(".room-errors", obj).append(div);
                    setTimeout(function(){message.hide(div)}, 2500)
                    
                },
                hide:function(div)
                {
                    div.fadeOut(function(){div.remove()});
                }
            }
            
            var options = $.extend({
                center: function()
                {
                    var img = $("img", o.frame);
                    o.frame.css({left: "50%", marginLeft:"-"+(img.width() / 2)+"px"});
                },

                setSize: function(v)
                {                

                    if(!v)
                    {
                        v = o.defaultSize;
                    }
                    
                    var value = v.toString().split("x");
                    if(value[0] > 60 || value[0] < 4 || value[1] > 60 || value[1] < 4) {
                        return false;
                    }
                    if(o.orientation == "horz")
                    {
                        pw = pixel.small(value[1]);
                        ph = pixel.small(value[0]);
                        pwl = pixel.large(value[1]);
                        phl = pixel.large(value[0]);
                        ach = value[0];
                        acw = value[1];
                    }
                    else
                    {
                        pw = pixel.small(value[0]);
                        ph = pixel.small(value[1]);
                        pwl = pixel.large(value[0]);
                        phl = pixel.large(value[1]);
                        ach = value[1];
                        acw = value[0];
                    }
                    
                    sq = value[0] * value[1];
                },

                resize: function(v, fade)
                {
                    var f = o.frame;
                    var img = $("img", o.frame);
                    o.setSize(v);
                    
                    if(fade == true)
                    {
                        f.fadeOut(1000, function(){
                            if(zoomed)
                            {
                                img.css({width:pwl, height:phl});
                                f.css({width:pwl, height:phl, bottom: "50%", marginBottom: -(phl / 2) + "px"}).fadeIn();
                                o.center();
                                $(".virtual-room .room-image-outer").css({width:pwl, height:phl});
                            }
                            else
                            {
                                img.css({width:pw, height:ph});
                                f.css({width:pw, height:ph, bottom: o.eye, marginBottom: -(ph / 2) + "px"}).fadeIn();
                                o.center();
                                $(".virtual-room .room-image-outer").css({width:pw, height:ph});
                            }
                        });
                    }
                    else
                    {
                        if(zoomed)
                        {
                            img.css({width:pwl, height:phl});
                            f.css({width:pwl, height:phl, bottom: "50%", marginBottom: -(phl / 2) + "px"});
                            o.center();
                            $(".virtual-room .room-image-outer").css({width:pwl, height:phl});
                        }
                        else
                        {
                            img.css({width:pw, height:ph});
                            f.css({width:pw, height:ph, bottom: o.eye, marginBottom: -(ph / 2) + "px"});
                            o.center();
                            $(".virtual-room .room-image-outer").css({width:pw, height:ph});
                        }
                    }

                    //$(".virtual-room-large img, .virtual-room-large .room-image-holder").css({width:pwl, height:phl});
                    if(zoomed)
                    {
                        $("span.clicktooltip", f).css({top: (pixel.large(fw)) + phl + "px"});
                    }
                    else
                    {
                        $("span.clicktooltip", f).css({top: (pixel.small(fw)) + ph + "px"}); 
                    }
                    utils.setTotalCost();
                },

                change: function()
                {
                    switch(o.type)
                    {
                        case "framed":
                            $(".room-image-outer", o.frame).fadeIn();
                            //$(".virtual-room-large .room-image-outer").children().show();
                            $(".attribute-frame-options").show();
                            $(".final-frame").show();
                        break;
                        default:
                            $(".room-image-outer", o.frame).fadeOut();
                            //$(".virtual-room-large .room-image-outer").children().hide();
                            $(".attribute-frame-options").hide();
                            $(".final-frame").hide();
                    }
                    utils.setTotalCost();
                },

                switchFrame: function()
                {
                    var f = o.frame;
                    var n = $(this);
                    var b = $("img", n).attr("src");

                    $(".room-image-outer", f).children().css({backgroundImage: "url("+b+")"});
                    //$(".virtual-room-large .room-image-outer").children().css({backgroundImage: "url("+b+")"});
                    // assign new info
                    fp = $(".productPrice", n).text().replace(/\$/g,'');
                    fw = $(".productWidth", n).text().replace(/\$/g,'');
                    fl = $(".product-title a", n).text();
                    o.change();
                    o.changeThickness();
                    utils.setTotalCost();
                    $("span.clicktooltip", f).css({top: (pixel.small(fw)) + ph + "px"}); 
                },

                changeThickness: function()
                {
                    var f = o.frame;
                    var fe = $(".room-image-outer", f).children();
                    switch(zoomed)
                    {
                        case false: 
                            
                            for (var i = 0; i < fe.length; i++)
                            {
                                var e = $(fe[i])
                                var c = e.attr("class");
                                
                                switch(c)
                                {
                                    case "room-image-top-left":
                                        e.css({
                                            left: -pixel.small(fw)+"px", 
                                            width: pixel.small(fw)+"px", 
                                            top: -pixel.small(fw)+"px", 
                                            height: pixel.small(fw)+"px"
                                        });
                                    break;
                                    case "room-image-left":
                                        e.css({left: -pixel.small(fw)+"px", width: pixel.small(fw)+"px"});
                                    break;
                                    case "room-image-bottom-left":
                                        e.css({
                                            left: -pixel.small(fw)+"px", 
                                            width: pixel.small(fw)+"px", 
                                            bottom: -pixel.small(fw)+"px", 
                                            height: pixel.small(fw)+"px",
                                            backgroundPosition: "-150px " + (-450 + pixel.small(fw))+"px "
                                        });
                                    break;

                                    case "room-image-top":
                                        e.css({top: -pixel.small(fw)+"px", height: pixel.small(fw)+"px"});
                                    break;

                                    case "room-image-top-right":
                                        e.css({
                                            right: -pixel.small(fw)+"px", 
                                            width: pixel.small(fw)+"px", 
                                            top: -pixel.small(fw)+"px", 
                                            height: pixel.small(fw)+"px",
                                            backgroundPosition: (-450 + pixel.small(fw))+"px " + "-150px "
                                        });
                                    break;

                                    case "room-image-right":
                                        e.css({right: -pixel.small(fw)+"px", width: pixel.small(fw)+"px",
                                        backgroundPosition: (-450 + pixel.small(fw))+"px " + "50% "});
                                    break;

                                    case "room-image-bottom-right":
                                        e.css({
                                            right: -pixel.small(fw)+"px", 
                                            width: pixel.small(fw)+"px", 
                                            bottom: -pixel.small(fw)+"px", 
                                            height: pixel.small(fw)+"px",
                                            backgroundPosition: -450 + pixel.small(fw)+"px " + (-450 + pixel.small(fw))+"px " 
                                        });
                                    break;

                                    case "room-image-bottom":
                                        e.css({
                                            bottom: -pixel.small(fw)+"px", 
                                            height: pixel.small(fw)+"px",
                                            backgroundPosition: "50% " + (-450 + pixel.small(fw))+"px "});
                                    break;
                                }
                            }

                        break;
                        case true:

                            for (i = 0; i < fe.length; i++)
                            {
                                var e = $(fe[i])
                                var c = e.attr("class");
                                var tempbg = e.css("background-image");
                                e.removeAttr("style").css({backgroundImage: tempbg});
                                switch(c)
                                {
                                    case "room-image-top-left":
                                        e.css({
                                            left: -pixel.large(fw)+"px", 
                                            width: pixel.large(fw)+"px", 
                                            top: -pixel.large(fw)+"px", 
                                            height: pixel.large(fw)+"px"
                                        });
                                    break;
                                    case "room-image-left":
                                        e.css({left: -pixel.large(fw)+"px", width: pixel.large(fw)+"px"});
                                    break;
                                    case "room-image-bottom-left":
                                        e.css({
                                            left: -pixel.large(fw)+"px", 
                                            width: pixel.large(fw)+"px", 
                                            bottom: -pixel.large(fw)+"px", 
                                            height: pixel.large(fw)+"px"
                                        });
                                    break;

                                    case "room-image-top":
                                        e.css({top: -pixel.large(fw)+"px", height: pixel.large(fw)+"px"});
                                    break;

                                    case "room-image-top-right":
                                        e.css({
                                            right: -pixel.large(fw)+"px", 
                                            width: pixel.large(fw)+"px", 
                                            top: -pixel.large(fw)+"px", 
                                            height: pixel.large(fw)+"px"
                                        });
                                    break;

                                    case "room-image-right":
                                        e.css({right: -pixel.large(fw)+"px", width: pixel.large(fw)+"px"});
                                    break;

                                    case "room-image-bottom-right":
                                        e.css({
                                            right: -pixel.large(fw)+"px", 
                                            width: pixel.large(fw)+"px", 
                                            bottom: -pixel.large(fw)+"px", 
                                            height: pixel.large(fw)+"px"
                                        });
                                    break;

                                    case "room-image-bottom":
                                        e.css({bottom: -pixel.large(fw)+"px", height: pixel.large(fw)+"px"});
                                    break;
                                }
                            }
                        }
                },

                doMagic: function(printtype)
                {
                    switch(printtype)
                    {
                        case "Framed":
                            return 'framed';
                        break;
                        case "Canvas Gallery Wrap":
                            return 'gallery';
                        break;
                        case "Mounted Canvas (Frame Ready)":
                            return 'mounted';
                        break;
                        case 'Canvas in tube with 2" borders':
                            return 'loose';
                        break;
                        default:
                            return 'framed';
                    }
                },

                start: function(img)
                {
                    var height = img.outerHeight()
                    var width = img.outerWidth()
                    if(width > height)
                    {
                        o.orientation = "horz";
                    }
                    else if(width < height)
                    {
                        o.orientation = "vert";
                    }
                        
                    $("img", o.frame).css({height: "100%", width: "100%"});
                    // bind change function to type select 
                    printType.live("change", function(){
                        var val = $("option:selected", this).text();
                        o.type = o.doMagic(val);
                        o.change();
                    });

                    var printtype = $("option:selected", printType).text();
                    o.type = o.doMagic(printtype);

                    $(".product-frame-item").live('click', o.switchFrame);
                
                    $(".product-frame-item").eq(0).trigger('click');
                    // bind resize function to size select 
                    printSize.live("change", function(){
                        var val = $("option:selected", printSize).text().split(' ');
                        o.resize(val[0], true);
                    });
                    
                    var printsize = $("option:selected", printSize).text().split(' ');
                    o.change();
                    o.center();
                    o.resize(printsize[0], false);
                    o.frame.animate({opacity:1});

                    $(".zoom-plus", obj).click(zoom.IN);
                    $(".zoom-minus", obj).click(zoom.OUT);
                    var personalEnabledBox = $("<input type='checkbox' class='personalEnabledBox' value='checked' />");
                    personalEnabledBox.bind("change", personalText.toggle);
                    $(".attribute-personalize").prepend(personalEnabledBox);
                    $(".personalize-placement").children("a").each(function(){
                        var trig = $(this).attr('class').toString().replace("-", "_");
                        switch(trig)
                        {
                            case "top_left":       $(this).bind("click", personal.position.top_left);      break;
                            case "top":            $(this).bind("click", personal.position.top);           break;
                            case "top_right":      $(this).bind("click", personal.position.top_right);     break;

                            case "left":           $(this).bind("click", personal.position.left);          break;
                            case "middle":         $(this).bind("click", personal.position.middle);        break;
                            case "right":          $(this).bind("click", personal.position.right);         break;

                            case "bottom_left":    $(this).bind("click", personal.position.bottom_left);   break;
                            case "bottom":         $(this).bind("click", personal.position.bottom);        break;
                            case "bottom_right":   $(this).bind("click", personal.position.bottom_right);  break;
                        }
                    });
                    $(".attribute-personalize .attribute-personalize-options").hide();
                    $(".attribute-personalize-text").each(function(){
                        $(this).bind("click", personalText.print_cursive);
                    });
                    $(".attribute-personalize-options").children("label").each(function(){
                        $("input", this).bind("blur", personalText.addText);
                    });  
                    $(".add-info input[type=submit]").bind("click", function(event){
                        
                        if(personalText.validate() !== false)
                        {
                            //$(this).click();
                        }
                        else
                            event.preventDefault();
                    });                
                    personalText.validate();
                },

                initiate: function()
                {
                    //Get all LI in the UL
                    printType = $(".attribute-style select");
                    printSize = $(".attribute-size select");
                    o.frame = $(".room-image-holder", obj)
                    o.frame.css({display:"block", opacity:0});

                    var img = $("img", o.frame);
                    if(img[0].complete == true)
                    {
                        o.start(img);
                    }
                    else
                    {
                        img.load(function(){
                             o.start(img);
                        });
                    }
                    
                }

            }, defaults, options);

            var o = options;
            
            obj = $(this);
            o.initiate();
            return this;
            
        }
    });

})(jQuery);

(function($)
{
	$.fn.blink = function(options)
	{
		var defaults = { delay:200, repeat:2 };
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var obj = $(this);
            var i = 0;
			var inter = setInterval(function()
			{
                if(i <= defaults.repeat)
                {
				    if($(obj).hasClass("blink"))
				    {
					    $(obj).removeClass('blink');
				    }
				    else
				    {
					    $(obj).addClass('blink');
				    }
                }
                else
                {
                    $(obj).removeClass('blink');
                    clearInterval(inter);
                }
                i++;
			}, options.delay);
		});
	}
}(jQuery))
