(function($)
{
    jQuery.extend({
            vf_ajax: function(options)
            {
                // code|

                var defaults =
                {
                        url: "",
                        data: {},
                        type: "GET",
                        onComplete: function(){},
                        onFail: function(){}};

                options = $.extend({},defaults, options);

                $.ajax(
                {
                        url: options.url,
                        data: options.data,
                        type: options.type,
                        success: function(data)
                        {
                            if(data.indexOf('|')== -1)
                            {
                                options.onComplete.call(this,0, data);
                            }
                            else
                            {
                                var values = data.split('|');
                                options.onComplete.call(this,values[0], values[1]);
                            }
                        },
                        error: function(error)
                        {options.onFail.call(this,error);}
                });
            }
    });
})(jQuery);

$(document).ready(function()
{
    $(".colorbox").fancybox();

    $(".youtube").click(function(event)
    {
        $.fancybox(
        {
            'padding'		: 0,
            'autoScale'		: false,
            'overlayOpacity'    : 0.5,
            'transitionIn'	: 'fade',
            'transitionOut'	: 'none',
            'title'		: this.title,
            'titlePosition'     : 'inside',
            'width'		: 800,
            'height'		: 600,
            'href'		: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'		: 'swf',
            'swf'		:
            {
                'wmode'             : 'transparent',
                'allowfullscreen'   : 'true'
            },
            'onClosed': function()
            {$("#ytplayer").show();}
        });

        event.preventDefault();
    });

    $('.whats_this').fancybox();

    $('#top_logo').click(function()
    {
        window.location = "http://www.vectorfabrics.com/";
    });

    $('.product').click(function()
    {
        window.location = $(this).children('a:first').attr('href');
    });

    $('#right #txt_username').focus(function()
    {$(this).removeClass('username-background');});

    $("#right #txt_username").focusout(function()
    {
        if($(this).val()=='')
            $(this).addClass('username-background');
    });

     $('#right #txt_password').focus(function()
    {$(this).removeClass('password-background');});

    $("#right #txt_password").focusout(function()
    {
        if($(this).val()=='')
            $(this).addClass('password-background');
    });

     $('#search_input').focus(function()
    {$(this).removeClass('search-background');});

    $("#search_input").focusout(function()
    {
        if($(this).val()=='')
            $(this).addClass('search-background');
    });

    if($('#right #txt_password').val()!='')
    {
        $('#right #txt_password').removeClass('password-background');
    }

    if($('#right #txt_username').val()!='')
    {
        $('#right #txt_username').removeClass('username-background');
    }

    if($('ul li a.secure:first').hasClass('active'))
    {
        $('ul li a.secure:first').parent('li').addClass('organge');
    }

    $('#companymenu a.active').parents('li').addClass('active');

});
