$(function () {
//////////////////////////////////////////////////////////////////////////
////// START - CODE FOR LOADING THE TOP MENU CHASING BAR
//////////////////////////////////////////////////////////////////////////

	var $doc = $(document), $win = $(window), $chaser, $forch,
		forchBottom, visible;
	function shown() {
		visible = true;
	}
	function hidden() {
		visible = false;
	}
	$chaser = $('#header ul.menu').clone().hide().appendTo(document.body).wrap("<div class='chaser'></div>");
	$forch = $('.forchaser').first();
	forchBottom = $forch.height() + $forch.offset().top;
	hidden();
	$win.bind('scroll', function () {
		var top = $doc.scrollTop();
		if (!visible && top > forchBottom) {
			$chaser.slideDown(300, shown);
		} else if (visible && top < forchBottom) {
			$chaser.slideUp(200, hidden);
		}
	});

	
//////////////////////////////////////////////////////////////////////////
// LOAD DATA INTO THE CURRENT-DATE DIV
//////////////////////////////////////////////////////////////////////////
	$.ajax({
	  url: "php-includes/date.php",
	  success: function(data){
		$("#current-date").html(data);
	  }
	});

});


$(window).load(function() {
//////////////////////////////////////////////////////////////////////////
// SOCIAL ICONS SMALL SLIDER
//////////////////////////////////////////////////////////////////////////
	$('li.social-icons > a').click(function() {
		var $t = $(this).next();
		if($(this).hasClass('opened')) {
			$t.parent().animate({width:$(this).width()+'px'}, 300, 'easeOutExpo');
			$(this).removeClass('opened');
		}else{
			$t.parent().animate({width:($t.find('.inner').outerWidth()+$(this).width())+'px'}, 300, 'easeOutExpo');
			$(this).addClass('opened');
		}
	});


//////////////////////////////////////////////////////////////////////////	
// SEARCH FIELD SMALL SLIDER
//////////////////////////////////////////////////////////////////////////
	$('li.search-box > a').click(function() {
		var $t = $(this).next();
		if($(this).hasClass('opened')) {
			$t.parent().animate({width:$(this).width()+'px'}, 300, 'easeOutExpo');
			$(this).removeClass('opened');
		}else{
			$t.parent().animate({width:($t.find('input[type=text]').outerWidth()+$(this).width())+'px'}, 300, 'easeOutExpo');
			$(this).addClass('opened');
		}
	});


//////////////////////////////////////////////////////////////////////////
// REMOVE MARGIN BOTTOM FROM EACH LAST PARAGRAF
//////////////////////////////////////////////////////////////////////////
	//$('body').find('p:last-child').css('margin-bottom',0);
	

//////////////////////////////////////////////////////////////////////////
// INSERT SHADOW UNDER IMAGES HAVING
//////////////////////////////////////////////////////////////////////////
	$('img.with-shadow-1').each(function() {
		$(this).wrap('<div class="block-img-shadow" />');
		
	});
	$('img.with-shadow-2').each(function() {
		$(this).wrap('<div class="block-img-shadow" />');
		$('<div class="under-shadow"><img src="php-includes/img.php?src=../images/image_shadows/shadow02.png&amp;w='+$(this).width()+'" alt="" /></div>').insertAfter(this);
	});
	$('img.with-shadow-3').each(function() {
		$(this).wrap('<div class="block-img-shadow" />');
		$('<div class="under-shadow"><img src="php-includes/img.php?src=../images/image_shadows/shadow03.png&amp;w='+$(this).width()+'" alt="" /></div>').insertAfter(this);
	});
	$('img.with-shadow-4').each(function() {
		$(this).wrap('<div class="block-img-shadow" />');
		$('<div class="under-shadow"><img src="php-includes/img.php?src=../images/image_shadows/shadow04.png&amp;w='+$(this).width()+'" alt="" /></div>').insertAfter(this);
	});
	
	
	$('.head-image').each(function() {
		$(this).parent().append('<span class="zoom-overlay"></span>');
	});
	

//////////////////////////////////////////////////////////////////////////
// SWAPPERS FROM SLIDESHOW
//////////////////////////////////////////////////////////////////////////
	var sp = 300;
	$('#swappers div.swapper').hover(
		function() {
			$(this).stop().animate({top:'-180px'}, {queue: false, duration: sp, easing: "easeOutExpo"});
			$(this).find('.bgr').stop().animate({'opacity':0.9}, {queue: false, duration: sp, easing: "easeOutExpo"});
			$(this).find('p').stop().animate({'opacity':1}, {queue: false, duration: sp, easing: "easeOutExpo"});
			$(this).find('.indicator').css('background-position','center top');
		},
		function() {
			$(this).stop().animate({top:'0px'}, {queue: false, duration: sp, easing: "easeOutExpo"});
			$(this).find('.bgr').stop().animate({'opacity':0.5}, {queue: false, duration: sp, easing: "easeOutExpo"});
			$(this).find('p').stop().animate({'opacity':0.5}, {queue: false, duration: sp, easing: "easeOutExpo"});
			$(this).find('.indicator').css('background-position','center bottom');
		}
	);


//////////////////////////////////////////////////////////////////////////
// ADD A LAST CLASS TO DIFFERENT ELEMENTS TO REMOVE MARGINS/PADDINGS
//////////////////////////////////////////////////////////////////////////
	$("#flickr_container li:nth-child(3n)").addClass("last");
	$(".small_ads li:nth-child(2n)").addClass("last");
	$(".projects .items li:nth-child(4n)").addClass("last");
	


//////////////////////////////////////////////////////////////////////////	
// LIVE COMMENTS OPENER
//////////////////////////////////////////////////////////////////////////
	$('.live-comments .opener').click(function(e) {
		e.preventDefault();
		var $t = $(this).next();
		if($t.hasClass('opened')) {
			$(this).removeClass('active');
			$t.removeClass('opened');
		}else{
			$(this).addClass('active');
			$t.addClass('opened');
		}
	})

	
//////////////////////////////////////////////////////////////////////////	
// TRIGGER TO SHOW THE HIDDEN MAP
//////////////////////////////////////////////////////////////////////////
	$('.map_link').click(function(e) {
		e.preventDefault();
		var $m = $('.hidden-map-wrapper');
		if($m.hasClass('opened')) {
			$m.stop().animate({height:0}, {queue: false, duration: 300, easing: "easeOutExpo"});
			$m.removeClass('opened');
		}else{
			$m.stop().animate({height:'350px'}, {queue: false, duration: 300, easing: "easeOutExpo"});
			$('html, body').animate({scrollTop: '5000px'}, 300,'easeOutExpo');
			$m.addClass('opened');
		}
	})
	$('.close-map').click(function(e) {
		e.preventDefault();
		var $m = $('.hidden-map-wrapper');
		$m.stop().animate({height:0}, {queue: false, duration: 300, easing: "easeOutExpo"});
		$m.removeClass('opened');
	})


//////////////////////////////////////////////////////////////////////////
//INITIALIZE THE SUPERFISH MENU
//////////////////////////////////////////////////////////////////////////
	$(function($){ $("ul.sf-menu").supersubs({minWidth:13, maxWidth:30, extraWidth:0}).superfish({hoverClass:'sfHover', pathClass:'sf-active', pathLevels:0, delay:500, animation:{height:'show'}, speed:'def', autoArrows:1, dropShadows:0}) });


//////////////////////////////////////////////////////////////////////////
// INIT COLORBOX
//////////////////////////////////////////////////////////////////////////
	$("a[rel='colorbox']").colorbox();
	


//////////////////////////////////////////////////////////////////////////	
// INIT INFIELD LABELS
//////////////////////////////////////////////////////////////////////////
	$("#newsletter-form label, .infield label").inFieldLabels();


//////////////////////////////////////////////////////////////////////////	
// TWITTER LOADER
//////////////////////////////////////////////////////////////////////////
	$("#twitter").getTwitter({
		// change here the Twitter username
		userName: "tabusushi",
		numTweets: 1,
		loaderText: "Loading tweets...",
		slideIn: false,
		showHeading: true,
		headingText: "Latest Tweets",
		showProfileLink: true
	});


//////////////////////////////////////////////////////////////////////////
// LOAD TESTIMONIALS FADE TRANSITIONS
//////////////////////////////////////////////////////////////////////////
	$('#testimonials blockquote').quovolver();
	
//////////////////////////////////////////////////////////////////////////	
// ADD THE TRIGGER OF THE TOOLTIPS
//////////////////////////////////////////////////////////////////////////
	$(".hasTip").tipTip();


//////////////////////////////////////////////////////////////////////////	
// ACCORDION - Tutorial by Soh Tanaka - http://www.sohtanaka.com/web-design/easy-toggle-jquery-tutorial/
//////////////////////////////////////////////////////////////////////////	

$('.acc_container').hide(); //Hide/close all containers

// if you want to show the first div uncomment the line below  <-- read this
//Add "active" class to first trigger, then show/open the immediate next container
//$('.acc_trigger:first').addClass('active').next().show(); 

$('.acc_trigger').click(function(e){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
		$(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
	} else {
		$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
	}
	e.preventDefault(); //Prevent the browser jump to the link anchor
});


//////////////////////////////////////////////////////////////////////////	
// SIMPLE TABS - Tutorial by Soh Tanaka - http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
//////////////////////////////////////////////////////////////////////////	

	$("#simple-tabs .tab_content").hide(); //Hide all content
	$("#simple-tabs ul.tabs li:first").addClass("active").show(); //Activate first tab
	$("#simple-tabs .tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("#simple-tabs ul.tabs li").click(function(e) {
		$("#simple-tabs ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$("#simple-tabs .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
		e.preventDefault();
	});

//////////////////////////////////////////////////////////////////////////	
// TOGGLES - Tutorial by Soh Tanaka - http://www.sohtanaka.com/web-design/easy-toggle-jquery-tutorial/
//////////////////////////////////////////////////////////////////////////	

	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$(".tgg-trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});
	
	
//////////////////////////////////////////////////////////////////////////	
// ADD ODD CLASS TO ROWS
//////////////////////////////////////////////////////////////////////////	
	
	$(".zebra-style tr:odd, .faq-style .tgg-trigger:odd").addClass("odd");


})// end of window load


//////////////////////////////////////////////////////////////////////////
// HIDDEN MAP FUNCTION
//////////////////////////////////////////////////////////////////////////
	function loadHiddenMap() {
	
	// change this coordinates latitude,longitude - use this tool to get coordinates http://itouchmap.com/latlong.html
var locations = [
      ['Tabu Kalitea', 31.291241, -110.941787, 6],
      ['Tabu Dila', 29.114497, -110.952119, 4],
      ['Tabu Galerias', 29.067498, -110.95125, 5],
      ['Tabu Navarrete', 29.086946, -110.975904, 3],
      ['Tabu Rodriguez', 29.088464, -110.928912, 2],
      ['Tabu Sushi and Martini', 27.493521, -109.930294, 1]
    ];

    var map = new google.maps.Map(document.getElementById('hidden_map'), {
      zoom: 6,
      center: new google.maps.LatLng(29.067498, -110.95125),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
}
