$(Stedmans);

// Global variables
var EventsGalleryCurrentItem;

function Stedmans() {

	// Carousel controller
	$('#carousel').hide().delay(1000).fadeIn('fast', 'linear');
	
	$('#carousel').innerfade({
		animationtype:'fade',
		speed:'slow',
		timeout:'5000'
	});
	
	// Navigation controls
	$('#navigation ul li a').mouseenter(function(){
		$(this).parent('li').addClass('hover');
		$(this).next('ul').show();
	});
	
	$('#navigation ul li').mouseleave(function(){
		$(this).children('ul').hide();
		$(this).removeClass('hover');
	});
	
	// Caption controller
	$('#navigation').hover(function(){
		$('#navigation').css('z-index','100');
		$('#header #carousel .caption').fadeOut('fast', 'linear').hide();
	}, function(){
		$('#navigation').css('z-index','0');
		$('#header #carousel .caption').fadeIn('fast', 'linear').show();
	});
	
	// Description controller
	// Display descriptions for menu items.
	function SetDescription(menu, description) {
		var selector = '#menu-' + menu + ' ul .description';
		$(selector).html(description);
	}
	
	$('#menu-1 a').hover(function(){SetDescription(1, 'Because we understand hospitality service, Stedmans is the first choice for Sydney\'s most successful event organisers, premier venues, caterers, restaurants and private homes.')});
	
	$('#menu-1 [title="Your event"]').hover(function(){
		SetDescription(1, 'Hospitality is not only about serving food and drink - it\'s about creating an atmosphere.');
	});
	
	$('#menu-1 [title="Events gallery"]').hover(function(){
		SetDescription(1, 'Our regular corporate clients include; Louis Vuitton, Paspaley, Dior, Gucci, David Jones, Myers, Space Furniture, Moet &amp; Chandon...');
	});
	
	$('#menu-1 [title="Affiliates"]').hover(function(){
		SetDescription(1, 'After twenty years we\'ve learned a trick or two about making any party a fun experience to organise as well.');
	})
	
	$('#menu-3 a').hover(function(){
		SetDescription(3, 'We offer various practical short courses that will have you working at major Sydney events or restaurants, cafés and bars immediately.');
	});
	
	$('#menu-3 [title="Hospitality courses"]').hover(function(){
		SetDescription(3, 'Hospitality courses - All the short-course learning you need to start working in restaurants, cafés, bars and functions. Casual agency work at Stedmans may be available on completion of these courses.');
	});
	
	$('#menu-3 [title="Room hire"]').hover(function(){
		SetDescription(3, 'Stedmans facilities are available for hire on a daily, or half-daily basis. Facilities include large rooms, conference & training furniture, audio visual and other training equipment, fully-equipped bar and fridge, espresso machine, photographic space, staff and catering.');
	});
	
	$('#menu-4 a').hover(function(){
		SetDescription(4, 'We are always looking for motivated people who want to create a career in hospitality. If you think you have the right attitude and standards, contact us to begin your training.');
	});
	
	$('#menu-4 [title="Requirements"]').hover(function(){
		SetDescription(4, 'Stedmans\'s staff are renowned for their open friendly manner, their professional presentation and capable air. Stedmans offers hospitality courses to reach appropriate standards of service.');
	});
	
	$('#menu-4 [title="Standards"]').hover(function(){
		SetDescription(4, 'If you are seeking work with us you will require a reliable nature and keen attitude. Legally, you will also need to be over 18 years of age, have a current Australian work visa, an Australian Tax File Number and an RSA (Responsible Services of Alcohol) certificate - which, if necessary, we can train you to achieve.');
	});
	
	$('#menu-4 [title="Timesheet"]').hover(function(){
		SetDescription(4, 'Timesheets are of course very important if you want to be paid! You can either fill out one here on-line, or download, print and fax (or post) a PDF timesheet.');
	});
	
	$('#menu-5 a').hover(function(){
		SetDescription(5, 'Come and meet the Stedmans\' team. Our senior staff bring with them a complete corporate knowledge of entertaining in Sydney.');
	});
	
	$('#menu-5 [title="Core team details"]').hover(function(){
		SetDescription(5, 'After 20 years of working with the largest and most prestigious events companies, venues, caterers and regulatory bodies, we\'ve developed some finely honed talents for what people want from their big night out. Talk to us about your event.');
	});
	
	$('#menu-5 [title="Q Talent"]').hover(function(){
		SetDescription(5, 'Stedmans sister company, "Q Talent", is an extras\' casting agency which employs, trains and presents their clients. We also take on all the legal responsibilities and administrative tasks that come with employing extras.');
	});
	
	// Two images with captions controller
	$('#two_images_with_captions img').hover(function(){
		$(this).fadeTo('fast','1').css('z-index','1');
		$('#two_images_with_captions img').not(this).fadeTo('fast','0.1').css('z-index','0');
		$(this).parent('a').next('p').toggle();
	}, function(){
		$('#two_images_with_captions img').fadeTo('fast','1');
		$(this).parent('a').next('p').toggle();
	});
	
	// Three images with captions controller
	// -------------------------------------
	// On pages with the three images element, when you hover over one of those images the others will fade out, 
	// be sent behind the hovered element and the caption for the element will be displayed.
	$('#three_images_with_captions img').hover(function(){
		$(this).fadeTo('fast', '1').css('z-index', '1');
		$('#three_images_with_captions img').not(this).fadeTo('fast', '0.1').css('z-index', '0');
		$(this).parent('a').next('p').toggle();	
	}, function(){
		$('#three_images_with_captions img').fadeTo('fast','1');
		$(this).parent('a').next('p').toggle();
	});
	
	// Events and staff types controller
	// ---------------------------------
	
	// Set the width of the staff images ul so that it fits all the content horizontally,
	// keeping in mind that each image module is 150px wide.
	var imageWidth = 150;
	var numberOfImages = $('#your_event #staff_images ul > li').size();
	var containerWidth = numberOfImages * imageWidth;
	containerWidth = containerWidth + 'px';
	$('#your_event #staff_images ul').css('width',containerWidth);
	
	// Scrolling controller
	// This controls the buttons that scroll left and right
	$('#your_event #prevnext #previous').click(function(){
		$('#your_event #staff_images').scrollTo({top:'0', left:'-=150px'}, {duration:'fast'});
	});
	
	$('#your_event #prevnext #next').click(function(){
		$('#your_event #staff_images').scrollTo({top:'0', left:'+=150px'}, {duration:'fast'});
	});
	
	// Hover over an image and the caption fades in and out
	$('#your_event #event_images ul li, #your_event #staff_images ul li').hover(function(){
		$(this).children('p').fadeIn('fast');
	}, function(){
		$(this).children('p').fadeOut('fast');
	});
	
	// Hover over a link on the left and the caption on the image (if the image is displayed) will fade in and out
	$('#your_event #controller ul li').hover(function(){
		var attr = $(this).html();
		
		// Fix issue with the interpretation of &amp; in the HTML to the CSS.
		// Might be a bit ugly, but I preferred to stick with &amp; in the HTML.
		if (attr == 'Cook &amp; serve') {
			attr = 'Cook and serve';
		}
		var selector = '#event_images ul [title="'+attr+'"] p, #staff_images ul [title="'+attr+'"] p';
		$(selector).fadeIn('fast');
	}, function(){
		var attr = $(this).html();
		
		// Fix issue with the interpretation of &amp; in the HTML to the CSS.
		if (attr == 'Cook &amp; serve') {
			attr = 'Cook and serve';
		}
		var selector = '#event_images ul [title="'+attr+'"] p, #staff_images ul [title="'+attr+'"] p';
		$(selector).fadeOut('fast');
	});
	
	// Click image so that it goes to a single view
	$('#your_event #event_images ul li').click(function(){
		var list = $('#your_event #event_images ul li');
		var item = list.index(this);
		// Add one to the item because the list index begins at 0, :nth-child index begins at 1.
		item++;
		ShowEventOrStaff('event', item);
	});
	
	$('#your_event #staff_images ul li').click(function(){
		var list = $('#your_event #staff_images ul li');
		var item = list.index(this);
		// Add one to the item because the list index begins at 0, :nth-child index begins at 1.
		item++;
		ShowEventOrStaff('staff', item);
	});
	
	// Click sidebar so that image becomes single view
	$('#your_event #controller ul.events li').click(function(){
		var list = $('#your_event #controller ul.events li');
		var item = list.index(this);
		// Add one to the item because the list index begins at 0, :nth-child index begins at 1.
		item++;
		ShowEventOrStaff('event',item);
	});
	
	$('#your_event #controller ul.staff li').not('.no-image').click(function(){
		var list = $('#your_event #controller ul.staff li');
		var item = list.index(this);
		// Add one to the item because the list index begins at 0, :nth-child index begins at 1.
		item++;
		ShowEventOrStaff('staff',item);
	});
	
	// And one for the links that don't have associated images
	$('#your_event #controller ul.staff li.no-image').click(function(){
		$('#event_images:visible, #staff_images:visible, #prevnext').fadeOut('fast');
		$('#imagebox:visible').fadeOut('fast');
		$('#imagebox img').hide();
		$('#imagebox p:first').html('Please speak to our consultants for further information');
		$('#imagebox p.attribute').html('');
		$('#imagebox').fadeIn('fast');
		return false;
	});
	
	// Events gallery controller
	// -------------------------
		
	// Set the width of the images ul so that it attempts to even out the number of pictures on each row,
	// keeping in mind each image module is 150px wide.
	var imageWidth = 150;
	var numberOfImages = $('#events_gallery #images ul > li').size();
	
	var numberOfImagesOnTopRow = Math.ceil(numberOfImages/2);
	var containerWidth = numberOfImagesOnTopRow * imageWidth;
	containerWidth = containerWidth+'px';
	$('#events_gallery #images ul').css('width',containerWidth);
	
	// Scrolling controller
	// This controls the buttons that scroll left and right if all the images are visible,
	// Or slides between the images if only one image is visible.
	$('#events_gallery #controller #previous').click(function(){
		if ($('#events_gallery #images').is(':visible')) {
			$('#events_gallery #images').scrollTo({top:'0', left:'-=150px'}, {duration:'fast'});
		} else {
			item = EventsGalleryCurrentItem;
			// If we're at the start of the list, don't go any further.
			if (item > 0) { item--; }
			ShowEvent(item);
		}
	});
	
	$('#events_gallery #controller #next').click(function(){
		if ($('#events_gallery #images').is(':visible')) {
			$('#events_gallery #images').scrollTo({top:'0', left:'+=150px'}, {duration:'fast'});
		} else {
			item = EventsGalleryCurrentItem;
			// If we're at the end of the list, don't go any further.
			if (item < numberOfImages-1) { item++; }
			ShowEvent(item);
		}
	});
	
	// Hover over an image and the caption fades in and out
	$('#events_gallery #images ul li').hover(function(){
		$(this).children('p').fadeIn('fast');
	}, function(){
		$(this).children('p').fadeOut('fast');
	});
	
	// Click image so that it goes to a single view
	$('#events_gallery #images ul li').click(function(){
		var list = $('#events_gallery #images ul li');
		var item = list.index(this);
	
		ShowEvent(item);
	});
	
	// Staff types controller
	// ----------------------
	// Hover over an image and the caption fades in and out
	$('#staff_types #images ul li').hover(function(){
		$(this).children('p').fadeIn('fast');
	}, function(){
		$(this).children('p').fadeOut('fast');
	});
	
	// Hover over a link on the left and the caption on the image (if the image is displayed) will fade in and out
	$('#staff_types #controller ul li a').hover(function(){
		var attr = $(this).html();
		
		// Fix issue with the interpretation of &amp; in the HTML to the CSS.
		// Might be a bit ugly, but I preferred to stick with &amp; in the HTML.
		if (attr == 'Cook &amp; serve') {
			attr = 'Cook and serve';
		}
		var selector = '#staff_types #images ul [title="'+attr+'"] p';
		$(selector).fadeIn('fast');
	}, function(){
		var attr = $(this).html();
		
		// Fix issue with the interpretation of &amp; in the HTML to the CSS.
		if (attr == 'Cook &amp; serve') {
			attr = 'Cook and serve';
		}
		var selector = '#staff_types #images ul [title="'+attr+'"] p';
		$(selector).fadeOut('fast');
	});
	
	// Sandpit code
	// ------------
	
	// Progress through background images on the header:
	setInterval(function() {
		console.log('go');
	}, 10000000);
	
}

// Functions
// ---------
// Function to hide the staff types images and display the single image

// Function to show the event or staff image with content.
// For use on the Hospitality for you > Your event page.
function ShowEventOrStaff(type, item) {
	if (type == 'event') {
		var type = '#event_images';
	} else if (type == 'staff') {
		var type = '#staff_images';
	}
	
	selector = '#your_event '+type+' ul li:nth-child('+item+')';
	var content = $(selector).attr('content');
	var image = $(selector).attr('image');
	var attribute = $(selector).attr('attribute');

	$('#event_images:visible, #staff_images:visible, #prevnext').fadeOut('fast');
	$('#imagebox:visible').fadeOut('fast');
	$('#imagebox img').show().attr('src','images/hospitality-for-you/your-event/'+image);
	$('#imagebox p:first').html(content);
	$('#imagebox p.attribute').html(attribute);
	$('#imagebox').fadeIn('fast');
	return false;
}

function ShowStaff(staff) {
	var content = [
	{image:'images/employment-pages/requirements/supervisor.jpg',text:'Supervisor<br>Our supervisors possess all of the necessary skills and experience to provide the leadership our clients and staff expect on the job. They represent our most senior personnel, and are key in delivering the high standards that are synonymous with Stedmans.',attribute:'Photo: Robert Rosen'},
	{image:'images/employment-pages/requirements/boardroom_waiter.jpg',text:'Boardroom waiter<br>Our Boardroom waiters have the ability to work unsupervised; are well versed in corporate boardroom etiquette; can liaise with clients directly; set tables; serve guests professionally in a variety of situations and adhere to RSA legislation.',attribute:'Coco Republic, Calvin Klein Launch 2010<br>Photo: Fiora Sacco'},
	{image:'images/employment-pages/requirements/private_home_waiter.jpg',text:'Private home waiter<br>A Private Home Waiter is a very experienced senior Boardroom Waiter; they have the ability to work unsupervised in private houses to the high standards expected of private clients.',attribute:'Photo: Robert Rosen'},
	{image:'images/employment-pages/requirements/a_la_carte_waiter.jpg',text:'A la carte waiter<br>Our Professional industry waiters are capable of working in a restaurant or caf&eacute; environment. They understand how to work a section of a restaurant, provide wine and general guest service.',attribute:'Photo: Robert Rosen'},
	{image:'images/employment-pages/requirements/function_waiter.jpg',text:'Event waiter<br>An Event waiter must have basic waiting skills; be able to follow instructions; lay tables; have the ability to carry 3 plates and clear them in a professional manner; carry and serve trays of drinks and canap&eacute;s; open wine and understand basic wine service.',attribute:'Photo: Robert Rosen'},
	{image:'images/employment-pages/requirements/senior_bar.jpg',text:'Senior bar<br>A Senior Bar must have the ability to coordinate service in event bars as well as supervise Junior Bar Staff at large events; work out logistics for bar service at functions and events; have a good knowledge of a basic range of drinks, including wine, beer and spirits.',attribute:'Photo: Robert Rosen'},
	{image:'images/employment-pages/requirements/cocktail_bar.jpg',text:'Cocktail bar<br>A Cocktail bar person is very experienced in all bar work; can mix various drinks and cocktails; work unsupervised; and possesses a wide knowledge of drinks and cocktails.',attribute:'Photo: David Grant Special Events'},
	{image:'images/employment-pages/requirements/barista.jpg',text:'Barista<br>It\'s never slow in an espresso bar, so a Barista must have the ability to work in a fast paced environment; operate most espresso machines on the market; and prepare a wide range of espresso coffee beverages.',attribute:''},
	{image:'images/employment-pages/requirements/cook_and_serve.jpg',text:'Cook &amp; serve<br>A Cook &amp; serve is the next best thing to a chef. They are an experienced waiter with food preparation skill who can work unsupervised in private homes; are adept at plating prepared canap&eacute;s &amp; food; serving food &amp; beverages; cleaning the kitchen, and handwashing special glassware and crockery if required.',attribute:'Photo: Robert Rosen'},
	{image:'images/employment-pages/requirements/kitchen_hand.jpg',text:'Kitchen hand<br>A Kitchen hand has the ability to work and operate dishwashers as well as possessing a good working knowledge of procedures in commercial kitchens. They are competent to set up an effective back area; stack hire equipment; work quickly and professionally; and leave the area in a neat and orderly fashion.',attribute:''},
	{image:'images/employment-pages/requirements/tea_person.jpg',text:'Tea person<br>A tea person has the ability to replenish condiments and is responsible for the cleaning of the kitchenette area.',attribute:''},
	{image:'images/employment-pages/requirements/cloakroom_staff.jpg',text:'Cloakroom staff<br>Cloakroom staff must be able to work in a fast paced environment; set up a cloakroom to meet the requirements of clients; as well as being able to take and account for coats and bags in a professional manner.',attribute:''}];

	$('#staff_types #images:visible').fadeOut('fast');
	$('#staff_types #imagebox:visible').fadeOut('fast');
	$('#staff_types #imagebox img').attr('src', content[staff].image);
	$('#staff_types #imagebox p:first').html(content[staff].text);
	$('#staff_types #imagebox p.attribute').html(content[staff].attribute);
	$('#staff_types #imagebox').fadeIn('fast');
	return false;
}

// Function to show the event image, and content.
// Pass the function the item number.
function ShowEvent(item) {
	EventsGalleryCurrentItem = item;
	// Add one to item because the nth-child command starts from 1, not zero
	item++;
	var selector = '#events_gallery #images ul li:nth-child('+item+')';
	var title = $(selector).children('p').html();
	var attribute = $(selector).attr('attribute');
	var image = 'images/hospitality-for-you/events-gallery/' + $(selector).attr('image');
	
	$('#events_gallery #images:visible').fadeOut('fast');
	$('#events_gallery #imagebox:visible').fadeOut('fast');
	$('#events_gallery #imagebox img').attr('src', image);
	$('#events_gallery #imagebox p:first').html(title);
	$('#events_gallery #imagebox p.attribute').html(attribute);
	$('#events_gallery #imagebox').fadeIn('fast');
	return false;
}

// Contact selector

var contacts = [{name:"Sydney office",ph:"02 9281 2433",email:"info@stedmans.com.au",img:"stedmans.jpg"},
{name:"Jarrod Glasson",ph:"02 9281 2433",email:"info@stedmans.com.au",img:"jarrod.jpg"},
{name:"Kelly Chan",ph:"02 9281 2433",email:"casting@qtalent.com.au",img:"kelly.jpg"},
{name:"Kelly Chan",ph:"02 9281 2433",email:"kelly@stedmans.com.au",img:"kelly.jpg"},
{name:"Helmut Schorer",ph:"02 9281 2433",email:"helmut@stedmans.com.au",img:"contact_helmut.jpg"},
{name:"Kim Knudsen",ph:"02 9281 2433",email:"kim@stedmans.com.au",img:"contact_kim.jpg"},
{name:"Kelly Chan",ph:"02 9281 2433",email:"kelly@stedmans.com.au",img:"kelly.jpg"},
{name:"Megawati Cokro",ph:"02 9281 2433",email:"mega@stedmans.com.au",img:"contact_megawati.jpg"},
{name:"Megawati Cokro",ph:"02 9281 2433",email:"mega@stedmans.com.au",img:"contact_megawati.jpg"}];

function changeContact(id) {
	var data = contacts[id];
	var directory = "images/contacts/";	
	var contactName = document.getElementById("name");
	contactName.innerHTML = data.name; 	
	var contactPh = document.getElementById("phone");
	contactPh.innerHTML = data.ph; 
	var contactEmail = document.getElementById("email");
	contactEmail.innerHTML = "<a href=\"mailto:" + data.email + "\">" + data.email + "</a>"; 	
	var contactPhoto = document.getElementById("photo");	
	contactPhoto.style.backgroundImage = "url(" + directory + data.img + ")";
}
