var newsletterInputSlide = null;
var newsletterOutputSlide = null;

function rememberLocation()
{
	//setCookie('location', locationTitlesCarousel.atScreen );
}

function setCookie(c_name, value)
{
/*
var expiredays = 365;
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
*/
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

/*  ----------------------| FLASH INTEGRATION |----------------------  */	

 function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }
 
 function printPromotion(couponId) {
  var movie = getFlashMovie("CouponSheet");
 	movie.printPromotion(couponId);
 }

/*  ----------------------| NEWSLETTERSUBSCRIPTION INLINE |----------------------  */	

	window.addEvent("domready", function() {
		if($('newsletterform') == null ) return;

		newsletterInputSlide = new Fx.Slide('newsletter-input');
		newsletterOutputSlide = new Fx.Slide('newsletter-output');

		$('newsletterform').addEvent('submit', function(e) {
			/**
			 * Prevent the submit event
			 */
			new Event(e).stop();


			
			
			/**
			 * This empties the log and shows the spinning indicator
			 */
			var log = $('newsletter-output').empty().addClass('ajax-loading');
			newsletterOutputSlide.show();
			newsletterInputSlide.hide();
					 
			/**
			 * send takes care of encoding and returns the Ajax instance.
			 * onComplete removes the spinner from the log.
			 */
			this.send({
				update: log,
				onComplete: function() {
					newsletterOutputSlide.show();
					log.removeClass('ajax-loading');
				}
			});
		});
	});

	function showNewsletterInput()
	{
		newsletterInputSlide.show();
		newsletterOutputSlide.hide();
	}

/*  ----------------------| BLABLAH |----------------------  */	

	window.addEvent('domready', function () {

	$$(".fade").forEach(function(element){
			element.onmouseover =  function(){
				element.firstChild.firstChild.src = element.firstChild.firstChild.src.replace(".jpg","_f2.jpg");
			}
			
			element.onmouseout =  function(){
				element.firstChild.firstChild.src = element.firstChild.firstChild.src.replace("_f2.jpg",".jpg");
			}			

		});

  });

	var locationTitlesCarousel = null;
	
	window.addEvent("domready", function() {
		if($('LocationDetailsCarousel') == null ) return;
		
			locationTitlesCarousel = new iCarousel("LocationTitlesCarouselContent", {
			idPrevious: "btn_prev_location",
			idNext: "btn_next_location",
			idToggle: "undefined",
			onNext: function() { rememberLocation(); },
			onPrevious: function() { rememberLocation(); },
			onGoTo: function() { rememberLocation(); },
			item: {
				klass: "LocationTitlesCarouselItem",
				size: 150
			},
			animation: {
				type: "scroll",
				duration: 600,
				amount: 1
			}
			
		});
		
		var loc=getCookie('location');
		if (loc!=null && loc!="") locationTitlesCarousel.goTo(loc);	
		
		var fade = new Fx.Style('LocationTitlesCarouselContent', 'opacity',{duration:800});
		fade.start(0,1);	
	});
	
	var locationDetailsCarousel = null;
	
	window.addEvent("domready", function() {
		if($('LocationDetailsCarousel') == null ) return;
			
			locationDetailsCarousel = new iCarousel("LocationDetailsCarouselContent", {
			idPrevious: "btn_prev_location",
			idNext: "btn_next_location",
			idToggle: "undefined",
			item: {
				klass: "LocationDetailsCarouselItem",
				size: 800
			},
			animation: {
				type: "scroll",
				duration: 600,
				amount: 1
			}
			
		});
		
		var fade = new Fx.Style('LocationDetailsCarouselContent', 'opacity',{duration:800});
		fade.start(0,1);
		
		loc=getCookie('location');
		if (loc!=null && loc!="") locationDetailsCarousel.goTo(loc);
		
	});

/* NEWSLETTER SUBSCRIPTION AJAX FORM */

	window.addEvent("domready", function() {
		if($('myForm') == null ) return;
		
		alert("!");
		
		$('myForm').addEvent('submit', function(e) {
			/**
			 * Prevent the submit event
			 */
			new Event(e).stop();
			
			/**
			 * This empties the log and shows the spinning indicator
			 */
			var log = $('log_res').empty().addClass('ajax-loading');
		 
			/**
			 * send takes care of encoding and returns the Ajax instance.
			 * onComplete removes the spinner from the log.
			 */
			this.send({
				update: log,
				onComplete: function() {
					log.removeClass('ajax-loading');
					$('myForm').empty();
				}
			});
		});
	});

window.addEvent("!domready", function() {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(39.480991, -87.271614), 11);
			
			var point = new GLatLng(39.414208,-87.406805);			
			var marker = new GMarker(point,{title:'yo'});
				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml('<p>test</p>');
				})			
			map.addOverlay(marker);
			
			point = new GLatLng(39.44201,-87.413836);
			map.addOverlay(new GMarker(point));

			point = new GLatLng(39.492235,-87.360165);
			map.addOverlay(new GMarker(point));		

			point = new GLatLng(39.526636,-87.112334);
			map.addOverlay(new GMarker(point));			
			

		}
	});