/**
 * jQuery.placeholder - Placeholder plugin for input fields
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2008/10/14
 *
 * @author Blair Mitchelmore
 * @version 1.0.1
 *
 * @link http://plugins.jquery.com/project/placeholder
 */
new function($){$.fn.placeholder=function(settings){settings=settings||{};var key=settings.dataKey||"placeholderValue";var attr=settings.attr||"placeholder";var className=settings.className||"placeholder";var values=settings.values||[];var block=settings.blockSubmit||false;var blank=settings.blankSubmit||false;var submit=settings.onSubmit||false;var value=settings.value||"";var position=settings.cursor_position||0;return this.filter(":input").each(function(index){$.data(this,key,values[index]||$(this).attr(attr));}).each(function(){if($.trim($(this).val())==="")
$(this).addClass(className).val($.data(this,key));}).focus(function(){if($.trim($(this).val())===$.data(this,key))
$(this).removeClass(className).val(value)
if($.fn.setCursorPosition){$(this).setCursorPosition(position);}}).blur(function(){if($.trim($(this).val())===value)
$(this).addClass(className).val($.data(this,key));}).each(function(index,elem){if(block)
new function(e){$(e.form).submit(function(){return $.trim($(e).val())!=$.data(e,key)});}(elem);else if(blank)
new function(e){$(e.form).submit(function(){if($.trim($(e).val())==$.data(e,key))
$(e).removeClass(className).val("");return true;});}(elem);else if(submit)
new function(e){$(e.form).submit(submit);}(elem);});};}(jQuery);


jQuery(document).ready(function()
{
    // table-text overflow width fix
    if (jQuery("table.overflow"))
    {
        jQuery("table.overflow").each(function()
        {
            jQuery("td.rightWidth", this).width(jQuery("td.rightWidth span", this).outerWidth(true));
        });
    }

/*
    var lb = jQuery(".lightbox");
    if (lb && lb.length)
    {
        lb.lightbox();
    }
*/

    var lb = jQuery("a.cbLightbox");
    if (lb && lb.length)
    {
        lb.colorbox({rel:'lightbox', opacity: 0.8, photo: true});
    }

    // "Leave feedback" inputs should have a "X chars left" message below them.
    if (jQuery("input[name='feedback']"))
    {
        jQuery("input[name='feedback']").change(feedbackInputChanged).keypress(feedbackInputChanged);
    }

    // Firefox padding bug.
    if (jQuery.browser.mozilla)
    {
        jQuery("#strip-search").css("top", "84px");
    }

    // Enable HTML5's placeholder attribute for browsers that don't support it.
    jQuery("[placeholder]").placeholder({blankSubmit: true});

    // Search sellers by username.
    jQuery("form#strip-search").submit(function()
    {
        if (this.c1.value === "special-seller")
        {
            this.action = "/zibbeters";
        }
        else if (this.c1.value === "special-this-shop")
        {
            this.action = "/" + this.username.value
            this.query.name = "search";
        }
        else if (this.c1.value === "" && (this.query.value === "" || this.query.value === "Type keywords here..."))
        {
            this.query.value = "All items";
        }
    });

    // When the Versign logo is clicked, open a pop-up instead of changing the page.
    jQuery("#footer-top-verisign-logo").click(function()
    {
        window.open(this.getAttribute("href"), "Zibbet's Versign Certificate", "width=520,height=450");
        return false;
    });
});

function feedbackInputChanged(event)
{
    var notice = jQuery(".feedback-chars-left", this.form);
    var charsLeft = 180 - this.value.length;

    notice.css("color", (charsLeft <= 20 ? "red" : "black"));
    notice.text(charsLeft + " characters left.");
}

function findChild(element, tagName, classSearch)
{			
    var children = element.getElementsByTagName(tagName);
    var className;

    for (var i = 0; i < children.length; i++)
    {
        var child = children[i];
		
        if (child.getAttribute("class"))
        {
            className = child.getAttribute("class");
        }
        else if(child.getAttribute("className"))
        {
            className = child.getAttribute("className");
        }
        else
        {
            continue;
        }
			
        if (className.indexOf(classSearch) >= 0)
        {
            return child;
        }
    }

    return null;
}

function hideSuccessBox()
{
    var suc = document.getElementById("success");
    if (suc)
    {
        document.getElementById("success").style["display"] = "none";
    }
}

