// news ticker scrollable
$(document).ready(function() {			
var root = $("#news_ticker").scrollable({circular: true}).autoscroll({ autoplay: true, interval: 7000 });	
});		

// partners scrollable
$(document).ready(function() {	
	// only scroll if there is more than 7
	if($("#partners .items img").size() > 7)
	{
		var root = $("#partners").scrollable({circular: true}).autoscroll({ autoplay: true, interval: 7000 });
	}
});		

// spotlight scrollable
//$(document).ready(function() {	
//$(function() {

//$(".spotlight_media").tabs("img", {

//	// enable "cross-fading" effect
//	fadeOutSpeed: 400,
//	autoplay: true,

//	// start from the beginning after the last tab
//	rotate: true

// use the slideshow plugin. It accepts its own configuration
//}).slideshow({autoplay:true, interval:12000, clickable:true, fadeOutSpeed:400});

//});		
//});		

// skyrocket scrollable
$(document).ready(function() {			
var root = $("#skyrocket").scrollable({circular: true, steps:1});	
});

// expandable list
	$("#accordion li.pane").addClass("panehide");
$(document).ready(function() {
	//Switch the "Open" and "Close" state per click
	$("#accordion li.expander").toggle(function(){
	$(this).addClass("current");
	}, function () {
	$(this).removeClass("current");
	});

	//Slide up and down on click
	$("#accordion li.expander").click(function(){
	$(this).next("#accordion li.pane").slideToggle("fast");
	});	
});

// Tooltips 
$(document).ready(function() {
	$("td.info p").tooltip({ effect: 'toggle', position: 'bottom right', offset: [-80, -10]});
});

$(document).ready(function() {
	$("div.image_item img[title]").tooltip({offset: [10, 55]});
	$("form.currency_selector button[title]").tooltip({offset: [0, 55], position: 'bottom center', tipClass: 'tooltip currency'});
	$("td.currency img[title]").tooltip({offset: [0, 50], position: 'bottom center', tipClass: 'tooltip currency'});
});


// Course information currency changing
$("a.currency_dollars").click(function () {
  $('p.dollar').removeClass('price_hide');
  $('p.pound').addClass('price_hide');
  $('p.euro').addClass('price_hide');
	return false;
});
$("a.currency_pounds").click(function () {
  $('p.pound').removeClass('price_hide');
  $('p.dollar').addClass('price_hide');
  $('p.euro').addClass('price_hide');
	return false;
});
$("a.currency_euros").click(function () {
  $('p.euro').removeClass('price_hide');
  $('p.dollar').addClass('price_hide');
  $('p.pound').addClass('price_hide');
	return false;
});


// Form Date selector
$(document).ready(function() {
	$(":text#dob").dateinput({format: 'dd/mm/yyyy', selectors: true, yearRange:[-100,1]});
});

// Form Validation

$.metadata.setType("attr", "validate");
$(document).ready(function() {
	$("#myform").validate({
		messages: {
			member_first_name: {required: 'Please enter your first name', email: 'Invalid email address'},
			member_last_name: {required: 'Please enter your last name'},
			email: {required: 'Please enter your email address'},
			email_address: {required: 'Please enter your email address'},
			gender: {required: 'Please select your gender'},
			dob: {required: 'Please enter your Date of Birth'},
			username: {required: 'Please enter your Username'},
			password: {required: 'Please enter your Password'},
			password_original: {required: 'Please enter your current Password'},
			password_verify: {required: 'Please re-enter your new Password'},
			repeat_password: {required: 'Please confirm your Password'},
			new_password: {required: 'Please enter your new Password'},
			member_address_1: {required: 'Please enter the first line of your address'},
			member_address_town_city: {required: 'Please enter your Town / City'},
			member_address_postcode: {required: 'Please enter your Postcode'},
			member_country: {required: 'Please select your Country'},
			member_telephone: {required: 'Please enter your Telephone number'},
			booking_quantity: {required: 'Please enter the number of places'},
			booking_emergency_name: {required: 'Please enter an emergency contact name'},
			booking_emergency_number: {required: 'Please enter an emergency number'}
		}
	});
	$("#contactform").validate({
		messages: {
			first_name: {required: 'Please enter your first name', email: 'Invalid email address'},
			last_name: {required: 'Please enter your last name'},
			email: {required: 'Please enter your email address'},
			address_line_1: {required: 'Please enter the first line of your address'},
			address_postcode: {required: 'Please enter your Postcode'},
			address_country: {required: 'Please select your Country'},
			phone: {required: 'Please enter your Telephone number'},
			message: {required: 'Please enter a message'}
		}
	});
	$("#forgot_username_form").validate({
		messages: {
			email: {required: 'Please enter your email address'}
		}
	});
	$("#forgot_password_form").validate({
		messages: {
			email: {required: 'Please enter your email address'}
		}
	});
    $("#publishForm").validate({
        messages: {
            title: {required: 'Please enter your title for this question'},
            field_id_56: {required: 'Please enter your question'},
            field_id_94: {required: 'Please select your local file to upload'},
            field_id_93: {required: 'Please enter your question'}
        }
    });
    $("#comment_form").validate({
        messages: {
            comment: {required: 'Please enter your response'}
        }
    });

});

// add same as billing address checkbox to delivery address
$('.delivery_address h2').after(
'<div class="form_label">'+
'<label><input type="checkbox" name="use_billing" id="use_billing" /> Same as billing address</label>'+
'</div>');

// functionality to copy address from billing to delivery
function copyFields(e)
{
	// get the id of the input being typed
	var billingInputId = e.target.id;

	// swap prefix 'billing_' for 'delivery_'
	var deliveryInputId = billingInputId.replace('billing_', 'delivery_');

	// update delivery field
	$('#'+deliveryInputId).val(e.target.value);
}

// copy the country
function copyCountry(e)
{
	$('#delivery_address_country').get(0).selectedIndex = e.target.selectedIndex;
}

// bind copyFileds listener when checkbox is checked
$('#use_billing').change(function()
{
	// bind when checked, unbind when unchecked
	if($(this).attr('checked'))
	{
		$('.billing_address input').bind('keyup', copyFields);

		// copy all current data
		$('.billing_address input').each(function(){ $(this).keyup(); });

		// special case for selects
		$('.billing_address select').bind('change', copyCountry);
		$('.billing_address select').change();
	}
	
	// unbind the listeners
	else 
	{
		$('.billing_address input, .billing_address select').unbind();
	}
	
});


//prettyPhoto    
$("a[rel^='prettyPhoto']").prettyPhoto({show_title: false, default_width:640, default_height:480,modal: false, keyboard_shortcuts: true});

// member change package in stage 4 of reg screen
$(document).ready(function() {
	$("#show_options").removeClass('hide');
	$("#hide_options").addClass('hide');
	$(".change_package").click(function () {
		$('#reload').val('TRUE');
		$('#myform').submit();
	});
});

//set a width for the user added image with caption templates (added via ckeditor template)
$(document).ready(function() {
	$('div.caption_image').width($("div.caption_image img").width());
});

// hide  flash messages
$(document).ready( function() {
    $('.noteflash').delay(5000).fadeOut();
});

