/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2008 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact.js 132 2008-05-23 16:05:17Z emartin24 $
 *
 */
$j(document).ready(function () {
	$j('#moreDetail').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$j.get("/data/TeacherDetail.php", function(data){
			// create a modal dialog with the data
			$j(data).modal({
				close: false,
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: contact.open,
				onClose: contact.close
			});
		});
	});

	// preload images
	var img = ['cancel.png','form_bottom.gif','form_top.gif','form_top_ie.gif','loading.gif','send.png'];
	$j(img).each(function () {
		var i = new Image();
		i.src = '/images/contact/' + this;
	});
});

var contact = {
	message: null,
	open: function (dialog) {
		// hide brightcove player, for IE only, avoid the overlap with the dialog
		if ($j.browser.msie)
		{
			$j('#player').css('visibility', 'hidden');
		}
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#contact-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#contact-container .contact-input').css({
				'font-size': '.9em'
			});
		}

		var title = $j('#contact-container .contact-title').html();
		$j('#contact-container .contact-title').html('Loading...');
		$j('#teacherName').html($j('#popup_teacher_name').attr('value')); 
		$j('#place').html($j('#popup_place').attr('value')); 
		$j('#picture').attr('src', ($j('#popup_picture').attr('src')  )); 
		$j('#interests').html($j('#popup_interests').html()); 
		$j('#course').html($j('#DataTextImageHist').html()); 
		$j('#name').html($j('#popup_name').html()); 
		$j('#courses').html($j('#popup_courses').html()); 
		$j('#experience').html($j('#popup_experience').html()); 
		$j('#personality').html($j('#popup_personality').html());
		$j('#favorite_teacher').html($j('#popup_favorite_teacher').attr('value'));
		$j('#personal_theme_tune').html($j('#popup_personal_theme_tune').attr('value'));
		$j('#advice_for_kids').html($j('#popup_advice_for_kids').attr('value'));
		$j('#fun_facts').html($j('#popup_fun_facts').attr('value'));
		
		
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#contact-container .contact-content').animate({
						height: 485
					}, function () {
						$j('#contact-container .contact-title').html(title);
						$j('#contact-container form').fadeIn(200, function () {
							$j('#contact-container #contact-name').focus();
	
							// fix png's for IE 6
							if ($j.browser.msie && $j.browser.version < 7) {
								$j('#contact-container .contact-button').each(function () {
									if ($j(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$j(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	
	close: function (dialog) {
		$j('#contact-container .contact-message').fadeOut();
		$j('#contact-container .contact-title').html('Goodbye...');
		$j('#contact-container form').fadeOut(200);
		$j('#contact-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
						// show up brightcove player when finish, for IE only
						if ($j.browser.msie)
						{
							$j('#player').css('visibility', 'visible');
						}
					});
				});
			});
		});
	}
};