$(document).ready(function() { // As soon as the document loads, do this...
	loadScripts();
});

function killFrames() {
	// If the page is loaded in a frame, bypass the frame and reload in the top of the browser.
	if (top != self) {
		top.location.href = self.location.href
	}
}

function loadScripts() {
	// Load script files and jQuery plugins separate from the HTML. 
	// http://plugins.jquery.com/project/xLazyLoader
	$.xLazyLoader({
		css: [
			'http://www.durham-nc.com/resources/.template/includes/calendar/calendar-dcvb.css'
		],
		js: [
			'http://www.durham-nc.com/resources/.template/includes/swfobject.js',
			'http://www.durham-nc.com/resources/.template/includes/video/flowplayer-3.1.0.min.js',
			'http://www.durham-nc.com/resources/.template/includes/calendar/calendar.js',
			'http://www.durham-nc.com/resources/.template/includes/calendar/calendar-setup.js',
			'http://www.durham-nc.com/resources/.template/includes/calendar/calendar-en.js',
			'http://www.durham-nc.com/resources/.template/includes/calendar/calendar-extras.js'
		],
		img: [
//			'http://www.durham-nc.com/resources/.template/images/lodging-hotline-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/ql-chat-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/ql-lodging-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/ql-guide-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/ql-maps-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-about-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-lodging-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-things-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-dining-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-visitors-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-planners-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-newcomers-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-films-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/nav-media-over.gif',
//			'http://www.durham-nc.com/resources/.template/images/widget-hotel.jpg',
//			'http://www.durham-nc.com/resources/.template/images/widget-air.jpg',
//			'http://www.durham-nc.com/resources/.template/images/widget-car.jpg',
//			'http://www.durham-nc.com/resources/.template/images/widget-packages.jpg'
		],
		/*
		name: '',
		*/
		success: function(){
			modifyHtml();
		},
		error: function(){
			
		},
		each: function(url){
			
		}
	
	});
}

function modifyHtml() {
	// For each list, mark up the first and last items.
	$('ul,ol,dl').each(function() {
		$(this).children('li:first,dt:first').addClass('first');
		$(this).children('li:last,dt:last').addClass('last');
	});
	$('ul').addClass('tier1');
	$('ul ul').each(function() {
		$(this).removeClass('tier1');
		$(this).addClass('tier2');
	});
	$('ul ul ul').each(function() {
		$(this).removeClass('tier2');
		$(this).addClass('tier3');
	});
	
	$('#logo').append('<div id="printContacts" class="forPrint"><p>Durham Convention & Visitors Bureau<br />101 East Morgan Street, Durham, NC 27701<br />toll free: (800) 446-8604 | local: (919) 687-0288</p></div>');
	$('#logo').append('<div id="printUrl" class="forPrint"><span class="label">Find this page at: </span><br /><span class="url">' + window.location + '</span></div>');
	
	$('#listings div.item:even').each(function() {
		$(this).addClass('even');
	});
	$('#listings div.item:odd').each(function() {
		$(this).addClass('odd');
	});
	
	// Insert a listing's URL before the description.
	$('#listings .url').each(function() {
		// Add zero-width non-joiner character after each URL slash to allow IE to wrap URLs.
		var orgUrl = $(this).attr('href');
		orgUrl = orgUrl.replace(/\//g,'/&#8203;');
		var $insertionPoint;
		var $itemName = $(this).closest('.item-name');
		var $tel = $itemName.siblings('.tel');
		var $adr = $itemName.siblings('.adr');
		if($tel.length) {
			$insertionPoint = $tel;
		} else if($adr.length) {
			$insertionPoint = $adr;
		} else {
			$insertionPoint = $itemName;
		}
		$insertionPoint.after('<div class="item-url forPrint">' + orgUrl + '</div>');
	});
	
	if($('#start').length) {
		setupCalendar();
	}
}


function translate()
   {
   var w = document.langForm.langOptions.selectedIndex;
   var url_add = document.langForm.langOptions.options[w].value;
   window.location.href = url_add;
   }


function backButton() {
	document.write('<a href="javascript:history.go(-1);" onmouseover="self.status=document.referrer;return true;">&lt;&lt; Go Back</a>');
	}

function searchAppliance() {
	document.write('<form method="get" action="http://search.durham-nc.com/search">');
    document.write('<input type="hidden" name="site" value="default_collection" />');
    document.write('<input type="hidden" name="client" value="default_frontend" />');
    document.write('<input type="hidden" name="proxystylesheet" value=" default_frontend" />');
    document.write('<input type="hidden" name="output" value="xml_no_dtd" />');
    document.write('<input name="q" type="text" id="query" value="" />');
	document.write('<input name="btnG" type="image" id="Search" value="Google Search" src="http://www.durham-nc.com/images/template/go-button.gif" alt="Go" />');
    document.write('</form>');
	}

function initDate()
{
	var now = new Date();
	var mth = now.getMonth();
	var dd = now.getDate();
	var yy = now.getFullYear();
	if (mth <10)
	{
		mth == 0 + mth;
	}
	if (dd <10)
	{
		dd == 0 + dd;
	}
	if ((mth==11) && (dd>=29)) {
/*		document.resrvForm.doa_mm.selectedIndex = mth;
		document.resrvForm.doa_dd.selectedIndex = dd - 1;
		document.resrvForm.dod_yy.value= yy;
		document.resrvForm.dod_dd.selectedIndex = dd - dd;
		document.resrvForm.dod_mm.selectedIndex = mth-mth;
		document.resrvForm.dod_yy.value= yy+1;*/
		document.getElementById('CB_frommonth').selectedIndex = mth;
		document.getElementById('CB_fromdate').selectedIndex = dd - 1;
		document.getElementById('CB_todate').selectedIndex = dd - dd;
		document.getElementById('CB_tomonth').selectedIndex = mth-mth;
		document.getElementById('AIR_frommonth').selectedIndex = mth;
		document.getElementById('AIR_fromdate').selectedIndex = dd - 1;
		document.getElementById('AIR_todate').selectedIndex = dd - dd;
		document.getElementById('AIR_tomonth').selectedIndex = mth-mth;
		document.getElementById('CAR_frommonth').selectedIndex = mth;
		document.getElementById('CAR_fromdate').selectedIndex = dd - 1;
		document.getElementById('CAR_todate').selectedIndex = dd - dd;
		document.getElementById('CAR_tomonth').selectedIndex = mth-mth;
	}
	else if ((dd>=29 ) || ((dd>=27 ) && (mth==1)))
	{
/*		document.resrvForm.doa_mm.selectedIndex = mth+1;
		document.resrvForm.doa_dd.selectedIndex = dd-dd;
		document.resrvForm.doa_yy.value= yy;
		document.resrvForm.dod_dd.selectedIndex = (dd-dd)+1;
		document.resrvForm.dod_mm.selectedIndex = mth + 1;
		document.resrvForm.dod_yy.value= yy;*/
		document.getElementById('CB_frommonth').selectedIndex = mth+1;
		document.getElementById('CB_fromdate').selectedIndex = dd-dd;
		document.getElementById('CB_todate').selectedIndex = (dd-dd)+1;
		document.getElementById('CB_tomonth').selectedIndex = mth + 1;
		document.getElementById('AIR_frommonth').selectedIndex = mth+1;
		document.getElementById('AIR_fromdate').selectedIndex = dd-dd;
		document.getElementById('AIR_todate').selectedIndex = (dd-dd)+1;
		document.getElementById('AIR_tomonth').selectedIndex = mth + 1;
		document.getElementById('CAR_frommonth').selectedIndex = mth+1;
		document.getElementById('CAR_fromdate').selectedIndex = dd-dd;
		document.getElementById('CAR_todate').selectedIndex = (dd-dd)+1;
		document.getElementById('CAR_tomonth').selectedIndex = mth + 1;
	}
	else
	{
/*		document.resrvForm.doa_mm.selectedIndex=mth;
		document.resrvForm.doa_dd.selectedIndex=dd+1;
		document.resrvForm.dod_yy.value= yy;
		document.resrvForm.dod_mm.selectedIndex=mth;
		document.resrvForm.dod_dd.selectedIndex=dd+3;
		document.resrvForm.dod_yy.value= yy;*/
		document.getElementById('CB_frommonth').selectedIndex=mth;
		document.getElementById('CB_fromdate').selectedIndex=dd-1;
		document.getElementById('CB_tomonth').selectedIndex=mth;
		document.getElementById('CB_todate').selectedIndex=dd+1;
		document.getElementById('AIR_frommonth').selectedIndex=mth;
		document.getElementById('AIR_fromdate').selectedIndex=dd-1;
		document.getElementById('AIR_tomonth').selectedIndex=mth;
		document.getElementById('AIR_todate').selectedIndex=dd+1;
		document.getElementById('CAR_frommonth').selectedIndex=mth;
		document.getElementById('CAR_fromdate').selectedIndex=dd-1;
		document.getElementById('CAR_tomonth').selectedIndex=mth;
		document.getElementById('CAR_todate').selectedIndex=dd+1;
	}
}

function sendArtData()
{
    var value = '';
    var art = document.art;
    var art_types = art.art_types;    

    for (i = 0; i < art_types.length; i++)
    {
        if (art_types[i].checked)
        {
            value += art_types[i].value + ",";
        }
    }

    value = value.replace(/,$/, '');
    document.art.art_types_submit.value = '(' + value + ')';

    art.submit();
}

function hideLocationMenus(menus)
{
	for (i in menus)
	{
		document.getElementById(menus[i]).style.display = 'none';
	}
}

function changeLocationMenus(mySelect)
{
	// Hide all menus
	hideLocationMenus(new Array('location', 'durhamDistrict', 'otherDiningArea'));

	// Hide location comments
	for (i = 0; i < 10; i++)
	{
		document.getElementById('description' + i).style.display = 'none';
	}

	menuName = mySelect.value;
	document.getElementById(menuName).style.display = 'block';
}

function resetLocationDropdown()
{
	document.getElementById('durhamDistrictRadio').checked='checked';
}

function hideElement(elementName)
{
	document.getElementById(elementName).style.visibility = 'hidden';
}

function setupCalendar () {
	Calendar.setup({
		inputField  : "start",         // ID of the input field
		button      : "start"       // ID of the button
	});
	var myDate = new Date();
	var day = myDate.getDate();
	var month = myDate.getMonth() + 1;
	var year = myDate.getFullYear();
	document.getElementById("start").value = month + "/" + day + "/" + year;
	Calendar.setup({
		inputField  : "end",         // ID of the input field
		button      : "end"       // ID of the button
	});
}

