// Americano Restaurant & Bar main.js

var Americano = {
	Init: function () {
		this.SetSearchEvent();
		this.SetImageModal();
		this.initSlider();
		this.featureSlide();
		this.twitterInit();
		this.googleDirections();
		this.beautifyMenu();
	},
	
	SetSearchEvent: function (){
		$('#searchOpen').click(function() {
			$('#pageOverlay').fadeIn();
			$('#searchInput').focus();
		});
  		$('#searchClose').click(function() {
    		$('#pageOverlay').fadeOut();
		});
  		$('#searchLabel').click(function() {
    		$('#pageOverlay').fadeOut();
		});
	},
	
	SetImageModal: function (){
		if ($(".imageGallery").length > 0) {
			$(".imageGallery a").fancybox({
				cyclic:			true,
				padding:		0,
				centerOnScroll:	true,
				overlayColor:	'#333',
				overlayOpacity:	0.8
			});
		}
		
		if ($(".pageimgholder a").length > 0) {
			$(".pageimgholder a").fancybox({
				cyclic:			true,
				padding:		0,
				centerOnScroll:	true,
				overlayColor:	'#333',
				overlayOpacity:	0.8
			});
		}
		
		if ($(".modallink").length > 0) {
			$(".modallink").fancybox({
				cyclic:			true,
				padding:		0,
				centerOnScroll:	true,
				overlayColor:	'#333',
				overlayOpacity:	0.8
			});
		}
		
		if ($(".iframemodal").length > 0) {
			$(".iframemodal").fancybox({
				cyclic:			true,
				padding:		20,
				centerOnScroll:	true,
				overlayColor:	'#333',
				overlayOpacity:	0.8,
				params:			'?modal',
				'width':		800,
				'height':		'100%',
				'type':			'iframe'
			});
		}
	},
	
	initSlider: function (){
		if ($(".nivoSlider").length > 0) {
			$(".nivoSlider").nivoSlider({
				effect:			'fade',
				captionOpacity:	1,
				animSpeed:		1000,
				pauseTime:		6000,
				slices:			1,
				boxCols:		1,
				boxRows:		1
			});
		}
	},
	
	featureSlide: function(){
		
		$('div.feature').bind({
			mouseenter: function() {
				$('.featureImage', $(this)).stop(true, false).animate({ height: "93px", 'boxShadowBlur': '20px' }, 200);
				$('.featureContent', $(this)).stop(true, false).animate({ height: "134px" }, 200);
			},
			mouseleave: function() {
				$('.featureImage', $(this)).stop(true, false).animate({ height: "45px", 'boxShadowBlur': '0px' }, 200);
				$('.featureContent', $(this)).stop(true, false).animate({ height: "0px" }, 200);
			}
		});
		
	},
	
	twitterInit: function() {  
		getTwitters('tweets', { 
			id: 'americanosf', 
			count: 5, 
			enableLinks: true, 
			ignoreReplies: true, 
			clearContents: true,
			template: '<p class="author">%user_screen_name%</p><p class="date"><a href="http://twitter.com/%user_screen_name%/statuses/%id_str%/">%time%</a></p><p>%text%</p>',
			callback: 'twitterCallback'
		});
	},
	
	googleDirections: function(){
		if($('input#address').length > 0) {
			$('input#submit').bind({
				click: function() {
					window.location = "http://maps.google.com/maps?f=d&source=s_d&saddr=" + $('input#address').val() + "&daddr=8+Mission+Street,+San+Francisco,+CA+94105";
				}
			});
		}
	},
	
	beautifyMenu: function (){
		if ($(".blockOpen").length > 0) {
			$('div.blockOpen').nextUntil('div').wrapAll('<div class="tileholder"></div>');
			$('div.blockOpen').remove();
			$('div.blockClose').remove();
		}
	},
	
	nextUntil: function(expr) { 
		var match = []; 
		this.each(function(){ 
			for (var i=this.nextSibling; i; i=i.nextSibling ) { 
				if (i.nodeType != 1) continue; 
				if (jQuery.filter(expr, [i]).length) break; 
				match.push(i); 
			} 
		}); 
		return this.pushStack(match, arguments); 
	}
}

function twitterCallback() {
				alert('callback');
				var tweetCount = $(".li", "#tweets").length-1;
				var activeTweet = 0;
				
				if (tweetCount > 0) {
					$('#scrollUp').bind({
						click: function() {
							$(".tweet").eq(activeTweet).removeClass("displayed");
							if (activeTweet > 0) {
								activeTweet--;
							} else {
								activeTweet = tweetCount;
							}
							$(".tweet").eq(activeTweet).addClass("displayed");
						}
					});
					
					$('#scrollDown').bind({
						click: function() {
							$(".tweet").eq(activeTweet).removeClass("displayed");
							if (activeTweet < tweetCount) {
								activeTweet++;
							} else {
								activeTweet = 0;
							}
							$(".tweet").eq(activeTweet).addClass("displayed");
						}
					});
				}
}

$(document).ready(function () {
    Americano.Init();
});



