// JavaScript Document

var j$ = jQuery;

j$(document).ready(init);


var windowWidth = 400;
var windowHeight = 400;

var flashFile = "foo.swf";

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)
	{
		j$('.siteMap ul').columnizer({
			'columns':4});
	}
	else
	{
		j$('.siteMap ul').columnize({'columns':4});
	}
	

	sections = j$('#menuItems .menuSection').size();
//	alert(sections);
	j$('#menuItems .menuSection').each(setSection);
	
	j$('#couponPrint').click(function(){
		j$(this).printElement();
		return false
	 });

	//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('austingrill.com');
				if(cI<0 || cI>12)
				{
					j$(this).attr({'target':'_blank'});
				}
			}
		});

}

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);
	}
	
}

function colFunction()
{
	j$('#menuItems .menuSection .column').width(290);
	j$('#menuItems .menuSection .first').css({'margin-right':30,'margin-left':5});
//	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>");
}
