// JavaScript Document

var j$ = jQuery;

	j$(document).ready(init);
	j$(window).load(loaded);

var windowWidth = 400;
var windowHeight = 400;
var contentHeight = 0;
var lcHeight = 0;
var rcHeight = 0;
var lcTop = 0;
var rcTop = 0;

var ii = 0;
var sections = 0;

var navWidth = 0;

var geocoder, map, addressMarker, gdir, fromAddress, toAddress;

function init()
{
	//ASSIGN VALUES TO GLOBALS
	windowWidth = j$(window).width();
	windowHeight = j$(window).height();
////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
	//TABLE RESET
	j$('table').attr({'cellspacing':0, 'width':'100%'});
	j$('td').attr({'valign':'top'});
////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
	//add miss priss
	if(j$.browser.msie && j$.browser.version<7 || !j$('body#index').length)
	{
	}
	else
	{
		j$('#leftCol').append('<div id="missPriss"><img src="/assets/images/missPrissGown.png" alt="Miss Priss Gown" /></div>');
	}
////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
	//apply target="blank" to OUTGOING LINKS
	j$('a').each(function(i){
			var h=j$(this).attr('href');
			if(h.indexOf('http://')>-1)
			{
				var cI = h.indexOf('victoriansquareshoppes.com');
				if(cI<0 || cI>12)
				{
					j$(this).attr({'target':'_blank'});
				}
			}
		})
////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
	//sifr
	if(j$.browser.msie && j$.browser.version<8)
	{
	}
	else
	{
		j$('h1').sifr({
				font: '/assets/templates/vss/js/sifr.swf',
	//			debug: true,
				version: 3,
				build: 436,
				width: 573,
				lineHeight:20,
				overY:1.2
		});
		var headlineHeight = j$('.sIFR-flash>*:first').attr('height');
		j$('h1').css({'height':headlineHeight+'px'});
	}
	if(j$.browser.msie && j$.browser.version>=8)
	{
		j$('.sIFR-alternate').css({'visibility':'hidden'});
	}
////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
	//anything slider
	j$('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 6000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 600,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",             // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: navFormat       // Details at the top of the file on this use (advanced use)
	});
	function navFormat(index, panel){
		return panel.attr('title')
//		return index + " Toot"; // This would have each tab with the text 'X Panel' where X = index
	}
	
	var numThumbs = j$('#thumbNav a').size();
	j$('#thumbNav a').each(function(i){
										var tw = j$(this).width();
										if(tw > navWidth)
										{
											navWidth = tw;
										}
										if(i+1 >= numThumbs)
										{
											j$('#thumbNav a').width(navWidth).css({'text-align':'left'});
										}
									});
	
////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
	//map page
	
	if(j$('body').hasClass('mapPage'))
	{
		 toAddress = '401 West Main Street, Lexington, KY 40507';

		map = new GMap2(document.getElementById('mapCanvas'));
		gdir  = new GDirections(map, document.getElementById("directions"));
		j$('body').append('<div id="message">toot</div>');
		j$('#message').hide();
		j$('#section2').append('<ul id="locationList"></ul>');
		var victorianSquare = new GLatLng(38.0489785, -84.4999079);
		
		var markers = [];
		var marker
		
		marker = new GMarker(victorianSquare);
		marker.name= 'Victorian&nbsp;Square<br />Shoppes&nbsp;&amp;&nbsp;Entertainment';
		marker.address = '401&nbsp;West&nbsp;Main&nbsp;Street<br />Lexington,&nbsp;KY&nbsp;40507';
		map.addOverlay(marker);
		markers.push(marker);
		
		
		map.setCenter(victorianSquare, 14);
		
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		
		j$(markers).each(function(i,marker){
			  GEvent.addListener(marker, "mouseover", function(){
				displayPoint(marker,i);
			});
			  GEvent.addListener(marker, "click", function(){
				  map.panTo(marker.getLatLng());
			});
			  GEvent.addListener(marker, "mouseout", function(){
				hidePoint(marker,i);
			});
		});
		
		j$("#message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
	}
	
	
////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
	//location link buttons
	var locBtnWid = 0;
	j$("#locationInfo a").each(function(){
									     var ww = j$(this).width();
										 if(ww > locBtnWid)
										 {
											 locBtnWid = ww;
										 }
									   })
	j$("#locationInfo a").width(locBtnWid + 10).css({'display':'block'})
	
}

function loaded()
{
	if(windowWidth % 2 > 0 && windowWidth >= 980)
	{
//		alert('bing');
		windowWidth -= 1;
		j$('body').width(windowWidth);
	}
	if(windowHeight > j$('#wrapperOuter').height())
	{
		var htDiff = windowHeight - j$('#wrapperOuter').height();
		j$('#footOuter').css({'padding-bottom': 40 + htDiff});
	}
}

function displayPoint(marker, i)
{
	var pointname = marker.name;
	var pointaddress = marker.address;
	var contents = "<h4>"+ pointname +"</h4><p>"+ pointaddress +"</p>";
	
//			map.panTo(marker.getPoint());
	var markerOffset = map.fromLatLngToDivPixel(marker.getPoint());
	j$("#message").show().css({ top:markerOffset.y, left:markerOffset.x }).html(contents);
}
function hidePoint(marker, i)
{
	j$("#message").hide();
}

function overlayDirections()
{
	fromAddress =
	  document.getElementById("street").value
	  + " " + document.getElementById("city").value
	  + " " + document.getElementById("state").options[document.getElementById("state").selectedIndex].value
	  + " " + document.getElementById("zip").value;
	gdir.load("from: " + fromAddress + " to: " + toAddress);
}
		  
