var SubNav = {
	show: function(){},
	hide: function(){},
	init: function(){
		if($('li.parentLi').length){
			$('li.parentLi').mouseover(function(e){
				$(this).addClass('open');
				$(this).find('ul.subnav').show();
			});
			$('li.parentLi').mouseout(function(e){
				$(this).removeClass('open');
				$(this).find('ul.subnav').hide();
			});
		}
	}
}

var SlideDeck = {
	init: function(){
		if($('.slidedeck').length){	
			if (jQuery.browser.safari && document.readyState != "complete"){
				setTimeout( arguments.callee, 100 );
				return;
			}
			$('a.nextSlide').click(function(e){
				e.preventDefault();
                window.adDeck.next();
				$('.right img.slideImages').removeClass('active').fadeOut('fast');
				$('.right img.slideImages:first-child').addClass('active').fadeIn('fast');
				return false;
			});
			$('.slidedeck dt').click(function(){
				$('.right img.slideImages').removeClass('active').fadeOut('fast');
				$('.right img.slideImages:first-child').addClass('active').fadeIn('fast');
			});
			$('a.imageLink').click(function(e){
				e.preventDefault();
				var imgId = $(this).attr('href').split('#')[1];
				$('#'+imgId).addClass('active');
				$('#'+imgId).siblings().removeClass('active');
				$('#'+imgId).fadeIn("normal",function(){
					$('#'+imgId).siblings().hide();
				});					
				return false;
			});
			if($('#home_contact').length){
				window.validateForms['home_contact'] = new FormValidator('home_contact',{name: 'Name Required', email: 'Email Address Required'});
				$('#home_contact').submit(function(e){
					if (window.validateForms['home_contact'].validate()) {
						e.preventDefault();
						$.post(
							'/wordpress/wp-content/themes/xsprada/slidedeck/contact.php',
							$('#home_contact').serialize(),
							function(response){
								if (response.success) {
									$('#request_more_wrapper').fadeOut("normal", function(){
										$('#thankyou_message').fadeIn("normal");
									});
								}
							},
							'json'
						);
					}
					return false;
				});
			}
		}	
	}
}

$(document).ready(function(){
	window.validateForms = {};
	DOMUtilities.init();
	SubNav.init();
	SlideDeck.init();
 });
 /**
 * DOM Utilies Object for handling basic DOM actions
 * @author					Dave Shepard
 * @version					1.0
 * @required libraries:		JQuery 1.3.2 or later
 * 
 * Usage:
 *     $(document).ready(function(){
 *     		DOMUtilities.init();
 *     });
 *     
 * Can be initialized via the init(); method to apply to entire <body> or
 * a scope can be passed to limit the initialization to the child elements
 * of a particular element. Individual methods can als be called and passed
 * a scope.
 */
var DOMUtilities = {
	targetBlank: function(locality){
		// XHTML 1.0 Strict work around for external links
		$(locality+' a[rel*="external"]').attr("target","_blank");
	},
	inputAutoClear: function(locality){
		$(locality+' input.clearField').focus(function(){
			if(this.defaultValue == this.value) this.value='';
		}).blur(function(){
			if(this.value == '') this.value = this.defaultValue;
		});
	},
	imgRollover: function(locality){
		// Image roll-over setup
		$(locality+' img.rollOver, '+locality+' input[type="image"].rollOver')
			.mouseover(function(){
				if (this.src.indexOf("_i.") != -1) {
					this.src = this.src.replace("_i.", "_o.");
				}
			}).mouseout(function(){
				if (this.src.indexOf("_o.") != -1) {
					this.src = this.src.replace("_o.", "_i.");
				}
				if(this.src.indexOf("_a.")) {
					this.src = this.src.replace("_a.","_i.");
				}
			}).filter("input").mousedown(function(){
				this.src = this.src.replace("_o.","_a.");
			}).mouseup(function(){
				this.src = this.src.replace("_a.","_i.");
			});
	},
	scrollTo: function(locality){
		//scrollTo setup
		$(locality+' a.scrollTo')
			.click(function(){
				$.scrollTo('#content', 800);
				return false;
			});
	},
	init: function(locality){
		if(locality == null) {
			locality = "body";
		}
		this.targetBlank(locality);
		this.inputAutoClear(locality);
		this.imgRollover(locality);
		this.scrollTo(locality);
	}
}
