jQuery.stjohncs = {
    init: function() {

        /* Fix MSIE6 Image flicker */var m = document.uniqueID /*IE*/ && document.compatMode /*>=IE6*/ && !window.XMLHttpRequest /*<=IE6*/ && document.execCommand; try { if (!!m) { m("BackgroundImageCache", false, true) /* = IE6 only */ } } catch (oh) { };

        // Site credits
        $('#sitecredits a').hover(
	        function() { $(this).text('CreateThe Group'); },
	        function() { $(this).text('Site Credits'); }
        );

        $('#sitecredits a').click(function(e) {
            e.preventDefault();
        });

        $('.clearDefault').clearDefault();

        $("#utilitynav #careers a").click(function() {

            var src = $(this).attr("href");
            $(this).attr("href", "");

            window.open(src, "Careers");
            return false;

        });
        // search box
        /*
        $(".search .frmtext").focus(function() {
        $(this).val("");
        }).blur(function() {
        if ($(this).val() == "") {
        $(this).val("Search Products");
        }
        });
        */

        $(":input").mouseover(function() {
            $(this).addClass("frmhover");
        }).mouseout(function() {
            $(this).removeClass("frmhover");
        }).focus(function() {
            $(this).addClass("frmfocus");
        }).blur(function() {
            $(this).removeClass("frmfocus frmhover");
        })

        // report links (hide show in non-ie browsers)      
        if (!$.browser.msie) {
            $('.postContent, .comments-list li').hover(function() {
                $(this).find('a.reportLink').css("visibility", "visible");
            }, function() {
                $(this).find('a.reportLink').css("visibility", "hidden");
            });
        } else {
            $('.postContent a.reportLink, .comments-list li a.reportLink').css("visibility", "visible");
        }

        //Allow viewable long usernames
        $('.memberList li,.userGrid li').hover(function() {
            $(this).find('.userlink').css("overflow", "visible").css("z-index", 1000);
        }, function() {
            $(this).find('.userlink').css("overflow", "hidden").css("z-index", 0);
        });

        //If privacy set to community only, show message on member item
        $('.internal').tooltip();
        /*
        $('.internal').hover(function(){
        $(this).fadeTo(50, .5);
        $(this).after("<div class=\"msg\">"+$(this).attr("title")+"</div>");
        },function() {
        $(this).fadeTo(50, 1);
        $(this).siblings(".msg").remove();
        });
        */


    }, //end init	 

    centerAxis: function(settings) {

        var images = $(this);

        settings = jQuery.extend({
            maxHeight: 150
        }, settings);


        images.each(function() {

            var _height = $(this).find("img").outerHeight();

            var _margin = (_height >= settings["maxHeight"]) ? 0 : (settings["maxHeight"] - _height) / 2;

            $(this).css("margin-top", _margin);

        });

    }, // end center axis

    friends: function() {


        $(window).bind("load", function() {

            $(".avatar").centerAxis();
            $(".requestUserList .avatar").centerAxis({ maxHeight: 60 });


        });

    }, // end friends

    termsConditions: function() {

        $(".terms-open").click(function() {
            $("body").append("<div id='tc'></div>");

            initjscrollPane = function() {
                $("#tc").jScrollPane({
                    showArrows: true,
                    scrollbarWidth: 15,
                    scrollbarMargin: 0
                });
            }

            $("#tc").load("/en-us/termsofuse/ .content", "", initjscrollPane).dialog({
                autoOpen: false,
                draggable: false,
                bgiframe: true,
                dialogClass: "tc-dialog",
                show: "fade",
                height: 450,
                width: 570,
                modal: true,
                resizable: false,
                stack: false,
                overlay: {
                    opacity: 0.5,
                    background: "black"
                },
                show: {
                    effect: "slide",
                    options: { direction: "up" },
                    speed: "2000"
                },
                open: function(e, ui) {


                    //$(this).fadeIn();

                },
                close: function(e, ui) { }

            });
            $("#tc").dialog("open")

        });
    }, //end terms and conditions

    customFileInput: function() {
        //reference http://www.appelsiini.net/projects/filestyle


        $("input[type=file]").filestyle({
            image: "/community/themes/stjohn/images/btn-browse.gif",
            imageheight: 18,
            imagewidth: 69,
            width: 180
        });


    }, //end custom file input

    editProfile: function() {

        /* Note: Tabs moved to server side code
		
        $("#menuTabs").tabs({
        select:function(e,ui){
        location.href=ui.tab.href;
                
        },
        fx: { opacity: 'toggle' } 
        });    
                  
    
        if(location.hash.substring(1)!=""){
        $("#menuTabs").tabs("select", '#'+location.hash.substring(1));
        }
        */

        $.stjohncs.termsConditions();
        $.stjohncs.customFileInput();

    }, // end edit profile

    photoAlbum: function() {

        $.stjohncs.customFileInput();
        $.stjohncs.termsConditions();

        $(".albumimg").centerAxis({
            maxHeight: 220
        });

    },   //end photo album
    createALook: function() {

        getFolders('/en-us/shoponline', 0);

        $("#next a").click(function() {

            if (hasMore) {
                getProducts(currentFolder, currentPage + 1);
            }
            return false;
        });

        $("#prev a").click(function() {
            if (currentPage > 1) {
                getProducts(currentFolder, currentPage - 1);
            }
            return false;
        });

        $("#sandbox").jScrollPane({
            showArrows: true,
            scrollbarWidth: 15,
            scrollbarMargin: 0
        });

        // create draggables
        $('#products li h3').draggable({
            opacity: 0.7,
            helper: 'clone'
        });

        /*
        if ($('#sandbox li.ui-droppable-disabled').length == 6) {
        $('#products li').draggable('disable');
        }
        */

        // create droppables
        $('#sandbox').droppable({
            accept: '#products li img',
            hoverClass: 'droppable-hover',
            tolerance: 'intersect',
            drop: function(ev, ui) {

                // create "remove" link
                var x = $('#sandbox li img').length; //$(this).attr("id").replace("sandboxitem-", "");
                var y = 0;
                var z = 0;

                var itemAlt = $(ui.draggable).attr('rel');
                itemAlt = itemAlt.split('||');

                var itemName = itemAlt[0];
                var itemId = itemAlt[1];
                var baseFileId = itemAlt[2];
                var systemFileName = itemAlt[3];
                var description = itemAlt[4];


                var $remove = $(document.createElement('a')).attr({ 'title': 'Remove', 'href': '#', 'rel': itemAlt[1] }).addClass('sandboxitem-remove deleteButton');
                $remove.click(function(e) {
                    e.preventDefault();

                    var _parent = $(this).parent("li");

                    // fade out the product image
                    $(this).prev().fadeTo(300, 0.00, function() {
                        // Remove the image
                        $(this).remove();
                    });

                    // Remove the delete image
                    $(this).remove();
                    _parent.remove();

                    /*
                    
                    // Re-enable the droppable
                    $(this).parent().droppable('enable');
                    // Remove the "remove" link
                    $(this).remove();
                    // enable products if sandbox not full
                    if ($('#sandbox li.ui-droppable-disabled').length < 6) {
                    $("#products-container").removeBlock();
                    $('.ajaxBlocker img').css('display', 'block');
                    }
                    */
                    lookCtrl.RemoveItem(itemId, x, y, z);
                    lookCtrl.SaveUserLook("#" + lookClientID);
                });

                // Append the image to the droppable

                var dropProduct = $('<li id="dropProd' + itemAlt[1] + '"><img /></li>');
                dropProduct.find('img').attr({
                    'src': CTSimagePathMini + systemFileName,
                    'title': itemName,
                    'alt': itemName
                });

                // Append "remove" link
                dropProduct.append($remove);

                //$(this).append($(document.createElement('img')).attr({ src: $(ui.draggable).children().attr('src'), alt: $(ui.draggable).children().attr('alt'), width: imgWidth, height: imgHeight }));
                $(this).append(dropProduct);

                $(this).find("li:last").children('img').css('opacity', '0.00').fadeTo(500, 1.00);

                // Disable the droppable
                //$(this).droppable('disable');


                lookCtrl.AddItemToLook(itemId, x, y, z, baseFileId, systemFileName, itemName, 0, description);
                lookCtrl.SaveUserLook("#" + lookClientID);

                // If 6 items, disable the draggables
                /*if ($('#sandbox li.ui-droppable-disabled').length == 6) {
                $("#products-container").blockAjax();
                $('.ajaxBlocker img').css('display', 'none');
                }*/

                $("#sandbox").jScrollPane({
                    showArrows: true,
                    scrollbarWidth: 15,
                    scrollbarMargin: 0
                });
            }
        });


        // pagination tooltip
        $('ul#products-paging a').tooltip({
            track: true,
            bgiframe: true,
            delay: 0,
            showURL: false,
            //fade: 250,
            extraClass: "paging-tooltip"
        });

        /*.tooltip({
        id: 'products-paging-tip',
        track: true,
        delay: 0,
        top: 25,
        left: 25
        });*/


        $(".ui-droppable-disabled").each(function() {

            var x = $('#sandbox li').index(this);  //$(this).attr("id").replace("sandboxitem-", "");
            var y = x;
            var z = x;

            var itemAlt = $(this).children("img").attr('rel');

            itemAlt = itemAlt.split('||');
            var itemName = itemAlt[0];
            var itemId = itemAlt[1];
            var baseFileId = itemAlt[2];
            var systemFileName = itemAlt[3];
            var lookItemId = itemAlt[4];
            var description = itemAlt[5];

            lookCtrl.AddItemToLook(itemId, x, y, z, baseFileId, systemFileName, itemName, lookItemId, description);

            $(this).find(".sandboxitem-remove").click(function(e) {
                e.preventDefault();

                var _parent = $(this).parent("li");

                // fade out the product image
                $(this).prev().fadeTo(300, 0.00, function() {
                    // Remove the image
                    $(this).remove();
                });

                // Remove the delete image
                $(this).remove();
                _parent.remove();

                lookCtrl.RemoveItem(itemId, x, y, z);
                lookCtrl.SaveUserLook("#" + lookClientID);
            });
        });

        $("#nextButton").click(function(event) {
            event.preventDefault();

            lookCtrl.SaveUserLook("#" + lookClientID);

            var looks = $("#" + lookClientID).val();

            var noerror = (looks != "");

            if (looks == "") {
                alert("Please select at least one item for your look.");
            }
            if (noerror) {
                $("#step1").children().fadeOut("fast");
                $("#products-container").fadeOut("fast",
                        function() {
                            $("#detail-container").fadeIn("fast");
                        }
                    );
            }
        });

        $("#backButton").click(function() {
            $("#detail-container").fadeOut("fast",
                function() {
                    $("#step1").children().fadeIn("fast");
                    $("#products-container").fadeIn("fast");
                }
            );
        });

        $("#createLook").click(
            function(event) {
                event.preventDefault();

                lookCtrl.SaveUserLook("#" + lookClientID);

                var name = $("#" + nameTBClientID).val();
                var description = $("#" + descriptionTBClientID).val();
                var looks = $("#" + lookClientID).val();

                var noerror = ((name != "") && (description != "") && (looks != ""));
                if (name == "") {
                    alert("Please enter a name for your look.");
                }
                else if (description == "") {
                    alert("Please enter a description for your look.");
                }
                if (noerror) {
                    $("form").submit();
                }
            });

    }, // end create a look
    reviewLook: function() {

        $(".gallery-item .galleryImg").tooltip({
            track: true,
            bgiframe: true,
            delay: 0,
            showURL: false,
            //fade: 250,
            extraClass: "wardrobe-tooltip",
            bodyHandler: function() {

                // suppress default tooltip text for proudct images
                $(this).find("img").attr("alt", "");
                $(this).find("img").attr("title", "");

                return $(this).parents("li").find(".p-info").html();
            }
        });

		$('a.productCommentDialogLink').each(function(){
			
			 var thisLink = $(this);	
			 var dialogBox = $("#" + thisLink.attr('rel'));   //Get the dialog id from link
	         var message = thisLink.next().val(); //.siblings('.productComment').val();
	         var messageInput = thisLink.next();
	         var commenttext = thisLink.prev();
			 
			 if (dialogBox == null) { return; }

			 thisLink.click(function(){
			 		
	            if (dialogBox == null) { return; }
		
				dialogBox.modal({
	                baseQuery: "#aspnetForm",
					overlay: 60,
	                containerId: "productCommentDialog",
					onOpen: function(dialog) {
	                    dialogBox.show();
	
	                    dialog.overlay.fadeIn('slow', function() {
	                        dialog.container.slideDown('slow', function() {
	                            dialog.data.fadeIn('slow');
	                        });
	                    });
	
	
	
	                    dialog.data.find(".messageBody textarea").val(message);
	                    dialog.data.find(".productImg img").attr("src", thisLink.parents(".gallery-item").find(".galleryImg img").attr("src"));
	                    dialog.data.find(".productImg div").html(thisLink.parents(".gallery-item").find("h3, cite.price").clone())
	
	                    dialog.data.find("a.buttonYES").click(function(eChoice) {
	                        
	                        var newMessage = dialog.data.find(".messageBody textarea").val();
	
	                        
	                        messageInput.val(newMessage);
	                        
	                       
	                        dialog.data.find(".messageBody textarea").val('');
	
	                        if (newMessage.length > 0) {
	
	                            thisLink.text('Edit Comment');
	                        	commenttext.html('"' + newMessage.substring(0, 20) + '"');
	                        }
	                        else {
	                        thisLink.text('Add Comment');
	                        commenttext.html('');
	                        }
	                        
	                        $.modal.close();
	                        return false;
	                        // Continue through to link
	                    });
	                    dialog.data.find("a.buttonNO").click(function(eChoice) {
	                        $.modal.close();
	                        return false;
	                    });
	                },
	                onClose: function(dialog) {
	
	                    dialog.container.hide('fast', function() {
	                        dialog.overlay.fadeOut('fast', function() {
	                            $.modal.close();
	
	                        });
	                    });
	                }
				});
						
				return false;
			 });
			
		});
    }, // end review look
    sendLook: function() {
        $(".sendList ul").jScrollPane({
            showArrows: true,
            scrollbarWidth: 15,
            scrollbarMargin: 0
        });

        $(window).bind("load", function() {

            $(".userSelect .userGrid li .avatar").centerAxis({ maxHeight: 80 });
            $(".userSelect .userGrid li .addUser").centerAxis({ maxHeight: 80 });


        })



    } // end send look

}

    