$(document).ready(function() {
       
       $('.accordion').accordion( { collapsible: true, active:'false' } );

       $('a.moreinfo').hover(
function(){$(this).text("!")},
function(){$(this).text("i")}
);


       if( $('div.updates ul#news').length ){
       $('div.updates ul#news').cycle({
	fx:     'fade',
	speed:  '500',
	timeout: 3000,
	//next: 'a.next',
	//prev: 'a.prev',
	pager:  '#pager',
	pauseOnPagerHover:false
	//before: function() { if (window.console) console.log(this.src); }
		});    
        }
  
        $('#gallery ul').cycle({
	fx:     'scrollHorz',
	speed:  500,
	timeout: 0,
	next: 'a#next,#gallery',
	prev: 'a#prev',		   
            after:     function() {                                     
        },

        before: function(){
            var newx = $(this).children('img').attr('width') ;
            var newy =  Math.max( $(this).height(), $('#mainbubble').height() ) ; 
                
                           
                //$('#gallery').animate({'width':newx},500);
                //$('.gallerywrap').animate({'height':newy},500);
              
            ;
                
                }
        
			//before: function() { if (window.console) console.log(this.src); }
		}); 


        


        var total = $('#sapevilist li').length;
        var i=0; 

        function sapevireload(){

            $('div#sapeviwrap').hide(250);
			$('div#sapevitext').html($('#sapevilist li:eq('+i+')').html());

			$('div#sapeviwrap').slideDown(250);
            if(i<total){i++;}else{i=1;} 
        }


        $('a#sapeviload, a#sapeviche').click(function(){
            sapevireload();
            return false;
        });

		$('a#sapeviche').hover(function(){

		    sapevireload();
			return false;

		},function(){

			$('div#sapeviwrap').hide();

		});

		$('a#sapeviclose').hide();

		$('a#sapeviclose').click(function(){
			$('div#sapeviwrap').hide();
			return false;
		});

		//$('.local-border').height($('.nav-local').height());

		// Tooltips
		$('ul#nav-global li a:not(li.sapevi a, li.first a)').qtip({
			content: {
				text: false // Use each elements title attribute
			},
			show: {
				delay: 0
			},
            position: {
				target: 'mouse',
				corner: {
					target: 'topMiddle',
					tooltip: 'topMiddle'
				},
				adjust: { 
					x: 0, y: 18 
				}
			},
			style: {
				background: '#000000',
				//background: '#280407',
				border: {
					width: 1,
					radius: 5,
					//color: '#280407'
					color: '#000000'
				},
				tip: {
					corner: 'topLeft',
					size: {
						x: 10,
						y : 10
					}
				},
				padding: 0,
				tip:true,
				color: '#FAF7E2',
				name: 'dark'
			}
		});

         $('ul#nav-global li.first a').qtip({
			content: {
				text: false // Use each elements title attribute
			},
			show: {
				delay: 0
			},
            position: {
   			target: 'mouse',
				corner: {
					target: 'topMiddle',
					tooltip: 'topLeft'
				},
				adjust: { 
					x: 0, y: 18 
				}
			},
			style: {
				background: '#000000',
				//background: '#280407',
				border: {
					width: 1,
					radius: 5,
					//color: '#280407'
					color: '#000000'
				},
				tip: {
					corner: 'topLeft',
					size: {
						x: 10,
						y : 10
					}
				},
				padding: 0,
				tip:true,
				color: '#FAF7E2',
				name: 'dark'
			}
		}); 

// winelist tooltips







        // map/locations accordion
        
        $('div.postnav ul li div.location_name a').click(function(){
        
            if ( $(this).parent().parent().hasClass('active') ){

               $('div.postnav ul li.active div.location_info').hide(250).parent().removeClass('active');

            }else{
            
                $('div.postnav ul li.active div.location_info').hide(250).parent().removeClass('active');                          
                $(this).parent().siblings('div.location_info').slideDown(250).parent().addClass('active'); 
            }

            return false;
        
        }
        
        );
        



        
       // if($('div.contentbox').height() > $('#mainbubble').height()  && $('div.contentbox').height() < $(window).height()) { $('#mainbubble').height($('div.contentbox').height()); } 

	   // if(!$('.contentbox').length){
		//	$('.nav-local').fadeTo(0,0);
		//}

		//$('.contentbox').fadeTo(0,0);

		//$('.nav-local, .contentbox').fadeTo('slow',1); 



        var   navh =  $('#mainbubble').height();

        if($('div.contentbox div.menuwrap').height() < $('#mainbubble').height()) { $('div.contentbox div.menuwrap').height($('#mainbubble').height()); } 
        if($('div.contentbox div.pagewrap').height() < $('#mainbubble').height()) { $('div.contentbox div.pagewrap').height($('#mainbubble').height()); }  
        //if($('div.OT_wrapper').height() < $('#mainbubble').height()) { $('div.contentbox div.pagewrap').height($('#mainbubble').height()); }  
        if($('.gallerywrap').height() < navh ) { $('.gallerywrap').height($('#mainbubble').height()); }   

        //WINELIST
        $("a.expand_").click(function(){
                var desc = $(this).parent().parent().siblings('.winedetails');

               if( desc.is(':visible') ) { 
                  $(this).parent().fadeTo(50);
               }else{
                   $(this).parent().fadeTo(100);
               }


               desc.toggle(250);



               return false;
            })




	  
		});

