;(function($) {

var ver = 'Lite-1.0';

$.fn.cycle = function(options) {
    return this.each(function() {
        options = options || {};
        
        if (this.cycleTimeout) clearTimeout(this.cycleTimeout);
        this.cycleTimeout = 0;
        this.cyclePause = 0;
        
        var $cont = $(this);
        var $slides = options.slideExpr ? $(options.slideExpr, this) : $cont.children();
        var els = $slides.get();
        if (els.length < 2) {
            if (window.console && window.console.log)
                window.console.log('terminating; too few slides: ' + els.length);
            return; // don't bother
        }

        // support metadata plugin (v1.0 and v2.0)
        var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {});
            
        opts.before = opts.before ? [opts.before] : [];
        opts.after = opts.after ? [opts.after] : [];
        opts.after.unshift(function(){ opts.busy=0; });
            


        var first = 0;
        $slides.css({position: 'absolute', top:0, left:0}).hide().each(function(i) { 
            $(this).css('z-index', els.length-i) 
        });
        
        $(els[first]).css('opacity',1).show(); // opacity bit needed to handle reinit case
        if ($.browser.msie) els[first].style.removeAttribute('filter');

        if (opts.fit && opts.width) 
            $slides.width(opts.width);
        if (opts.fit && opts.height && opts.height != 'auto') 
            $slides.height(opts.height);
        if (opts.pause) 
            $cont.hover(function(){this.cyclePause=1;}, function(){this.cyclePause=0;});

        $.fn.cycle.transitions.fade($cont, $slides, opts);
        
        $slides.each(function() {
            var $el = $(this);
            this.cycleH = (opts.fit && opts.height) ? opts.height : $el.height();
            this.cycleW = (opts.fit && opts.width) ? opts.width : $el.width();
        });

        $slides.not(':eq('+first+')').css({opacity:0});
        if (opts.cssFirst)
            $($slides[first]).css(opts.cssFirst);

        if (opts.timeout) {
            // ensure that timeout and speed settings are sane
            if (opts.speed.constructor == String)
                opts.speed = {slow: 600, fast: 200}[opts.speed] || 400;
            if (!opts.sync)
                opts.speed = opts.speed / 2;
            while((opts.timeout - opts.speed) < 250)
                opts.timeout += opts.speed;
        }
        opts.speedIn = opts.speed;
        opts.speedOut = opts.speed;

 		opts.slideCount = els.length;
        opts.currSlide = first;
        opts.nextSlide = 1;

        // fire artificial events
        var e0 = $slides[first];
        if (opts.before.length)
            opts.before[0].apply(e0, [e0, e0, opts, true]);
        if (opts.after.length > 1)
            opts.after[1].apply(e0, [e0, e0, opts, true]);
        if (opts.timeout)
            this.cycleTimeout = setTimeout(function() {
                go(els,opts,0,!opts.rev)
            }, opts.timeout + (opts.delay||0));
    });
};

function go(els, opts, manual, fwd) {
    if (opts.busy) return;
    var p = els[0].parentNode, curr = els[opts.currSlide], next = els[opts.nextSlide];
    if (p.cycleTimeout === 0 && !manual) 
        return;

    if (manual || !p.cyclePause) {
        if (opts.before.length)
            $.each(opts.before, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
        var after = function() {
            if ($.browser.msie)
                this.style.removeAttribute('filter');
            $.each(opts.after, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
        };

        if (opts.nextSlide != opts.currSlide) {
            opts.busy = 1;
            $.fn.cycle.custom(curr, next, opts, after);
        }
        var roll = (opts.nextSlide + 1) == els.length;
        opts.nextSlide = roll ? 0 : opts.nextSlide+1;
        opts.currSlide = roll ? els.length-1 : opts.nextSlide-1;
    }
    if (opts.timeout)
        p.cycleTimeout = setTimeout(function() { go(els,opts,0,!opts.rev) }, opts.timeout);
};


$.fn.cycle.custom = function(curr, next, opts, cb) {
    var $l = $(curr), $n = $(next);
    $n.css({opacity:0});
    var fn = function() {$n.animate({opacity:1}, opts.speedIn, opts.easeIn, cb)};
    $l.animate({opacity:0}, opts.speedOut, opts.easeOut, function() {
        $l.css({display:'none'});
        if (!opts.sync) fn();
    });
    if (opts.sync) fn();
};

$.fn.cycle.transitions = {
    fade: function($cont, $slides, opts) {
        $slides.not(':eq(0)').css('opacity',0);
        opts.before.push(function() { $(this).show() });
    }
};

// @see: http://malsup.com/jquery/cycle/lite/
$.fn.cycle.defaults = {
    timeout:       5367, 
    speed:         1000, 
    next:          null, 
    prev:          null, 
    before:        null, 
    after:         null, 
    height:       'auto',
    sync:          1,    
    fit:           0,    
    pause:         0,    
    delay:         0,    
    slideExpr:     null  
};

})(jQuery);












$(document).ready(function(){



    $('#mod_B').cycle();
    
	
	
$('div#hp_tabs1').empty().html('<img src="http://cdn.overstock.com/img/mxc/2009_os_homepageLoading2.gif">');

$.ajax({
  url: "26396/static.html?nocache=true",
  cache: false,
  success: function(html){
  setTimeout(function(){$('div#hp_tabs1').load('26396/static.html?nocache=true')}, 2000);
  }
});


$.ajax({
  url: "26397/static.html?nocache=true",
  cache: false,
  success: function(html){
    $("div#hp_tabs3").append(html);
  }
});




	$(".carousel-mainMod").jCarouselLite({
       speed:  1000,
	   auto: 6000,
	   visible:1,
	   scroll: 1,
	   btnGo: ['.1','.2','.3','.4'],
	   navcontainer:'#sectionlinks',
	   sectionlinks:'#sectionlinks a',
	   panel:'.carousel-mainMod-panel',
	   easing: "easeInQuad"

   });
	

	
	$("#recs").jCarouselLite({
       btnNext: "#tab-1 ul.tab-carousel-nav li a.tab-carousel-next",
       btnPrev: "#tab-1 ul.tab-carousel-nav li a.tab-carousel-prev",
	   panel:'#recs .tab-carousel-panel',
           speed: 1000,
	   visible: 1,
	   scroll: 1,
	   easing: "easeInQuad"
   });

	$("#recs2").jCarouselLite({
       btnNext: "#next2",
       btnPrev: "#prev2",
	   panel:'#recs2 .tab-carousel-panel2',
       speed: 1000,
	   visible: 6,
	   scroll: 6,
	   easing: "easeInQuad"
   });
   
	
	$('#tab-container1 ul').tabs();
	
});




/****************************************************************************************************

Browser Dectection

****************************************************************************************************/

var HM_DOM    = (document.getElementById) ? true : false;
var HM_NS4    = (document.layers) ? true : false;
var HM_IE     = (document.all) ? true : false;
var HM_IE4    = HM_IE && !HM_DOM;
var HM_Mac    = (navigator.appVersion.indexOf("Mac") != -1);
var HM_IE4M   = HM_IE4 && HM_Mac;
var HM_NS6    = (navigator.appName == "Netscape" && parseFloat(navigator.appVersion) > 4 && parseFloat(navigator.appVersion) < 7);
var HM_IsMenu = (HM_DOM && !HM_NS6) || (HM_IE4 && !HM_IE4M);


/****************************************************************************************************

Main Navigation Dropdowns

****************************************************************************************************/



var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function navigation_open()
{  navigation_canceltimer();
   navigation_close();
   ddmenuitem = jQuery(this).find('ul').css('visibility', 'visible');}

function navigation_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function navigation_timer()
{  closetimer = window.setTimeout(navigation_close, timeout);}

function navigation_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

jQuery(document).ready(function()
{  jQuery('#navigation > li').bind('mouseover', navigation_open)
   jQuery('#navigation > li').bind('mouseout',  navigation_timer)});

document.onclick = navigation_close;





/****************************************************************************************************

Tabs - Created by Bucky Flowers 7/23/09

****************************************************************************************************/


jQuery.fn.tabs = function () {
	return this.each(function () {
		var ul = jQuery(this);
		
		
		
		ul.find('a[href^=#]').each(function (i) {
			var tablink = jQuery(this);

			if (i) {
				jQuery(tablink.attr('href')).hide();

			}
			else {
				tablink.addClass('current');
			}

			tablink.click(function () {
				jQuery(ul.find('a.current').removeClass('current').attr('href')).hide();
				jQuery(tablink.addClass('current').attr('href')).show();
				if(tablink.attr('rel')){
					$("#tab-preloader").show();
					$.ajax( 
						{ 
							url: tablink.attr('rel'), 
							cache: false, 
							success: function(message) 
							{ 
							jQuery(tablink.attr('href')).empty().append(message); 
							$("#tab-preloader").hide();
							}
						});
				};

				return false;
			});
		});
	});
};







/****************************************************************************************************

jcarousellite  with an easing extention for jquery

****************************************************************************************************/


// jcarousel lite modified by Bucky Flowers to include pause on mouseover, and external position indicators

(function(jQuery) {                                          // Compliant with jquery.noConflict()
jQuery.fn.jCarouselLite = function(o) {
    o = jQuery.extend({
        btnPrev: null,
        btnNext: null,
        mouseWheel: false,
        auto: null,
        speed: 200,
        easing: null,
        vertical: false,
        circular: true,
		navcontainer:null,
		sectionlinks:null,
        visible: 3,
        start: 0,
        scroll: 1,
		pauseOnHover: true,
        beforeStart: null,
        afterEnd: null
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.

        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = jQuery(this), ul = jQuery("ul", div), tLi = jQuery("li", ul), tl = tLi.size(), v = o.visible;
		
		 var isMouseOver = false;
		 
		 
            // added: only perform if li > 1
            if(o.circular && tl > 1) {
                                ul.prepend(tLi.slice(tl-v-1+1).clone()).append(tLi.slice(0,v).clone());
                                o.start += v;
                        }

                        
       
                        update_navigation(1);

        var li = jQuery(o.panel), itemLength = li.size(), curr = o.start;
        div.css("visibility", "visible");

        li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
        var divSize = liSize * v;                           // size of entire div(total length for just the visible items)
		var nav = jQuery(o.navcontainer);
		
        li.css({width: li.width(), height: li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

		li.mouseover(function(){ isMouseOver = true; });        
        li.mouseout(function(){ isMouseOver = false; });
		nav.mouseover(function(){ isMouseOver = true; });        
        nav.mouseout(function(){ isMouseOver = false; });
		
        if(o.btnPrev)
            jQuery(o.btnPrev).click(function() {
                return go(curr-o.scroll);
            });

        if(o.btnNext)
            jQuery(o.btnNext).click(function() {
                return go(curr+o.scroll);
            });

        if(o.btnGo) {
            jQuery.each(o.btnGo, function(i, val) {
            jQuery(val).click(function() {
				
                return go(o.circular ? o.visible+i : i+1);
            		});
            	});
            }

        if(o.mouseWheel && div.mousewheel)
            div.mousewheel(function(e, d) {
                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
            });

        if(o.auto){    
                                setInterval(function() {
                                        if(o.pauseOnHover && isMouseOver) return;                    
                                        go(curr+o.scroll);
                                }, o.auto+o.speed);
                        }

        function vis() {
            return li.slice(curr).slice(0,v);
        };

        function go(to) {
            if(!running) {

                if(o.beforeStart)
                    o.beforeStart.call(this, vis());

                if(o.circular) {            // If circular we are in first or last, then goto the other end
                    if(to<=o.start-v-1) {           // If first, then goto last
                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
                    } else if(to>=itemLength-v+1) { // If last, then goto first
                        ul.css(animCss, -( (v) * liSize ) + "px" );
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
                    } else curr = to;
                } else {                    // If non-circular and to points to first or last, we just return.
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                }                           // If neither overrides it, the curr will still be "to" and we can proceed.

                running = true;

                ul.animate(
                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
                    function() {
                        if(o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
				
				
                );
				update_navigation((o.circular) ? 0+curr : 1+curr);
                // Disable buttons when the carousel reaches the last/first, and enable when not
                if(!o.circular) {
                    jQuery(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                    jQuery( (curr-o.scroll<0 && o.btnPrev)
                        ||
                       (curr+o.scroll > itemLength-v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                }

            }
            return false;
        };
		
		
		function update_navigation(curr){
                                var kids = jQuery(o.panel);
                                var cloneVal = (o.circular) ? 2 : 0;
                                var pos = (kids.size()-cloneVal <= curr) ? (curr > kids.size()-cloneVal) ? 1 : kids.size()-cloneVal : curr;
                                pos = (pos == 0) ? kids.size()-cloneVal : pos;

                                var sectionLinks = jQuery(o.sectionlinks);

                           
                               
                                for(k = 0; k < sectionLinks.size(); k++){
                                        if(pos == k+1){
                                                jQuery(sectionLinks[k]).attr("class", 'selected');
                                        } else {
                                                jQuery(sectionLinks[k]).attr("class", 'off');
                                        }
                                }
                        };
		
    });
};

function css(el, prop) {
    return parseInt(jQuery.css(el[0], prop)) || 0;
};
function width(el) {
    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) {
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};

})(jQuery);


jQuery.extend( jQuery.easing,
{
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	}
	
});
/****************************************************************************************************

end of overstock.js

****************************************************************************************************/



