$(function() {

    // Main Navigation Drop Downs
    $('#main_nav li').hover(
        function() {$(this).addClass('active')},
        function() {$(this).removeClass('active')}
    );
    
    //Home Page Slideshow
    $('#slideshow').cycle({
        /*fx: 'fade',*/
        speed: 'fast',
        timeout: 6000,
        pager: '#nav',
        pagerAnchorBuilder: function (idx, slide) {
            // return sel string for existing anchor
            return '#nav li:eq(' + (idx) + ') a';
        },
        before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
            var index = $(this).index();
            var tab = $('#nav li:eq('+ index +')');
            tab.find('a').addClass('activeSlideCustom');
        },
        after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
            var index = $(this).index();
            var tab = $('#nav li:eq('+ index +')');
            
            if( tab.is(':visible') )
            {
                last_active_slide = tab;
                tab.siblings('li').find('a').removeClass('activeSlideCustom');
            }
            else
            {
                last_active_slide.find('a').addClass('activeSlideCustom');
            }
        }
    });

    $('#direct').click(function () {
        $('#nav li:eq(2) a').triggerHandler('click');
        return false;
    });
    
    $('#nav a').click( function() {
        $('#slideshow').cycle('pause');
    });
    //Product Tabs
    
    
    $('#featured .col').bigClick();

    $("ul.tabs li").click(function(event) {
		event.preventDefault();
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
	});

    $(".page_stay_in ul.tabs li").click(function(event) {
		event.preventDefault();
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".movies_tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });
	
     $("ul.wine_tabs li").click(function(event) {
		event.preventDefault();
        $("ul.wine_tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".wine_tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });
	 
    function get_tip() {
        $('#tips').load(context.site_url + "/global/get_tip", "", function() {
            $('#get_tip').click(get_tip);
        });
        return false;
    }
    $('#get_tip').click(get_tip);
    
    $('#nav_banner li a span').vAlign();
});

jQuery.fn.vAlign = function() {
    return this.each(function(i){
        var h = $(this).height();
        var oh = $(this).outerHeight();
        var mt = (h + (oh - h)) / 2;
        $(this).css("margin-top", "-" + mt + "px");
        $(this).css("top", "50%");
        $(this).css("left", "0");
        $(this).css("width", "324px");
        $(this).css("position", "absolute");
    });
}

jQuery.fn.bigClick = function(options)
{
    var settings = {
        cssClass : 'clickable'
    }
    
    if(options) {
        jQuery.extend(settings, options);
    };
    
    this.each(function(){
        var anchor = $(this).find('a')[0];
        
        if(!anchor)
            return;         
        
        var href = $(anchor).attr('href');
        var title = $(anchor).attr('title');
        
        $(this).attr('title', title);
        
        $(this).mouseover(function(){
            $(this).css('cursor', 'pointer');
        });
        
        $(this).addClass(settings.cssClass).click(function(){
            window.location = href;
        });
    });
	
	
	swap_val = [];
    $(".swap").each(function(i) {
        swap_val[i] = $(this).val();
        $(this).focusin(function() {
            if ($(this).val() == swap_val[i]) {
                $(this).val("");
            }
            return false;
        }).focusout(function() {
            if ($.trim($(this).val()) == "") {
                $(this).val(swap_val[i]);
            }
            return false;
        });
    });
}


