$(document).ready(function()
{
	//$('#enquireForm').forms();
	
	
	var validator = $("#enquireForm").validate({
		rules: {
			firstnameContact: "required",
			lastnameContact: "required",
			emailContact: {
				required: true,
				email: true
			},
			securitycodeContact: "required",
			countryContact: "required",
			typeEvent: "required",
			dateEvent: "required",
			telephoneContact: "required",
			cityContact: "required"
		},
		messages: {
			firstnameContact: "Enter your firstname",
			lastnameContact: "Enter your lastname",
			emailContact: {
				required: "Please enter a valid email address",
				minlength: "Please enter a valid email address"
			},
			securitycodeContact: "Please enter the security code",
			countryContact: "Please select a country",
			typeEvent: "Please select a type of event",
			dateEvent: "Please select a date for an event",
			telephoneContact: "Please enter your telephone number",
			cityContact: "Please select a city"
		}
		
		
		
	});
	
	var validator1 = $("#enrolForm").validate({
		rules: {
			firstnameEnrol: "required",
			lastnameEnrol: "required",
			emailEnrol: {
				required: true,
				email: true
			},
			securitycodeEnrol: "required",
			countryEnrol: "required",
			course: "required",
			datePref: "required",
			cityEnrol: "required"
		},
		messages: {
			firstnameEnrol: "Enter your firstname",
			lastnameEnrol: "Enter your lastname",
			emailEnrol: {
				required: "Please enter a valid email address",
				minlength: "Please enter a valid email address"
			},
			securitycodeEnrol: "Please enter the security code",
			countryEnrol: "Please select a country",
			course: "Please select a type of course",
			datePref: "Please select a date of preference",
			cityEnrol: "Please select a city"
		}
		
		
		
	});
	
	
	var validator = $("#enquireFormcons").validate({
		rules: {
			firstnameContact: "required",
			lastnameContact: "required",
			emailContact: {
				required: true,
				email: true
			},
			telephoneContact: "required",
			securitycodeContact: "required",
			enquiry: "required"
		},
		messages: {
			firstnameContact: "Enter your firstname",
			lastnameContact: "Enter your lastname",
			emailContact: {
				required: "Please enter a valid email address",
				minlength: "Please enter a valid email address"
			},
			telephoneContact: "Please enter your telephone number",
			securitycodeContact: "Please enter the security code",
			enquiry: "Please specify your enquiry"
		}
		
		
		
	});
	
	//multimenu('#menu ul li');
	
	if($('.training').length!=0)
	{
		$('.training li').find('a').css({'padding-left':30, 'padding-right':31});
	}
	
	if($('.bridal').length!=0)
	{
		$('.bridal li').find('a').css({'padding-left':57, 'padding-right':58});
	}
	
	if($.browser.msie)
	{
		if($.browser.version == 6)
		{
			if($('.bridal').length!=0)
			{
				$('.bridal li:last').find('a').css({'padding-left':60, 'padding-right':60});
			}
			else if($('.training').length!=0)
			{
				$('.training li:last').find('a').css({'padding-left':36, 'padding-right':35});
			}
		}
		else if($.browser.version == 7)
		{
			if($('.bridal').length!=0)
			{
				$('.bridal li:last').find('a').css({'padding-left':60, 'padding-right':60});
			}
			else if($('.training').length!=0)
			{
				$('.training li:last').find('a').css({'padding-left':36, 'padding-right':35});
			}
		}
		else if($.browser.version == 8)
		{
			if($('.bridal').length!=0)
			{
				$('.bridal li:last').find('a').css({'padding-left':57, 'padding-right':57});
			}
			else if($('.training').length!=0)
			{
				$('.training li:last').find('a').css({'padding-left':32, 'padding-right':32});
			}
		}
		else if($.browser.version == 9)
		{
			if($('.bridal').length!=0)
			{
				$('.bridal li:last').find('a').css({'padding-left':54, 'padding-right':54});
			}
			else if($('.training').length!=0)
			{
				$('.training li:last').find('a').css({'padding-left':27, 'padding-right':27});
			}
		}
	}
	else
	{
		if($('.training').length!=0)
		{
			$('.training li:last').find('a').css({'padding-left':31, 'padding-right':32});
		}
	}
	
	
	setTimeout(function(){slidingHoverBg('#menu');},1);
	
	
	var glowImage 	= '<img src="images/subSiteLinkBaseHoverGlow.gif" width="146px" height="40px" />';
	var txt 		= $('#header blockquote a').html();
	var newTxt		= '<small>'+txt+'</small>';
			
	$('#header blockquote a').append(glowImage);
	$('#header blockquote a').append(newTxt);
	
	$('#header blockquote a').hover(
		function()
		{
			$(this).find('img').fadeIn(500);
			$(this).find('small').show();
		},
		function()
		{
			$(this).find('img').fadeOut(500);
			$(this).find('small').hide();
		});
	
	
	$('a[name=modal]').click(function(e) 
	{
		e.preventDefault();
		
		if($('.window').is(':visible'))
		{
			$('.window').animate({width:0, height:0, left: winW/2-0, opacity:0},600).find('h2, blockquote, div').hide();
		}
		
		var id = '#'+$(this).attr('href');
		 
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	 
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		$(document).scrollTop(200);
		
		$('#mask').fadeIn(500);   
		$('#mask').fadeTo("fast",0.8); 
	 
		var winH = $(window).height();
		var winW = $(window).width();
			
		$(id).find('h2, blockquote, div').hide();
		$(id).css({opacity:0, width:1, height:1, left: winW/2-$(id).width()/2}).show();
		$(id).animate({width:960, height:1200, left: winW/2-480, opacity:1},600).find('h2, blockquote, div').show();  
		//, rotate:'+=720deg'
  	 });  
     
    $('.window .close').click(function (e) 
 	{
        e.preventDefault();
		var winW = $(window).width();
		$('#mask').hide();
		$('.window').animate({width:0, height:0, left: winW/2-0, opacity:0},600).find('h2, blockquote, div').hide();
    });    
     
    $('#mask').click(function () 
 	{
		var winW = $(window).width();
		$(this).hide();
		$('.window').animate({width:0, height:0, left: winW/2-0, opacity:0},600).find('h2, blockquote, div').hide();
    });
 
 
  

	
	if($('.thumbvr').length!=0)
	{
		$('.thumbvr').thumbvr({
			duration:1200,
			easing:'easeOutBack'
		})
		
		$('.thumbvr a').fancybox({
			titleFormat:function(title, currentArray, currentIndex, currentOpts) {
				return '<div id="fancybox-title-over"><span class="gray">PHOTO</span> ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</div>';
			},
			overlayColor:'#000'
		})
	}
	
	if($('ul.services li').length!=0)
	{
		var glowTimer;
		$('ul.services li').hover(
			function()
			{
				var thisOne = $(this);
				$(this).addClass('glow');
				glowTimer = setTimeout(function(){thisOne.addClass('glowOut');},1000)
				$(this).css('border-color','#fffd34');
				$(this).find('span').css('border-color','#fffd34');
				$(this).find('a').addClass('hover');
				//$(this).glow('magenta', 500, 100);
			},
			function()
			{
				clearTimeout(glowTimer);
				$(this).removeClass('glow glowOut');
				$(this).css('border-color','#ffffff');
				$(this).find('span').css('border-color','#ffffff');
				$(this).find('a').removeClass('hover');
			});
	}
	
	
	if($('#hub').length!=0)
	{
		$('#hub div blockquote img').animate({opacity: 0},0);
		$('#hub div').hover(
			function()
			{
				$(this).find('blockquote img').css('border-color','#fffd34');
				$(this).find('a').css('color','#fffd34');
				switch($(this).attr('id'))
				{
					case 'first':
						$(this).find('blockquote img').animate({top: 0, opacity: 1},500);
					break;
					
					case 'second':
						$(this).find('blockquote img').animate({right: 0, opacity: 1},500);
					break;
					
					case 'third':
						$(this).find('blockquote img').animate({left: 0, opacity: 1},500);
					break;
					
					case 'fourth':
						$(this).find('blockquote img').animate({right: 0, bottom: 0, opacity: 1},500);
					break;
					
					default:
						//nothing
					break;
				}
				
			},
			function()
			{
				$(this).find('blockquote img').css('border-color','#fff');
				$(this).find('a').css('color','#fff');
			});
	}
	
	
	
	if($('#newsContentHolder').length!=0)
	{
		$('#newsContentHolder dl').hover(
			function()
			{
				$(this).find('dt a img').css('border-color','#fffd2b');
				$(this).find('dd a').css('color','#fffd2b');
			},
			function()
			{
				$(this).find('dt a img').css('border-color','#fff');
				$(this).find('dd a').css('color','#fff');
			});
	}
	
	
	
	
	// --------------------- Smooth Browser Scrolling Starts
	function filterPath(string) {
		return string
		.replace(/^\//,'')
		.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		.replace(/\/$/,'');
	}

	var locationPath = filterPath(location.pathname);
	var scrollElem = scrollableElement('html', 'body');

	// Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
	$('a[href*=#]').each(function() {

		// Ensure it's a same-page link
		var thisPath = filterPath(this.pathname) || locationPath;
		if (  locationPath == thisPath
			&& (location.hostname == this.hostname || !this.hostname)
			&& this.hash.replace(/#/,'') ) {

				// Ensure target exists
				var $target = $(this.hash), target = this.hash;
				if (target) {

					// Find location of target
					var targetOffset = $target.offset().top;
					$(this).click(function(event) {

						// Prevent jump-down
						event.preventDefault();

						// Animate to target
						$(scrollElem).animate({scrollTop: targetOffset}, 400, function() {

							// Set hash in URL after animation successful
							location.hash = target;

						});
					});
				}
		}

	});

	// Use the first element that is "scrollable"  (cross-browser fix?)
	function scrollableElement(els) {
		for (var i = 0, argLength = arguments.length; i <argLength; i++) {
			var el = arguments[i],
			$scrollElement = $(el);
			if ($scrollElement.scrollTop()> 0) {
				return el;
			} else {
				$scrollElement.scrollTop(1);
				var isScrollable = $scrollElement.scrollTop()> 0;
				$scrollElement.scrollTop(0);
				if (isScrollable) {
					return el;
				}
			}
		}
		return [];
	}
	
	// --------------------- Smooth Browser Scrolling Ends
			
		
});


eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('h.i[\'V\']=h.i[\'y\'];h.M(h.i,{B:\'C\',y:9(x,t,b,c,d){6 h.i[h.i.B](x,t,b,c,d)},14:9(x,t,b,c,d){6 c*(t/=d)*t+b},C:9(x,t,b,c,d){6-c*(t/=d)*(t-2)+b},13:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t+b;6-c/2*((--t)*(t-2)-1)+b},12:9(x,t,b,c,d){6 c*(t/=d)*t*t+b},Q:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t+1)+b},O:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t+b;6 c/2*((t-=2)*t*t+2)+b},P:9(x,t,b,c,d){6 c*(t/=d)*t*t*t+b},L:9(x,t,b,c,d){6-c*((t=t/d-1)*t*t*t-1)+b},S:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t+b;6-c/2*((t-=2)*t*t*t-2)+b},F:9(x,t,b,c,d){6 c*(t/=d)*t*t*t*t+b},J:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t*t*t+1)+b},K:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t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},W:9(x,t,b,c,d,s){e(s==w)s=1.l;6 c*(t/=d)*t*((s+1)*t-s)+b},Y:9(x,t,b,c,d,s){e(s==w)s=1.l;6 c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},Z:9(x,t,b,c,d,s){e(s==w)s=1.l;e((t/=d/2)<1)6 c/2*(t*t*(((s*=(1.D))+1)*t-s))+b;6 c/2*((t-=2)*t*(((s*=(1.D))+1)*t+s)+2)+b},z:9(x,t,b,c,d){6 c-h.i.r(x,d-t,0,c,d)+b},r:9(x,t,b,c,d){e((t/=d)<(1/2.k)){6 c*(7.o*t*t)+b}m e(t<(2/2.k)){6 c*(7.o*(t-=(1.5/2.k))*t+.k)+b}m e(t<(2.5/2.k)){6 c*(7.o*(t-=(2.17/2.k))*t+.18)+b}m{6 c*(7.o*(t-=(2.19/2.k))*t+.1a)+b}},1b:9(x,t,b,c,d){e(t<d/2)6 h.i.z(x,t*2,0,c,d)*.5+b;6 h.i.r(x,t*2-d,0,c,d)*.5+c*.5+b}});',62,74,'||||||return||Math|function|||||if|var|PI|jQuery|easing|pow|75|70158|else|sin|5625||sqrt|easeOutBounce|||abs|asin|undefined||swing|easeInBounce|cos|def|easeOutQuad|525|easeInCirc|easeInQuint|easeOutCirc|easeInOutCirc|easeInElastic|easeOutQuint|easeInOutQuint|easeOutQuart|extend|easeInSine|easeInOutCubic|easeInQuart|easeOutCubic|easeOutSine|easeInOutQuart|easeOutElastic|easeInOutElastic|jswing|easeInBack|easeInOutSine|easeOutBack|easeInOutBack||easeInExpo|easeInCubic|easeInOutQuad|easeInQuad|easeOutExpo|easeInOutExpo|25|9375|625|984375|easeInOutBounce'.split('|'),0,{}))



function slidingHoverBg(menuHolder)
{
	var currDiv 		= $('#menu ul li.current');
	var currPosition	= currDiv.position();
	var currWidth 		= currDiv.width();

	var hoverBlock	= $(menuHolder).find('span');
	var hyperlink	= $(menuHolder).find('ul li a');
	var duration	= 400;
	
	/*var initOffset	= hyperlink.parent().position();
	var initLeftPos = initOffset.left;
	var initImgPosition	= initLeftPos-hyperlink.width();*/
	
	if($(menuHolder).find('ul li').is(':first'))
	{
		hoverBlock.css({left: currPosition.left, width: $(menuHolder).find('ul li.current').width()-10});
	}
	else
	{
		hoverBlock.css({left: currPosition.left, width: $(menuHolder).find('ul li.current').width()});
	}
	
	
	hyperlink.hover(
		function()
		{
			//if(!$(this).parent().parent().parent().hasClass('hasSub'))
			if($(this).parent().parent().attr('id')=='nav')
			{
				var position = $(this).parent().position();
				var newpos = position.left;
				hoverBlock.stop().animate({left: newpos, width: $(this).parent().width()},duration);
				
			}
			else
			{
				var position = $(this).parent().parent().parent().position();
				var newpos = position.left;
				hoverBlock.stop().animate({left: newpos, width: $(this).parent().parent().parent().width()},duration);
			}
		},
		function()
		{
			hoverBlock.stop().animate({left: currPosition.left, width: currWidth},duration);
		}
	);
	
}



/* MULTI LEVEL MENU */
function multimenu(container) 
{
	$(container).hover(
	  function (e) 
	  {
		if($(this).hasClass('hasSub'))
		{
			//$(this).children('a').addClass('selected');
			//alert($(this).width());
			$(this).children('ul').width($(this).width());
			$(this).find('li').width($(this).width());
			$(this).find('li a').width($(this).width());
			
			$(this).children('ul').show();
			$(this).children('ul').fadeTo("slow",0.9);
					
		}
	  }, 
	  function (e) 
	  {
		  	//$(this).children('a').removeClass('selected');
			$(this).children('ul').hide();
	  }
	);
	
}


$.fn.forms = function()
{
	
	var contactform 	= $(this);
	var emailReg	 	= /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	contactform.find('a[name=submit]').click(function()
	{
		var isNotEmpty		= false;
		var isValidEmail 	= false;
		var fieldCounter	= 0;
		
		//alert(contactform.find('input.validate').length);
		
		contactform.find('input.validate').each(function()
		{
			if($(this).val() == '')
			{
				$(this).siblings('span.empty').slideDown();
				fieldCounter++;
				//alert('++ :'+fieldCounter);
			}
			else if(!emailReg.test(contactform.find('input[name=email]').val()))
			{
				$(this).siblings('span.error').slideDown();
				isValidEmail = true;
			}
			else
			{
				fieldCounter--;
				//alert('-- :'+fieldCounter);
			}
		});
		
		if(isValidEmail == false)
		{
			contactform.find('input[name=email]').siblings('span.error').slideUp();
		}
		
		alert(fieldCounter);
		
		if(fieldCounter == 0 && isValidEmail == false)
		{
			contactform.find('span.message').slideDown();
			$(document).scrollTop();
		}
		
	});
	
	contactform.find('input').blur(function()
	{
		if($(this).val()!='')
		{
			$(this).siblings('span.empty').slideUp();
		}
	});
	
};

