$(function() {
	$('div#footer ul.links li').each(function(i) {
		$(this).hover(
			function() {
				$('div#footer img.bg-img:eq('+i+')').css('zIndex',1);
			},
			function() {
				$('div#footer img.bg-img:eq('+i+')').css('zIndex',0);
			});
	});
	$('div#body div.content ul.bio li').each(function(i) {
		var p = i + 1;
		$(this).addClass('bio-'+p);
	});
	// Cycle Team
	if ($('ul#bio').length) {
		if(($.browser.msie && $.browser.version != '6.0') || !$.browser.msie) {
		$('ul#bio').cycle({
			timeout:5000,
			speed:1000,
			pause:1,
			before:function(a) {
				var img = this.className.replace(/bio/,'hand')+'.png';
				$(this).addClass('active');
				if (($.browser.msie && $.browser.version != '6.0') || !$.browser.msie) {
					$('div#body div.content div.backdrop').css({backgroundImage:'url(/layout/images/'+img+')'});
				}
				},
			after:function() {
				$(this).removeClass('active');
				},
			pager:'ul#hands',
			pagerClick:function() {
				$('ul#bio').cycle('pause');
				},
			pagerAnchorBuilder:function(i) {
				var p = i + 1;
				return '<li class="hand-'+p+'"><a href="#"></a></li>';
				}
			});
		}
	}
	$('div#body div.content ul#hands li').each(function(i) {
		var p = i + 1;
		$(this).hover(
			function() {
				$('div.team div.content ul#bio').cycle('pause');
				$('div#body div.content div.backdrop-2').css({backgroundImage:'url(/layout/images/hand-'+p+'.png)'});
			},
			function() {
				$('div.team div.content ul#bio').cycle('resume');
				$('div#body div.content div.backdrop-2').css({backgroundImage:'none'});
			});
	});
	
	
	
	// Gleam
	$('div.home div.content div.brush-stamp div.gleam').flash({
		src: '/layout/swf/NBD-shine.swf',
		width: 200,
		height: 150,
		wmode: 'transparent'
	});
	
	
	
	// Sifr
	/*
		$('div.home div.content div.bottom-box h3').flash(
			{ 
				src: '/layout/swf/egyptian710_bt.swf', 
				flashvars: { 
					css: [
					'* { color: #000000; }'
					].join(' ')
				},
				wmode: 'transparent'
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = '<div>'+this.innerHTML+'</div>';
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass('alt');
				$(this)
					.addClass('flash-replaced')
					.prepend($.fn.flash.transform(htmlOptions));
			}
		);
		$('div.home div.content div.bottom-box ul li').flash(
			{ 
				src: '/layout/swf/egyptian710_bt.swf', 
				flashvars: { 
					css: [
					'* { color: #000000; }'
					].join(' ')
				},
				wmode: 'transparent'
			},
			{ version: 7 },
			function(htmlOptions) {
				//htmlOptions.flashvars.txt = this.innerHTML;
				//this.innerHTML = '<div>'+this.innerHTML+'</div>';
				htmlOptions.flashvars.txt = $(this).html();
				$(this).html('<div>'+htmlOptions.flashvars.txt+'</div>');
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass('alt');
				$(this)
					.addClass('flash-replaced')
					.prepend($.fn.flash.transform(htmlOptions));
			}
		);
	*/
	
	
	
	
	
	
	
	// Location, location, location. (location)
	$('ul#locations li').hover(
		function() {
			$(this).addClass('hovered');
		},
		function() {
			$(this).removeClass('hovered');
		});
	$('ul#locations li').click(function() {
		$(this).toggleClass('expanded');
	});
	
	
	
	// Appointment Request Form Validation
	$('form#appt-request').validate(
		{
			rules: {
				appt_loc: 'required',
				pat_fname: 'required',
				pat_lname: 'required',
				pat_dphone: {
					required: {
						depends: function(e) {
							return ($('#pat-contact-type').val() == 'phone')? true:false;
						}
					}
				},
				pat_cphone: {
					required: {
						depends: function(e) {
							return ($('#pat-contact-type').val() == 'phone')? true:false;
						}
					}
				},
				pat_email: {
					required: {
						depends: function(e) {
							return ($('#pat-contact-type').val() == 'email')? true:false;
						}
					},
					email:true
				}
			},
			messages: {
				appt_loc: 'Please select a location.',
				pat_fname: 'Please provide your first name.',
				pat_lname: 'Please provide your last name.',
				pat_dphone: 'Please provide a home phone number so we can contact you.',
				pat_cphone: 'Please provide a cell phone number so we can contact you.',
				pat_email: {
					required: 'Please provide an email address so we can contact you.',
					email: 'Your email address appears to be invalid.<br />(Example: name@domain.com)'
				}
			},
			errorClass: 'invalid',
			highlight: function(e,ec) {
				$(e).addClass(ec);
			},
			unhighlight: function(e,ec) {
				$(e).removeClass(ec);
			},
			submitHandler: function(form) {
				var subOpt = {
					type: 'POST',
					target: '#success',
					success: showResponse
				};
				formShade($('div.form',form));
				$(form).ajaxSubmit(subOpt);
				return false;
			}
		});
	
	
	
	// Contact Form Validation
	$('form#contact-form').validate(
		{
			rules: {
				contact_name: 'required',
				contact_email: {
					required: {
						depends: function(e) {
							return ($('#contact-phone').val() == '')? true:false;
						}
					},
					email:true
				},
				contact_phone: {
					required: {
						depends: function(e) {
							return ($('#contact-email').val() == '')? true:false;
						}
					}
				},
				contact_message: 'required'
			},
			messages: {
				contact_name: 'Please provide your name.',
				contact_phone: 'Please provide either an email address or a phone number.',
				contact_email: {
					required: 'Please provide either an email address or a phone number.',
					email: 'Your email address appears to be invalid.<br />(Example: name@domain.com)'
				},
				contact_message: 'Please leave us a message.'
			},
			errorClass: 'invalid',
			highlight: function(e,ec) {
				$(e).addClass(ec);
			},
			unhighlight: function(e,ec) {
				$(e).removeClass(ec);
			}
		});
	
	
	
	$('ul#staff-files-list li span.title, ul#staff-files-list ul:not(.file-list) li span.title').click(function(){
		var p = $(this).parent('li');
		$(p).toggleClass('open');
		$('> ul',p).toggleClass('shown');
		});
	
	
	
	function formShade(el) {
		$('<div class="shade"><img src="/layout/images/spinner_bl.gif" alt="" /></div>').appendTo(el).fadeIn(400);
	}
	function showResponse() {
		$('form#appt-request div.form').slideUp(800);
		$('div#success').slideDown(800);
	}
	
	
	
	if ($('a#vid-launch').length) {
		$('a#vid-launch').fancybox({
			padding:0,
			margin:0,
			width:820,
			height:625,
			hideOnContentClick:false,
			overlayOpacity:0.7
		}).click();
	}
	
});