// JavaScript Document

var j$ = jQuery;


if(j$.browser.msie && j$.browser.version<7)
{
	j$(window).load(init);
}
else
{
	j$(document).ready(init);
	j$(window).load(resizeColumns);
}



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

var ii = 0;
var sections = 0;

function init()
{
	windowWidth = j$(window).width();
	windowHeight = j$(window).height();
	
	j$('table').attr({'cellspacing':0, 'width':'100%'});
	
	
	
	if(j$.browser.msie && j$.browser.version<7)
	{
		resizeColumns();
	}
	else
	{
		wrapDivs();
	}
	
	j$('.remove').remove();
	
	var resPageWidth = 1000;
	if(windowWidth < resPageWidth)
	{
		resPageWidth = windowWidth;
	}
	
//fix content inside text message iframe
	j$('#reservations .boxen').boxen({'width':resPageWidth,'height':380});
	j$('#textMessaging .boxen').boxen({'width':620,'height':670});
	

	j$('.siteMap ul').columnize({'columns':4});
	sections = j$('#menuItems .menuSection').size();
//	alert(sections);
	j$('#menuItems .menuSection').each(setSection);

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

}


function wrapDivs()
{
	j$('.wrapper_inner').wrapInner("<div class='ulc'><div class='urc'></div></div>");	
	j$('.subnavContainer li').append('<div class="bottom"></div>').prepend('<div class="top"></div>');
}

function resizeColumns()
{	
	lcHeight = 0;
	lcHeight = 0;
	lcTop = 0;
	rcTop = 0;
	contentHeight = 0;
	lcHeight = j$('.leftCol').height() - 560;
	if(j$.browser.msie && j$.browser.version<7)
	{
		lcHeight = j$('.leftCol .subnavContainer').height();
		lcHeight += j$('.leftCol .socialIcons').height();
//		alert(lcHeight);
	}
	
	lBgOffset = "-5px "+ lcHeight +"px";
	
	contentHeight = j$('.content').height();
	if(contentHeight < 570)
	{
		contentHeight = 570;
		j$('.content .middle').height(420);
	}
	
	j$('.leftCol').css({'background-position': lBgOffset});
	j$('#index .leftCol').css({'background-position': "left top"});

	lcTop = j$('.leftCol').outerHeight(true) - j$('.leftCol').height();

	lcHeight = contentHeight - lcTop -10;
	j$('.leftCol').height(lcHeight);
	rcTop = j$('.rightCol').outerHeight(true) -  j$('.rightCol').height() ;

	rcHeight = contentHeight - rcTop -10;
	j$('.rightCol').height(rcHeight);
	
}

function setSection(){
	var ct = j$(this).children().size();
	var contentString = j$(this).html();
//	alert(contentString);
//	alert(contentString.indexOf('No documents'));
	if(contentString.indexOf('No documents') > -1)
	{
		j$(this).remove();
	}
//	else
//	{
//		j$(this).prepend("<div class='block dontsplit'></div>");
//		j$(this).append("<div class='block dontsplit'></div>");
//		
//	}
	
	ii++
//	alert(ii);
	if(ii == sections)
	{
		ii = 0;
		sections = j$('#menuItems .menuSection').size();
//		alert(sections);
//		j$('#menuItems .menuSection').each(runColumnize);
		j$('#menuItems .menuSection').columnize({columns:2, dontsplit:'div'}).each(countColumnize);
	}
	
}

function countColumnize()
{
	j$('#menuItems .menuSection .column').width(240).css({'float':'left'});
	j$('#menuItems .menuSection .column:even').css({'margin-right':20});
//	j$('#menuItems .menuSection').each(addTitles);
	ii++
//	alert(ii);
	if(ii == sections)
	{
		j$('#menuItems div.menuSection').each(addTitles);
	}
}
var ie6Titles = false;

function runColumnize()
{
	alert(j$(this).attr('title'));
	if(j$.browser.msie && j$.browser.version<7)
	{
		if(ie6Titles == false)
		{
			ie6Titles = true;
			j$('#menuItems div.menuSection').each(addTitles);
		}
	}
	else
	{
		j$(this).columnize({
			columns:2
//			lastNeverTallest:true,
//			doneFunc:colFunction
		});
	}
	
}

function addTitles()
{
	var title = j$(this).attr('title');
//	alert(title);
	j$(this).prepend("<h2>"+title+"</h2>");
	j$(this).css({'overflow':'hidden'});
}
