(function($) {
    $(document).ready( function() {

	
	
	$(".faqs-link").colorbox({width:"700px", inline:true, href:"#faqs"});
	$(".privacy-link").colorbox({width:"700px", inline:true, href:"#privacy"});
	$(".sitemap-link").colorbox({width:"700px", inline:true, href:"#sitemap"});
	
	
	if ($.client.browser =="Firefox" && $.client.os=="Mac" )
	applycssMacFirefox();
	
	var query = getParameterByName("msg");
	
	checkarrow();
	
	if(query=="CourseSuccess")
	jQuery('#messageBox').text("Thank You For Your Submission!").fadeIn().delay(2000).fadeOut('slow');
	
	if(query=="WorkshopSuccess")
	jQuery('#messageBox').text("Thank You For Your Submission!").fadeIn().delay(2000).fadeOut('slow');
	
	if(query=="EnquireSuccess")
	jQuery('#messageBox').text("Thank You For Your Enquire!").fadeIn().delay(2000).fadeOut('slow');
	
	if(query=="BookSuccess")
	jQuery('#messageBox').text("Thank You For Your Booking!").fadeIn().delay(2000).fadeOut('slow');
	loadpredesc();
} );
 

$('a[rel=external]').click(function(){
	$(this).attr('target','_blank');
});	




function getcurrentfolder()
{ 
	return window.location.href.split(window.location.hostname)[1].split("/")[window.location.href.split(window.location.hostname)[1].split("/").length-1];
}

window.alert = function(message) { 

  jQuery('#messageBox').text(message).fadeIn().delay(2000).fadeOut('slow');


}

function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}




$('#course-workshop-links li').click(function(event){
	event.preventDefault();
	if($(this).attr('class')!="linkon")
	{
		$(this).parent().children("li").removeClass("linkon");
		$(this).addClass("linkon");
		
		Cufon.replace("#course-workshop-links li",{
			fontFamily:'AvantGarde LT ExtraLight',
			hover: {
				color: '#85307b'
			}
		});
		
		$(".chunk").hide();
		
		if($(this).attr('id') == "chunk-link1")
		
		{$("#chunk1").fadeIn();
		$('.event-name').text("course");
		Cufon.set('fontFamily', 'AvantGarde LT ExtraLight');
	Cufon.replace("h3",{
		
	});
		}
		
		else
		
		{$("#chunk2").fadeIn();
		$('.event-name').text("workshop");
		Cufon.set('fontFamily', 'AvantGarde LT ExtraLight');
	Cufon.replace("h3",{
		
	});
		}
	}
});	


 var clicked1=false;
 
 $('#FullName').click(function() {
  
  if(clicked1 == false)
  {$('#FullName').val(''); clicked1=true;}
});

var clicked2=false;
 
 $('#WorkPhone').click(function() {
  
  if(clicked2 == false)
  {$('#WorkPhone').val(''); clicked2=true;}
});



var clicked3=false;
 
 $('#EmailAddressEnquire').click(function() {
  
  if(clicked3 == false)
  {$('#EmailAddressEnquire').val(''); clicked3=true;}
}); 




var clicked4=false;
 
 $('#CAT_Custom_220293').click(function() {
  
  if(clicked4 == false)
  {$('#CAT_Custom_220293').val(''); clicked4=true;}
});



var counttestimonial = 0;
var currenttestimonial = 1;

$('#testimonial-wrap .testimonial-item').each(function(i) {
		counttestimonial++;
});
$('#testimonial-inner-wrap').css({"width":counttestimonial*220+"px"});
var bannerselectorismoving = false;

$('#left-arrow').click(function(event) {
	event.preventDefault();
	if(currenttestimonial>1)
	
	{
		bannerselectorismoving = true;
		currenttestimonial--;
	$('#testimonial-inner-wrap').animate({
		left: '+=220'
	  }, 500, function() {
		bannerselectorismoving = false;
		checkarrow();
	});
	
	
	}
});



$('#right-arrow').click(function(event) {
	event.preventDefault();
	if(currenttestimonial<counttestimonial)
	
	{
		bannerselectorismoving = true;
		currenttestimonial++;
	$('#testimonial-inner-wrap').animate({
		left: '-=220'
	  }, 500, function() {
		bannerselectorismoving = false;
		checkarrow();
	});
	
	}
});

function checkarrow()
{
	$('#left-arrow').fadeIn(300);
	$('#right-arrow').fadeIn(300);
	
	if(currenttestimonial<=1)
	$('#left-arrow').fadeOut(300);
	
	if(currenttestimonial>=counttestimonial)
	$('#right-arrow').fadeOut(300);
}

function loadpredesc()
{
	$('.book-wrap').each(function(i) {
		$(this).children('.book-grey').html($(this).children('.book-grey').children('p:first-child').html());
		
	});
}

$('.testimonial-read-more').click(function(event) {
	event.preventDefault();
	
	$('#testimonial-description-wrap').html($(this).next().html());
	
	$(this).colorbox({width:"700px", inline:true, href:"#testimonial-description-wrap",onClosed:function(){ $('#testimonial-description-wrap').html(""); }});
});


$('.course-detail-link').click(function(event){
	event.preventDefault();
	$('#course-detail').html($(this).next().html());
	$(this).colorbox({width:"700px", inline:true, href:"#course-detail",onClosed:function(){ $('#course-detail').html(""); }});
});


$('.course-form-link').click(function(event){
	event.preventDefault();
	var coursename = $(this).parent().children(".course-fake-name").text();
	$("#course-form").children("h3").text(coursename);
	$("#CAT_Custom_220763_77212").attr("value",coursename);
	$(this).colorbox({width:"700px", inline:true, href:"#course-form"});
});

$('.workshop-detail-link').click(function(event){
	event.preventDefault();
	$('#workshop-detail').html($(this).next().html());
	$(this).colorbox({width:"700px", inline:true, href:"#workshop-detail",onClosed:function(){ $('#workshop-detail').html(""); }});
});


$('.workshop-form-link').click(function(event){
	event.preventDefault();
	var workshopname = $(this).parent().children(".workshop-fake-name").text();
	$("#workshop-form").children("h3").text(workshopname);
	$("#CAT_Custom_220768_77213").attr("value",workshopname);
	$(this).colorbox({width:"700px", inline:true, href:"#workshop-form"});
});


$('.book-detail-link').click(function(event){
	event.preventDefault();
	/*
	var bookname = $(this).parent().children(".book-name").text();
	$('#book-detail').append($(this).next().html());
	$("#book-detail").children("h3").text(bookname);
	Cufon.set('fontFamily', 'AvantGarde LT ExtraLight');
	Cufon.replace("h3",{
		
	});
	$(this).colorbox({width:"700px", inline:true, href:"#book-detail",onClosed:function(){ $('#book-detail').html("<h3></h3>"); }});
	*/
	
	window.location = $(this).next().children("a").attr("href");
});


$('.book-form-link').click(function(event){
	event.preventDefault();
	var bookname = $(this).parent().children(".book-name").text();
	$("#book-form").children("h3").text(bookname);
	$("#CAT_Custom_225635_78928").attr("value",bookname);
	$(this).colorbox({width:"700px", inline:true, href:"#book-form"});
});

$("#logo").click(function(event){
	event.preventDefault();
	window.location = '/';
});

} ) ( jQuery );

