jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 


var roundCorners = function(selector) {
    if (!$.browser.msie) { 
        $(selector).corner("5px"); 
    }
};

var init_b = function() {
    var searchText = 'Search Lingerie...';
    roundCorners('.menu_col');
    if ($('#q').val() == searchText) {
        $('#q').click(function(e) {
            $(this).val('');
            $(this).unbind('click');
        });
    }
    var search = function() {
        query = encodeURIComponent($('#q').val()).replace(/%20/g, "+");
        $(document).attr('location', '/search/'+ query + '/' );    
    }
    $('#searchbtn').click(search);
    $('#q').bind("keypress", function(e) {
        if (e.keyCode == 13) {
            search();
            return false;
        }
    });
    $('#brand_ul_load').click(function() {
        url = '/ajax/manufacturer/list/';
        $.get(url, function(data) {
            $('#brand_ul').after(data).remove();
            $('#brand_ul_load').remove();
        });
    });
    $('.manlink').click(function() {
        url = '/' + $(this).attr('id');
        $(document).attr('location', url);
    });
};

var init_i = function() {
    var slideshow = function() {
        var slides = [
            ['/Sexy-Lingerie', '/media/images/vbanner-01.jpg'],
            ['/Sexy-Lingerie', '/media/images/vbanner-02.jpg'],
            ['/Sexy-Lingerie', '/media/images/vbanner-03.jpg'],
            ['/Sexy-Lingerie', '/media/images/vbanner-04.jpg'],
            ['/Sexy-Lingerie', '/media/images/vbanner-05.jpg'],
            ['/Sexy-Lingerie', '/media/images/vbanner-06.jpg']
        ];
        var i;
        var lenSlides = slides.length;
        $('#vbanner').html('<a id="vbannerlink" href=""></a>');
        for (i = 0; i < lenSlides; i++) {
            var img = $('<img />').attr('src', slides[i][1]);
            img.addClass('slide');
            img.css({zIndex: '' + (lenSlides - i) });
            if (i < lenSlides-1) { 
                img.fadeTo(0, 0); 
            }
            $('#vbannerlink').append(img);
            $('#vbannerlink').attr('href', slides[i][0]);
            slides[i].push(img);
        }
        var next_image = function() {
            var nextSlide = slides.pop();
            var currentSlide = slides[0];
            nextSlide[2].css({zIndex: '1'});
            currentSlide[2].css({zIndex: '100'});
            slides.unshift(nextSlide);
            nextSlide[2].fadeTo(0, 10);
            currentSlide[2].fadeTo(1500, 0);
            $('#vbannerlink').attr('href', currentSlide[0]);
        }
        setInterval(next_image, 6*1000);
    };
    slideshow();
};

var init_c = function() {
    /*$.ajaxSetup ({cache: false});*/
    roundCorners('.item');
    $('.item').hover(
        function() {
            $(this).toggleClass('item_highlight');
        },
        function() {
            $(this).toggleClass('item_highlight');
        }
    );
    $('.pagerlink').click(function() {
        url = $(this).attr('id').replace(/\$/g, '/');

        $.get(url, function(data){
            $('#pagecontent').fadeTo("slow", 0, function() {
                $('#pagecontent').html(data);
                $('#pagecontent').fadeTo('slow', 10);
            });
            
        });
    });     
};

var init_m = function() {
    init_c();
};

var init_p = function() {
    roundCorners('.page');
};

var init_pd = function() {
    roundCorners('.detail_thumb');
};

var init_s = function() {
    roundCorners('.item');
    $('.item').hover(
        function() {
            $(this).toggleClass('item_highlight');
        },
        function() {
            $(this).toggleClass('item_highlight');
        }
    );
};