// JavaScript Document
$(document).ready(function(){
$.ajaxSetup({ cache: false }); // don't cache any ajax processes 
// --- check for iphone or android browsers
if((navigator.userAgent.match(/iPhone/i))||
  (navigator.userAgent.match(/iPod/i))||
  (navigator.userAgent.match(/iPad/i))||
  (navigator.userAgent.match(/Android/i))){
   $('body').css('-webkit-text-size-adjust', 'none');
}
// -------------- navi hover click script --------------------
var hoverClass = 'hover_big_link';
$('.big_link').each(function(){
	$(this).hover(
		function(){
			$(this).addClass(hoverClass);
			status = $(this).find('a').attr('href');
		},
		function(){
			$(this).removeClass(hoverClass);
			status = '';
		}); // end hover
	$(this).click(function(){
			location = $(this).find('a').attr('href');					   
	}); // end click function
	$(this).css('cursor','pointer');
}); // target function
// USE CLASS: hover_change FOR ALL IMAGES TO BE SWAPPED ON HOVER
$('img.hover_change').each(function(){
	var imgFile = $(this).attr('src');
	var preloadImage = new Image();
	var imgExt = /(\.\w{3,4}$)/;
	preloadImage.src = imgFile.replace(imgExt,'-h$1');
	$(this).hover(
		function(){
			$(this).attr('src',preloadImage.src);	
		},
		function(){
			$(this).attr('src', imgFile);
		}
	);
});
// --------- SLIDESHOW -----------------------------------
$('#index_slideshow').html('');
var n_target = '.index_slide';
$(n_target).each(function(){
	$(this).hover(
		function(){ status = $(this).attr('href'); },
		function(){	status = ''; }); // end hover
	$(this).click(ssClickFunctionIdx);
}); // target function
// freeze the slideshow on hover
$('#ss_wrapper').live('mouseover',function(){ stopIdxInterval(); });
$('#ss_wrapper').live('mouseout',function(){ startIdxInterval(); });

runIdxSlideshow(); // activate the slideshow on page load
// -------------------------- END OF SLIDESHOW -----------|
});
var idx_timer = '';
function ssClickFunctionIdx(e){
	e.preventDefault();	
	stopIdxInterval();// stop the counter
	var existingImage = $('#index_slideshow img').attr('src');
	var clickedImage = $(this).attr('href');
	// only click if it is a new picture
	if((existingImage!=clickedImage)||(existingImage==null)||(existingImage=='undefined')){		
		removeIdxActive(); // clear all active classes	
		$(this).addClass('active_slide'); // set this items class to active
		var curId = $(this).attr('id'); // FIND / CREATE SLIDE LINKS - find the id for the new slide
		// use this id to find the appropriate link in the slide_links div
		var dest='', alt='';
		switch(curId){
			case 'slide_1' : dest = $('#link_1').attr('href'); alt = $('#link_1').attr('title'); break;
			case 'slide_2' : dest = $('#link_2').attr('href'); alt = $('#link_2').attr('title'); break;
			case 'slide_3' : dest = $('#link_3').attr('href'); alt = $('#link_3').attr('title'); break;
		}		
		var imgPath = $(this).attr('href'); // find the current slide href
		var oldImage = $('#index_slideshow img'); // replace current slide with a new slide
		var newImage = $('<a href="'+dest+'"><img src="'+imgPath+'" width="575" height"325" alt="'+alt+'"></a>');
		newImage.hide();
		$('#index_slideshow').prepend(newImage);
		newImage.fadeIn(700);
		oldImage.fadeOut(700, function(){ $(this).remove(); });
	}	
	// begin the timer only after the image has loaded - otherwise, just use startIdxInterval();
	$('#index_slideshow img').load(function(){ startIdxInterval(); });
}
function startIdxInterval(){
	if(idx_timer==null||idx_timer==''){ idx_timer = setInterval(runIdxSlideshow, 5000); }
}
function stopIdxInterval(){
	if(idx_timer!=null||idx_timer!=''){ clearInterval(idx_timer); idx_timer = ""; }
}
function runIdxSlideshow(){
	var activeItem = $('#slide_navi').find('.active_slide').attr('id');
	if(activeItem!=null){
		switch(activeItem){
			case 'slide_1' : $('#slide_2').click(); break;
			case 'slide_2' : $('#slide_3').click(); break;
			case 'slide_3' : $('#slide_1').click(); break;
		}
	}
	else{ $('#slide_1').click(); }
}
function removeIdxActive(){
	var activeItem = $('#slide_navi').find('.active_slide');
	activeItem.removeClass('active_slide');
}
// -------- GOOGLE MAPS API -----------------
/*
var map;
var geocoder;
// location lat/lng (33.74775, -78.81563)
function load(){	
  if(GBrowserIsCompatible()){
	var geocoder = new GClientGeocoder();
	var my_point = new GLatLng('33.74775', '-78.81563');
	var my_marker = new GMarker(my_point);
	var map2 = new GMap2(document.getElementById('map_disp'));
	map2.addControl(new GSmallMapControl());
	map2.setCenter(new GLatLng('33.74775', '-78.81563'), 14);	
	map2.addOverlay(my_marker);
	
  }
}
*/
// -----------------------------------------------------------------					   
	// Note that using Google Gears requires loading the Javascript
	// at http://code.google.com/apis/gears/gears_init.js

function initialize() {
    var latlng = new google.maps.LatLng(33.74775, -78.81563);
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_disp"),
        myOptions);
	var marker = new google.maps.Marker({ 
		map: map,
		position: latlng, 
		title: "Lombardo's Bistro" 
	});
	var bubble_content = '<div class="map_bubble">'+
						 '<h3>Lombardos Bistro</h3>'+
						 '<p>411 79th Avenue North</p>'+
						 '<p>Myrtle Beach, SC 29572</p>'+
						 '<p>843-497-6699</p>'+
						 '</div>';
	var infowindow = new google.maps.InfoWindow({
    	content: bubble_content
	});	
	infowindow.open(map,marker);
	
}

	// -----------------------------------------------------------------	
