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

$.fn.qtip.styles.phoenix = { // Last part is the name of the style
	width: 150,
	background: '#220b00',
	color: 'CCCCCC',
	textAlign: 'center',
	border: {
		width: 2,
		radius: 7,
		color: '#220b00'
	},
	tip: {
		corner: 'topMiddle',
		size: {
			x: 20,
			y: 8
		}
   }
}

jQuery(function() {
	// show a simple loading indicator
	var loader = jQuery('<div id="loader"><img src="images/ajax-loader.gif" alt="loading..." /></div>')
		.css({position: "relative", "margin-left": "335px", "margin-top": "50px"})
		.appendTo("#contact")
		.hide();
	jQuery().ajaxStart(function() {
		$('#contactForm').hide();
		loader.show();
	}).ajaxStop(function() {
		loader.hide();
		$('#contactForm').show();
	}).ajaxError(function(a, b, e) {
		throw e;
	});
		
	var v = jQuery("#contactForm").validate({
		errorLabelContainer: $("div.error"),
		rules: { 
			name: "required",
			email: {
				required: true,
				email: true
			}, 
			message: "required"
		},
		messages: {
			name: "please enter your name",
			email: "please enter a valid email",
			message: "please enter a message"
		},
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				success: alert("Thank you for contacting PHOENIXreaction!"),
				clearForm: true,
				resetForm: true
			});
		}
	});
		
});

$(document).ready(function() {
	$.preloadImages( "images/dw-logo-hover.png", "images/logo-design-hover.png", "images/ps-logo-hover.png", "images/wp-logo-hover.png", "images/graphics-hover.png", "images/print-hover.png", "images/more-hover.png", "images/input-focus-bg.png", "images/textarea-focus-bg.png", "images/top-hover.png", "images/mini-email.png", "images/mini-external.gif", "images/h2-free-stuff.png");
	
	$('#header').sparks([
    {
        number: 10,
        speed:  5,
        img:    'images/spark.png'
    }
	]);
	
	$('.blurb').hover(function () {
		$(this).children("span").css("color", "#999");
		$(this).children("span.title").css("color", "#ccc");
		rollsrc = $(this).children("img").attr("src");
		rollhov = rollsrc.replace(/([^.]*)\.(.*)/, "$1-hover.$2");
		$(this).children("img").attr("src", rollhov);
	},
	// on mouse out
	function () {
		$(this).children("span").css("color", "#333");
		rollsrc = $(this).children("img").attr("src");
		rolloff = rollsrc.replace( '-hover', '' );
		$(this).children("img").attr("src", rolloff);
	});

	$('.service').hover(function () {
		$(this).children("p").css("color", "#CCC");
		rollsrc = $(this).children("img").attr("src");
		rollhov = rollsrc.replace(/([^.]*)\.(.*)/, "$1-hover.$2");
		$(this).children("img").attr("src", rollhov);
	},
	// on mouse out
	function () {
		$(this).children("p").css("color", "#666");
		rollsrc = $(this).children("img").attr("src");
		rolloff = rollsrc.replace( '-hover', '' );
		$(this).children("img").attr("src", rolloff);
	});

	$('.wallpaper').hover(function () {
		$(this).children("p").css("color", "#CCC");
		rollsrc = $(this).children("img").attr("src");
		rollhov = rollsrc.replace(/([^.]*)\.(.*)/, "$1-hover.$2");
		$(this).children("img").attr("src", rollhov);
	},
	// on mouse out
	function () {
		$(this).children("p").css("color", "#666");
		rollsrc = $(this).children("img").attr("src");
		rolloff = rollsrc.replace( '-hover', '' );
		$(this).children("img").attr("src", rolloff);
	});

	$('.submitBtn').hover(function () {
		$(this).css("color", "#FFF");
	},
	// on mouse out
	function () {
		$(this).css("color", "#CCC");
	});

	
	$("#slider").easySlider();
	
	$('#message').limit('200','#charsLeft');
	
	$("input, textarea").addClass("idle");
		$("input, textarea").focus(function(){
			$(this).addClass("active").removeClass("idle");
		}).blur(function(){
			$(this).removeClass("active").addClass("idle");
	});
	
	$('a[rel="external"]').addClass("linkext");

	$('#navContactUs').qtip({
		content: 'Takes you to the contact form in the footer!',
		show: 'mouseover',
		hide: 'mouseout',
   		position: {
      		corner: {
         		target: 'bottomMiddle',
         		tooltip: 'topMiddle'
      		}	
		},
		style: 'phoenix'
	})

	$('#validxhtml').qtip({
		content: 'This page is valid W3C XHTML 1.0',
		show: 'mouseover',
		hide: 'mouseout',
   		position: {
      		corner: {
         		target: 'bottomMiddle',
         		tooltip: 'topMiddle'
      		}	
		},
		style: 'phoenix'
	})

	$('#validcss').qtip({
		content: 'This page is valid W3C CSS',
		show: 'mouseover',
		hide: 'mouseout',
   		position: {
      		corner: {
         		target: 'bottomMiddle',
         		tooltip: 'topMiddle'
      		}	
		},
		style: 'phoenix'
	})

	$('span.mailme').mailme();
	
	$("#showcase a").lightBox({
		imageBtnClose: 'images/lightbox-btn-close.png',
		imageBtnNext: 'images/lightbox-btn-next.png',
		imageBtnPrev: 'images/lightbox-btn-prev.png'
	});

	$("#downloads a.wallpaper").lightBox({
		imageBtnClose: 'images/lightbox-btn-close.png',
		imageBtnNext: 'images/lightbox-btn-next.png',
		imageBtnPrev: 'images/lightbox-btn-prev.png'
	});

	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href'),'external','width=800,height=600' );
        return false;
    });

});

