/*
 * CreditPoint Mortgages Site Specific Scripts
 * Designed and Developed by James Lai
 *
 * http://www.creditpointmortgages.ca
 * http://www.jameslaicreative.com
 *
 * Copyright (c) 2006 - 2010 James Lai
 *
 */

Cufon.replace('h1, h2, h3, h4, h5, h6');

jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, "");
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

$(document).ready(function() {
	
	$("#select_consultants").change(function() {
        window.location = '/home/contact/' + $(this).val();
    });

	$(".cbox").colorbox({width:"800px", height:"500px", iframe:true, opacity: 0.5});

    // FAQ Item Toggle
    $("#faq h4").click(function() {
        $(this).next("div").slideToggle();
    });

    // Apply Now validation
    $("#applyform").validate({
            rules: {
            first_name: 'required',
            last_name: 'required',
            address: 'required',
            city: 'required',
            province: 'required',
            postalcode: 'required',
            phone_home: {
                required: true,
                phoneUS: true
            },
            phone_mobile: {
                phoneUS: true
            },
            email: {
                required: true,
                email: true
            }
        }
        
    });

    // Global definition qTips
    $(".def").each(function() {
        $(this).qtip({
            content: {
                title: $(this).text(),
                text: "Retriving definition...",
                url: "/home/definitions",
                data: { def: $(this).text() },
                method: "post"
            },
            show: 'mouseover',
            hide: 'mouseout',
            position: {
                corner: {
                    target: 'topRight',
                    tooltip: 'bottomLeft'
                }
            },
            style: {
              width: 400,
              padding: "0 10px 10px 10px",
              background: '#fff',
              color: 'black',
              textAlign: 'left',
              title : {
                background: "#fff",
                color: "#910000",
                padding: "10px 0 5px 10px" ,
                fontSize: "14px",
                textTransform: "capitalize"
              },
              border: {
                 width: 1,
                 radius: 5,
                 color: '#93d4dc'
              },
              tip: 'bottomLeft'
            }
        });
    });

    $("#askaquestion").click(function() {
        $("<div />").appendTo("body").load("/home/askaquestion").dialog({
            width: "570",
            height: "350",
            title: "Ask a Question"
        });
    });

	$("#landing-form").validate({
		rules :{
			first_name: {
				required: true
			},
			last_name: {
				required: true
			},
			email: {
				required: true,
				email: true
			},
			phone: {
				required: true,
				phoneUS: true
			}
		}
	});
    
});

