$(document).ready(function(){
	//replace all fck inserted movies with swfobject
	//needed for accessibility options	
	//apply form validation
	if(jQuery.fn.validate){			
		if($('#FormSignup').length > 0 ){ // check if element is on page
			$("#FormSignup").validate({
				highlight: function(element, errorClass) {
					$(element).animate({
						opacity: 0.9
					}, 400, function () {
						$(element).css('color','#000000'); //red background for invalid data
						$(element).css('background-color','#FBE3E4'); //red background for invalid data
						$(element).css('border-color','#FBC2C4'); //red border for invalid data
					});
				},
				unhighlight: function(element, errorClass) {
					$(element).animate({
						opacity: 1.0
					}, 400, function () {
						$(element).css('color','#000000'); //red background for invalid data
						$(element).css('background-color','#E6EFC2'); //green background for valid data
						$(element).css('border-color','#C6D880'); //green border for valid data
					});
				},
				rules: {
					"data[FormSignup][firstname]": {  
						required: true           
					},
					"data[FormSignup][lastname]": {  
						required: true           
					},
					"data[FormSignup][email]": {
						required: true,
						email: true
					}
				},
				messages: {
					"data[FormSignup][firstname]": "Please enter your firstname.",
					"data[FormSignup][lastname]": "Please enter your last name.",
					"data[FormSignup][email]": "Please enter your email address."
				}
			});
		}
		if($('#FormContact').length > 0 ){ // check if element is on page
			$("#FormContact").validate({
				highlight: function(element, errorClass) {
					$(element).animate({
						opacity: 0.9
					}, 400, function () {
						$(element).css('color','#000000'); //red background for invalid data
						$(element).css('background-color','#FBE3E4'); //red background for invalid data
						$(element).css('border-color','#FBC2C4'); //red border for invalid data
					});
				},
				unhighlight: function(element, errorClass) {
					$(element).animate({
						opacity: 1.0
					}, 400, function () {
						$(element).css('color','#000000'); //red background for invalid data
						$(element).css('background-color','#E6EFC2'); //green background for valid data
						$(element).css('border-color','#C6D880'); //green border for valid data
					});
				},
				rules: {
					"data[FormContact][firstname]": {  
						required: true           
					},
					"data[FormContact][surname]": {  
						required: true           
					},
					"data[FormContact][company]": {  
						required: true           
					},
					"data[FormContact][telephone]": {  
						required: true           
					},
					"data[FormContact][email]": {
						required: true,
						email: true
					}
				},
				messages: {
					"data[FormContact][firstname]": "Please enter your firstname.",
					"data[FormContact][surname]": "Please enter your surname.",
					"data[FormContact][company]": "Please enter your company name.",
					"data[FormContact][telephone]": "Please enter your telephone number.",
					"data[FormContact][email]": "Please enter your email address."
				}
			});
		}
		if($('#FormCallmeback').length > 0 ){ // check if element is on page
			$("#FormCallmeback").validate({
				highlight: function(element, errorClass) {
					$(element).animate({
						opacity: 0.9
					}, 400, function () {
						$(element).css('color','#000000'); //red background for invalid data
						$(element).css('background-color','#FBE3E4'); //red background for invalid data
						$(element).css('border-color','#FBC2C4'); //red border for invalid data
					});
				},
				unhighlight: function(element, errorClass) {
					$(element).animate({
						opacity: 1.0
					}, 400, function () {
						$(element).css('color','#000000'); //red background for invalid data
						$(element).css('background-color','#E6EFC2'); //green background for valid data
						$(element).css('border-color','#C6D880'); //green border for valid data
					});
				},
				rules: {
					"data[FormCallmeback][firstname]": {  
						required: true           
					},
					"data[FormCallmeback][surname]": {  
						required: true           
					},
					"data[FormCallmeback][telephone]": {  
						required: true           
					}
				},
				messages: {
					"data[FormCallmeback][firstname]": "Please enter your firstname.",
					"data[FormCallmeback][surname]": "Please enter your surname.",
					"data[FormCallmeback][telephone]": "Please enter your telephone number."
				}
			});
		}
	}
	
	/* EMBED MEDIA */
	if(jQuery.fn.media){
		//set default player location
		$.fn.media.defaults.flvPlayer = '/css/site/flash/mediaplayer.swf';
		//run media plugin on all a links with media class
		$('a.media').media();
	}
	
	
	if(jQuery.fn.showhide){
		//apply show hide plugin for use in gallery
		if($('a.showhide').length > 0 ){
			$('a.showhide').showhide({
				animate:true,
				event:'click',
				target:'#large_img',
				show_closer:false
			});
		}
	}
	
	
	if(jQuery.fn.inputfocus){
		if($('#header-outer-wrapper form div.input').length > 0 ){ // check if element is on page
			//apply form field effect
			$('#header-outer-wrapper form div.input').inputfocus({
				bgColourFocus:'#EFFCFF',
				bgColour:'#FFFFFF',			
				animate:true
			});
		}
	}
	
	if(jQuery.fn.cycle){
		if($('#quotes').length > 0 ){ // check if element is on page
			$('#quotes').css('height','160px');//set height of quotes box
			$('#quotes').cycle({fx:'fade',timeout:'7000'});
		}
		if($('#questions').length > 0 ){ // check if element is on page
			$('#questions').css('height','120px');//set height of quotes box
			$('#questions').cycle('fade');
		}
		if($('div.banner-item div.col-1').length > 0 ){ // check if element is on page
			$('div.banner-item div.col-1').cycle('fade');
		}		
	}
	
	jQuery.each(jQuery.browser, function(i) {
		//safari only css amend using jquery
	  if($.browser.safari){
		$('#nav-wrapper ul li a').css({'font-size':'1.1em', 'padding-right':'60px'});
		$('#nav-wrapper ul li a.long').css({'padding-right':'5px'});
	  }
	});
	
	// say the container is expandable 
	$('div.banner-item').bind('toggleContent', function(e, url, wrapper, img) { 
		//$(this).find('div.col-1').css('border','1px solid #FF0000');
		
		if(jQuery.fn.media){
			
			if(jQuery.fn.cycle){
				$(this).children(wrapper).cycle('pause');
			}
			//remove any existing divs
			if($(this).children(wrapper).children('div.flash-movie').length > 0){
				$(this).children(wrapper).children('div.flash-movie').remove();
				$(this).children(wrapper).children('div.closer').remove();
			}
			$(this).children(wrapper).append('<div class="flash-movie"><a class="{width:584, height:330}" href="'+url+'"></a></div>');
			$(this).children(wrapper).children('div.banner-img').css('height', '330px');
			$(this).children(wrapper).css('height', '330px');
			$.fn.media.defaults.flvPlayer = '/css/site/flash/player.swf';
			$.fn.media.defaults.bgColor = '#000000';
			//set the default image as a flash var.
			//set the flash stretching to full screen as a flash var
			$.fn.media.defaults.flashvars = {'image':'/img/site/content/movie-wallpaper.jpg',
											 'stretching':'exactfit'
											 };
			$.fn.media.defaults.params = { wmode: "transparent"};
			$(this).children(wrapper).children('div.flash-movie').children('a').media();
			$(this).children(wrapper).append('<div class="closer"><p>close [X]</p></div>');
			$(this).children(wrapper).children('div.closer').click(function(){ 
																			$(this).siblings('.flash-movie').remove();
																			$(this).remove(); 
																			if($('#home').length < 1 ){ // resize banner for none home pages
																				$('#banner-wrapper div.col-1').css('height', '221px');
																				$('#banner-wrapper div.col-1 div.banner-img').css('height', '221px');
																			}
																	});
		}
			
	}); 
	 
	// bind the expansion/contraction to the toggleElement 
	$('a.show-vid').click(function() { 
		var href = $(this).attr('href');
		$(this).parent().trigger('toggleContent', [ href, '.col-1' ]);
		return false;
	}); 

	
});