﻿/* Constants */

SECTIONS = new Array();
SECTIONS[0] = 'Weddings';
SECTIONS[1] = 'The Inn';
SECTIONS[2] = 'Parties';
SECTIONS[3] = 'Events';
SECTIONS[4] = 'Jacks';

GALLERY_PATH  = '/gallery/';
HEADER_PHOTO_PATH  = '/cg_common/header_photos/';



function InsertPackages(sectionNo, dest) {
	$.getJSON('/cg_admin/ajax/package_read.php',
		(sectionNo == null) ? { 'active' : true } : { 'section': sectionNo, 'active' : true },
		function(response){
			$(dest).empty();
			$.each(response.data, function(i, item){
				$(dest).append(
					'<h4>' + item.name + 
					(item.image.length > 0 ? '<img src="' + GALLERY_PATH + item.image + '" />' : '') +
					'</h4><p>' + item.description.replace(/\n/g, '<br />') + '</p>'
					);
	          });
	        });
	}



function InsertSpecialPackages(sectionNo, dest) {
	$.getJSON('/cg_admin/ajax/package_read.php',
		{
		active: true,
		special: true,
		section: (sectionNo == null ? '' : sectionNo)
		},
		function(response){
			$(dest).empty();
			$.each(response.data, function(i, item){
				$(dest).append(
					'<h4>' + item.name + 
					(item.image.length > 0 ? '<img src="' + GALLERY_PATH + item.image + '" />' : '') +
					'</h4><p>' + item.description.replace(/\n/g, '<br />') + '</p>'
					);
	          });
	        });
	

	}




/* Submenu Handling */


function BuildSubmenu(menuXMLFile, finalizeFunction) {
	$.get(
		menuXMLFile,
		function(data) {
			var xmlDoc = $(data).find('submenu');
			var newHTML = '<h1>' + xmlDoc.attr('title') + '</h1>';
			newHTML += '<ul>';
			$(xmlDoc).find('link').each(function() { newHTML += "<li onclick=\"location.href='" + $(this).attr('url') + "'\">" + $(this).attr('title') + '</li>'; });
			newHTML += '</ul>';
			$('.sideNav').prepend(newHTML);
			if(finalizeFunction) {
				finalizeFunction();
				}
	        },
		'xml');
	}



function ShowSubmenuGroup(clickedItem) {
	if(clickedItem.id != 'currentMenuGroup') {
		$('#currentMenuGroup + ul').slideUp('fast');
		$('#currentMenuGroup').attr('id', '');
		$(clickedItem).attr('id', 'currentMenuGroup');
		$('#currentMenuGroup + ul').slideDown('fast');
		}
	}



/* Photo Rotator Handling */


ROTATOR_PAUSE = 5000;

rotators = null;
currentRotator = 0;
function NextPhoto() {
	if(++currentRotator < rotators.length) {
		$(rotators[currentRotator]).fadeIn('slow');
		}
	else {
		currentRotator = 0;
		for(i = rotators.length - 2; i > 0; i--) {
			$(rotators[i]).hide();
			}
		$(rotators[rotators.length - 1]).fadeOut('slow');
		}
	}

function StartRotator(destObj, xmlFile) {
	$.get(
		xmlFile,
		function(data) {
			var xmlDoc = $(data).find('rotators');
			newHTML = '';
			$(xmlDoc).find('image').each(function() { newHTML += '<img src="' + HEADER_PHOTO_PATH + $(this).text() + '" />'; });
			$(destObj).html(newHTML);
			rotators = $('#photoRotator img').get();
			setInterval(function() { NextPhoto(); }, ROTATOR_PAUSE); 
	        },
		'xml');

	}





