$(function() {

	//Initialize food slideshow
	$('#slideshow-food').data('miss', 0);
	$('#slideshow-food img').hide();
	$('#miss1').show();

	initializeStars();

	// $("#jquery_jplayer_1").jPlayer({
	// 	ready: function () {
	// 		$(this).jPlayer("setMedia", {
	// 			mp3: "venezuela.mp3"
	// 		}).jPlayer("play");
	// 	},
	// 	ended: function() { //loop media
	// 		$(this).jPlayer("play");
	// 	},
	// 	swfPath: "/js/jplayer",
	// 	supplied: "mp3",
	// 	volume: 0.2
	// });

});

$(window).load(function() {

	$('#lunch-specials').fancybox({
		'overlayOpacity':	0.8,
		'overlayColor'	:	'#000',
		'titleShow'		:	false,
		'scrolling'		:	'no',
		'onClosed'		:	function() {
			//Wait 2 seconds then start slideshow
			setTimeout(function() {openCurtain();}, 2000);

			$('#jquery_jplayer_1').jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "venezuela.mp3"
					}).jPlayer("play");
				},
				ended: function() { //loop media
					$(this).jPlayer("play");
				},
				swfPath: "/js/jplayer",
				supplied: "mp3",
				volume: 0.2
			});
		}
	}).trigger('click');

});

function openCurtain () {

	//Cycle image before opening the curtain
	changeImage();
	// if (!$.browser.msie) starsOpen();
	// else if ($.browser.msie && parseInt($.browser.version) > 6) starsOpen();
	if (!$.browser.msie || $.browser.msie && parseInt($.browser.version) > 6) starsOpen();

	//Open the curtain
	$('#curtain-left').stop().animate({width:'110px'}, 2000 );
	$('#curtain-right').stop().animate({width:'110px'},2000 );

	//Wait 4 seconds then close the curtain
	setTimeout(function() {closeCurtain();}, 6000);

}

function closeCurtain () {

	if (!$.browser.msie) starsClose();
	else if ($.browser.msie && parseInt($.browser.version) > 6) starsClose();

	//Close the curtain
	$('#curtain-left').stop().animate({width:'423px'}, 2000 );
	$('#curtain-right').stop().animate({width:'423px'},2000 );

	//Wait .1 seconds then open the curtain
	setTimeout(function() {openCurtain();}, 2100);

}

function changeImage() {

	//Check which image is next and assign variables
	var current = $('#slideshow-food').data('miss');
	var next = (current % 7) + 1;

	var currentImage = '#miss' + current;
	var nextImage = '#miss' + next;

	//Show the new image and hide the last image
	$(nextImage).show();
	$(currentImage).hide();

	//Remember which image is currently being viewed
	$('#slideshow-food').data('miss', next);

}

function initializeStars () {

	var x = $('#top-content').offset().left;
	var y = $('#top-content').offset().top;

	$('#stars').show();
	$('#star-1').css('top', y + 500 + 'px').css('left', x + 450 + 'px');
	$('#star-2').css('top', y + 500 + 'px').css('left', x + 450 + 'px');
	$('#star-3').css('top', y + 500 + 'px').css('left', x + 450 + 'px');
	$('#star-4').css('top', y + 500 + 'px').css('left', x + 450 + 'px');
	$('#star-5').css('top', y + 500 + 'px').css('left', x + 450 + 'px');
	$('#star-6').css('top', y + 500 + 'px').css('left', x + 450 + 'px');
	$('#star-7').css('top', y + 500 + 'px').css('left', x + 450 + 'px');

}

function starsOpen () {
	var x = $('#top-content').offset().left;
	var y = $('#top-content').offset().top;

	if ($.browser.msie) {
		initializeStars();
		$('#star-1').animate({top: y +  40 + 'px', left: x + 300 + 'px'}, 2000 );
		$('#star-2').animate({top: y +  85 + 'px', left: x + 485 + 'px'}, 2000 );
		$('#star-3').animate({top: y +  80 + 'px', left: x + 705 + 'px'}, 2000 );
		$('#star-4').animate({top: y + 355 + 'px', left: x + 895 + 'px'}, 2000 );
		$('#star-5').animate({top: y + 580 + 'px', left: x + 905 + 'px'}, 2000 );
		$('#star-6').animate({top: y + 270 + 'px', left: x +  20 + 'px'}, 2000 );
		$('#star-7').animate({top: y + 380 + 'px', left: x +   0 + 'px'}, 2000 );
	} else {
		$('#star-1')
			.animate({top: y + 40 + 'px', left: x + 300 + 'px', opacity:'-=0.4'}, 2000 )
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=0.4'}, 500)
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=1'}, 1800);
		$('#star-2')
			.animate({top: y + 85 + 'px', left: x + 485 + 'px', opacity:'-=0.4'}, 2000 )
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=0.4'}, 500)
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=1'}, 1800);
		$('#star-3')
			.animate({top: y + 80 + 'px', left: x + 705 + 'px', opacity:'-=0.4'}, 2000 )
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=0.4'}, 500)
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=1'}, 1800);
		$('#star-4')
			.animate({top: y + 355 + 'px', left: x + 895 + 'px', opacity:'-=0.4'}, 2000 )
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=0.4'}, 500)
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=1'}, 1800);
		$('#star-5')
			.animate({top: y + 580 + 'px', left: x + 905 + 'px', opacity:'-=0.4'}, 2000 )
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=0.4'}, 500)
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=1'}, 1800);
		$('#star-6')
			.animate({top: y + 270 + 'px', left: x + 20 + 'px', opacity:'-=0.4'}, 2000 )
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=0.4'}, 500)
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=1'}, 1800);
		$('#star-7')
			.animate({top: y + 380 + 'px', left: x + 0 + 'px', opacity:'-=0.4'}, 2000 )
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=0.4'}, 500)
			.animate({opacity:'+=0.4'}, 900)
			.animate({opacity:'-=1'}, 1800);
	}
}

function starsClose () {
	if ($.browser.msie) {
		$('#stars').hide();
	} else {
		var x = $('#top-content').offset().left;
		var y = $('#top-content').offset().top;

		$('#star-1')
			.animate({top: y + 500 + 'px', left: x + 450 + 'px'}, 0 )
			.animate({opacity:'+=1'}, 0);
		$('#star-2')
			.animate({top: y + 500 + 'px', left: x + 450 + 'px'}, 0 )
			.animate({opacity:'+=1'}, 0);
		$('#star-3')
			.animate({top: y + 500 + 'px', left: x + 450 + 'px'}, 0 )
			.animate({opacity:'+=1'}, 0);
		$('#star-4')
			.animate({top: y + 500 + 'px', left: x + 450 + 'px'}, 0 )
			.animate({opacity:'+=1'}, 0);
		$('#star-5')
			.animate({top: y + 500 + 'px', left: x + 450 + 'px'}, 0 )
			.animate({opacity:'+=1'}, 0);
		$('#star-6')
			.animate({top: y + 500 + 'px', left: x + 450 + 'px'}, 0 )
			.animate({opacity:'+=1'}, 0);
		$('#star-7')
			.animate({top: y + 500 + 'px', left: x + 450 + 'px'}, 0 )
			.animate({opacity:'+=1'}, 0);
	}
}
