/*
 * Load Cufon Fonts and perform replacement
 */

//new Asset.javascript('/js/cufon-yui.js');
//new Asset.javascript('/js/FrancophilSans_500-FrancophilSans_700.font.js');

Cufon.replace(".tagline");
Cufon.replace(".chead");
Cufon.replace(".home-feature-links a", {hover: true});
Cufon.replace("#sidebar h2");
Cufon.replace("#sidebar h3");

jQuery.validator.addMethod("defaultTxt", function(value, element, params) {
	value = jQuery.trim(value);
	if (value != 'Name:' && value != 'Email:') {
		return true;
	}
}, jQuery.format("Please enter the correct value for {0} + {1}"));

$(function() {
	
	var agree = $("input[name='checkbox']");
	
	scanCheckbox();
	agree.change(function(){
		scanCheckbox();
	});
	
	if ($('#carousel').length > 0) {
		$('#carousel').cycle({
		    fx:    'fade', 
		    speed:  500,
		    timeout:  10000,
			next:   '#next', 
   			prev:   '#prev',
			pause:	true
		});
	}

	if ($('#photo-slider').length > 0) {
		
		$("a.lightbox").fancybox({
			'titleShow'     : false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack'
		});
		
		$('#photo-slider a').live('click', function(){
			return false;
		});

	}
	
	$('#navigation li').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).addClass('sfhover');
		} else {
			$(this).removeClass('sfhover');
		};
	});
	
	$("#subForm input, input[name='keywords'], #login input[name='pass']").focus(function(){
		if($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	});

	$("#subForm input, input[name='keywords'], #login input[name='pass']").blur(function(){
		if($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});
	
	$("#subForm").validate({
		'onkeyup': false,
		'rules': {
			'cm-name': {
				required: true,
				defaultTxt: true,
				minlength: 3
			},
			'cm-bikddd-bikddd': {
				required: true,
				email: true
			}
		},
		messages: {
			'cm-name': '',
			'cm-bikddd-bikddd': {
				required: '',
				email: ''
			}
		},
		'errorElement': 'em',
		'errorClass': 'invalid',
		'success': function(label) {
			label.removeClass();
			label.addClass("valid");
		}
	});
	
	$('#passwordField').keyup(function(e) {
		if(e.keyCode == 13) {
			$(this).submit();
		}
	});
	
	function scanCheckbox() {
		if (agree.is(':checked')) {
			$('#passwordField').removeAttr("disabled");
			$('#submitForm').removeAttr("disabled");
			$('#passwordField').val($('#passwordField').attr('title'));
		} else {
			$('#passwordField').attr("disabled", true);
			$('#submitForm').attr("disabled", true);
		};
	};

});
