	jQuery.preloadImages = function()
 {
    for (var i = 0; i < arguments.length; i++)
    {
        jQuery("<img>").attr("src", arguments[i]);
    }
}
$.preloadImages();


var Plaza = {

    init: function(page)
    {
		var a = document.URL.split("//");
			// split at protocol
			a = (a[1] ? a[1] : a[0]).split("/");
			page = a[1];
			subpage = a[2];
			// use last element of a; split at /
			// host is a[0]; path is a[1..(n-1)]; a[n] is page
	
		var page = page || 'home';
		page == 'home' || page == 'index.php' ? page = 'home' : page = page;
		this.page = page;

		this.navStates('#nav>ul>li');
		
       //alert(subpage);
       		
       
		// $('#submitBtn').click(function() {			
		// 			$('#contact-form').submit();
		// 		});

            jQuery.validator.addMethod("phone",
                        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}$/);
                            //phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
                        },
                        "Please provide a valid phone number");
            
            $("#contact-form").validate();
            
        // Render UI effects per page
        switch (page) {
        case 'home':

        break;
		case 'directory':
			$(".popup").colorbox({width:"878", height:"553", iframe:true});
		break;
		case 'events':

        break;
		case 'mommy':
			
		break;
		case 'contact':
			$('a.contact').addClass('contact-on');
			if ($.browser.msie && $.browser.version < 7) {
				$('input:text').addClass('text');
			}			
			switch (subpage) {
	        case '':	        
            $("#contact").validate({
			  rules: {
				  firstname: "required",
                  lastname: "required",					 
				  email: { required:true, email:true},
				  phone: "phone"
				}
			});
			break;
			case 'mommy_sign_up.php':	        
            $("#contact").validate({
			  rules: {
				  firstname: "required",
                  lastname: "required",					 
				  email: { required:true, email:true},
				  phone: "phone"
				}
			});
			break;
			case 'email.php':	        
            $("#contact").validate({
			  rules: {
				  firstname: "required",
                  lastname: "required",					 
				  email: { required:true, email:true},
				  phone: "phone"
				}
			});
			break;
			}
			
		break;
        }
    },

    // FUNCTIONS   

    navStates: function(b)
    // b is the id of the li tag - controls over states and dropdowns for top nav - on states are controlled separately inside the doc ready
    {
        //nav over states
        $(b).hover(
        function() {
            aTag = $(this).find('a:first');
            origUrl = aTag.css('backgroundImage');
            bkrdUrl = aTag.css('backgroundImage');
            // orginial value of bkrdUrl- will change
            if (origUrl.match(/_on.png/))
            {
                bkrdUrl = origUrl.split("_on.png").join(".png");
            }
            else if (origUrl.match(/_over.png/))
            {
                bkrdUrl = origUrl.split("_over.png").join(".png");
            }

            aTag.css('backgroundImage', bkrdUrl.split(".png").join("_over.png"));
            $(this).find('ul').css('display', 'block');
        },
        function() {

            if (bkrdUrl.match(/_on.png/))
            {
                aTag.css('backgroundImage', origUrl.split("_over.png").join("_on.png"));
            }
            else
            {
                aTag.css('backgroundImage', origUrl.split("_over.png").join(".png"));
            }
            $(this).find('ul').css('display', 'none');
        });

        //nav on states
       //alert(Plaza.page);
		
		if (Plaza.page == 'home') {
            $('#nav ul li a.home').parent().addClass('on');        
		} else if (Plaza.page == 'directory') {
            $('#nav ul li a.stores').parent().addClass('on');
        } else if (Plaza.page == 'events') {
            $('#nav ul li a.calendar').parent().addClass('on');
        } else if (Plaza.page == 'mommy') {
            $('#nav ul li a.mommy').parent().addClass('on');
        } else if (Plaza.page == 'directions') {
            $('#nav ul li a.directions').parent().addClass('on');
        } 
    },

    aTagOverStates: function(aTag, onTextStyle, onTextColor, offTextStyle, offTextColor)
    //uses 'a' tag w/ parent tag's background image changing on hover
    {
        $(aTag).hover(
        function() {
            parentTag = $(this).parent();
            //alert(parentTag.get(0).tagName);
            bkrdUrl = parentTag.css('backgroundImage');

            parentTag.css('backgroundImage', bkrdUrl.split(".png").join("_over.png"));
            $(this).css({
                'textDecoration': onTextStyle,
                'color': onTextColor
            });
        },
        function() {
            parentTag.css('backgroundImage', bkrdUrl.split("_over.png").join(".png"));
            $(this).css({
                'textDecoration': offTextStyle,
                'color': offTextColor
            });
        });
    },
    linkRollovers: function(a)
    // id of a tag using background image
    {
        $(a).hover(
        function() {
            bkrdUrl = $(this).css('backgroundImage');
            $(this).css('backgroundImage', bkrdUrl.split(".png").join("_over.png"));
        },
        function() {
            $(this).css('backgroundImage', bkrdUrl.split("_over.png").join(".png"));
        });
    },

    

    rollovers: function(b)
    // b is the id of the img tag
    { 
        $(b).mouseenter(
        function() {
            $(this).attr('src', $(this).attr("src").split(".").join("-over."));
			//alert($(this).attr("src"));
        }).mouseleave(
        function() {
            $(this).attr('src', $(this).attr("src").split("-over.").join("."));
			//alert($(this).attr("src"));
        });
    }


}






