$(document).ready(function(){

	//-------------------------------------------------------------------------------------------------
	//--- EMBED MOVIES - flv/flash ---
	
	//replace all fck inserted movies with swfobject
	//needed for accessibility options
	var cnt = 1;
	var next_img = null;
	//find all embed objects
	$('div.flash-movie').each(function()
	{								   
		flash_preview_img = '/content/image/flash-default.jpg';
		var next_img = $(this).siblings('img');
		var flash_preview_img = null;
		var flash_div = $(this).children("a");
		var flash_href = flash_div.attr('href');
		var flash_extension = flash_div.attr('href').substring(flash_div.attr('href').lastIndexOf(".")+1,flash_div.attr('href').length);
		var flash_preview_img = '/content/image/flash-default.jpg';
		
		/**/
		switch(flash_extension){
			case "flv":
			//case "swf":
				if(next_img.length > 0 && next_img.attr('src').length > 0){
					flash_preview_img = next_img.attr('src');
					//remove the image from the page
					next_img.remove();
				}
				flash_href = flash_href + '&image=' + flash_preview_img;
				flash_div.attr('href',flash_href);
			break;
		}
		
		flash_div.media();				
		//if there is an img next to the flash video then use that image as the image preview
		/*
		if(next_img.length > 0 && next_img.attr('src').length > 0){
			flash_preview_img = next_img.attr('src');
			//remove the image from the page
			next_img.remove();
		}
		*/
							
		//set default player location
		//$.fn.media.defaults.flvPlayer = '/css/flash/player.swf';
		//run media plugin on all a links with media class
		//$('#'+flash_div+' a').media();
	});
	
	//think embed is for the swf type files
	//but vern is loading them with somehthing other than swfobject so leave em alone
	$('embed').each(function(){							
			//if they are flash movies
			if($(this).attr('type') == 'application/x-shockwave-flash'){				
				//get the source fo the flash movie
				if($(this).attr('src')){
					
					//get width and height of movie to use for replacement below
					flash_width = $(this).attr('width');
					flash_height = $(this).attr('height');
					//alert(flash_width+":"+flash_height);
					flash_src = $(this).attr('src');
					flash_div = 'flash-'+cnt;
					flash_extension = $(this).attr('src').substring($(this).attr('src').lastIndexOf(".")+1,$(this).attr('src').length);
					flash_preview_img = '/content/image/flash-default.jpg';
					
					//give the element and id
					$(this).attr('id','embed-'+cnt);
					
					switch(flash_extension){	
						default:
						if(jQuery.fn.flash){
							//replace the embed obect with a holding div
							$(this).replaceWith('<div id="'+flash_div+'"></div>');
							//use swfobject to embded the flash movie
							$('#'+flash_div).flash({ 
								// test.swf is the flash document 
								swf: flash_src,
								play: false,
								width : flash_width,
								height : flash_height
								//width : 425,
								//height : 344
							}); 
						}else{
							alert('You need to have the swfobject plugins installed.');
						}
						break;
					}
					
				}
				
			}
		cnt ++;
	});
	//--- EMBED MOVIES - flv/flash ---
	//-------------------------------------------------------------------------------------------------


	/* EMBED MEDIA */
	if(jQuery.fn.media){
		//set default player location
		$.fn.media.defaults.flvPlayer = '/css/flash/mediaplayer.swf';
		//run media plugin on all a links with media class
		$('a.media').media();
	}


	//-------------------------------------------------------------------------------------------------
	//--- USERS ---	
	//user register form
	if ($('#form-register').length > 0){ // check if element is on page
		$("#form-register").livequery(function(){
			$(this).validate({
				rules: {
					txt_title: "required",
					txt_firstname: "required",
					txt_surname: "required",
					txt_address: "required",
					txt_postcode: "required",
					txt_phone: "required",
					txt_reg_email: {
						required: true,
						email: true
					},
					txt_password: "required",
					txt_repeat_password: {
						required: true,
						equalTo: "#txt_password"
					}
				},
				messages: {
					txt_title: "Please enter your title.",
					txt_firstname: "Please enter your first name.",
					txt_surname: "Please enter your surname.",
					txt_address: "Please enter your address.",
					txt_postcode: "Please enter your postcode.",
					txt_phone: "Please enter your telephone number.",
					txt_reg_email: "Please enter a valid email address.",
					txt_password: "Please enter a password.",			
					txt_repeat_password: { 
						required: "Please confirm password.", 
						equalTo: "Please enter the same password as above." 
					} 				
				}
			});	
		});
	}// check if element is on page


	//user edit form
	if ($('#form-useredit').length > 0){ // check if element is on page
		$("#form-useredit").livequery(function(){
			$(this).validate({
				rules: {
					txt_title: "required",
					txt_firstname: "required",
					txt_surname: "required",
					txt_address: "required",
					txt_postcode: "required",
					txt_phone: "required",
					txt_reg_email: {
						required: true,
						email: true
					},
					//txt_password: "required",
					txt_repeat_password: {
						//required: true,
						equalTo: "#txt_password"
					}
				},
				messages: {
					txt_title: "Please enter your title.",
					txt_firstname: "Please enter your first name.",
					txt_surname: "Please enter your surname.",
					txt_address: "Please enter your address.",
					txt_postcode: "Please enter your postcode.",
					txt_phone: "Please enter your telephone number.",
					txt_reg_email: "Please enter a valid email address.",
					//txt_password: "Please enter a password.",			
					txt_repeat_password: { 
						//required: "Please confirm password.", 
						equalTo: "Please enter the same password as above." 
					} 				
				}
			});	
		});
	}// check if element is on page
	
	
	//user reminder form
	if ($('#form-reminder').length > 0){ // check if element is on page
		$("#form-reminder").livequery(function(){
			$(this).validate({
				rules: {
					f_email: {
						required: true,
						email: true
					}
				},
				messages: {
					f_email: "Please enter a valid email address."				
				}
			});	
		});
	}// check if element is on page


/*	//user reminder form
	if ($('#form-login').length > 0){ // check if element is on page
		$("#form-login").livequery(function(){
			$(this).validate({
				rules: {
					f_email: {
						required: true,
						email: true
					},
					f_password: "required"
				},
				messages: {
					f_email: "Please enter a valid email address.",
					f_password: "Please enter your password."
				}
			});	
		});
	}// check if element is on page*/

	//apply form validation
	if(jQuery.fn.validate){			
		if($('#form-login').length > 0 ){ // check if element is on page
			$("#form-login").validate({
				highlight: function(element, errorClass) {
					$(element).animate({
						opacity: 0.9
					}, 300, 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
					}, 300, 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: {
					f_email: "required",
					f_password: "required"
				},
				messages: {
					f_email: "Please enter your email.",
					f_password: "Please enter your password."
				}
			});
		}
	}

	//--- USERS ---
	//-------------------------------------------------------------------------------------------------




}); //jquery load

