
jQuery(document).ready(function($) {
    
    $("#four_navs li").hover(function(){
        $(".slideup",this).stop().animate({ marginTop:"-100px" });
    },function(){
        $(".slideup",this).stop().animate({ marginTop:"0px" });
    });

    //setInterval( "slideSwitch()", 5000 );

	$('#mycarousel').jcarousel({
        auto: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });

	$(document).pngFix();

	$("#main_menu ul").lavaLamp({
		fx: "easeInOutCubic",
		speed: 500/*,
		click: function(event, menuItem) {
			//return true;
		}*/
	});
	
	var dockOptions = { align: 'bottom', labels: true, size: 150 };
	$('#food_menu').jqDock(dockOptions);
	
	$("#menu_book").jFlip(684,1026,{background:"#0f0200",cornersTop:true,scale:"fill"}).
		bind("flip.jflip",function(event,index,total){
			$("#menu_book_description").html("Image "+(index+1)+" of "+total);
		});


	var ver = getInternetExplorerVersion();

		$('#our-menu li')
			.css('pointer','default')
			.css('list-style-image','none');
		$('#our-menu li:has(table)')
			.click(function(event){
				if (this == event.target || ver >= 8.0 ) {
					$(this).css('list-style-image',
						(!$(this).find('table').is(':hidden')) ? 'url(http://i-sophie.com/wp-content/themes/sophie/images/plusbox.gif)' : 'url(http://i-sophie.com/wp-content/themes/sophie/images/minusbox.gif)');
					$(this).find('table').toggle('slow');
				}
				return false;
			})
			.css({cursor:'pointer', 'list-style-image':'url(http://i-sophie.com/wp-content/themes/sophie/images/plusbox.gif)'})
			.find('table').hide();
		$('#our-menu li:not(:has(table))').css({cursor:'default', 'list-style-image':'none'});


});

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function slideSwitch() {

	var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // markup
    var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');

    // random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

	$active.animate({opacity: 0.0}, 1000);

    $next.css({opacity: 0.0})
       .addClass('active')
       .animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
	});
}

function getInternetExplorerVersion() {
	// Returns the version of Internet Explorer or a -1
	// (indicating the use of another browser).
	var rv = -1; // Return value assumes failure.
	
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat( RegExp.$1 );
	}
	
	return rv;
	
}

