$(document).ready(function () { 
							
	rollovers();
	
	//$(document).pngFix(); 
	
	if($('#slider').length) {
		$('#slider').easySlider({
			controlsShow: false,
			auto: true, 
			continuous: true,
			speed: 400,
			pause: 9000
		});
	}
	
	if($('ul.archive').length) {
		$('ul.archive li').click(function() {
			$('ul.archive').removeClass('open')							  
			$('ul.archive li ul').hide();
			var thisList = $(this).find('ul');	
			thisList.show();
		});
		
	}
	
	if($('select#queryType').length) {
		$('select#queryType').selectmenu({ width: 242 });

	}
	
	if($('#emailaddress').length) {
		$("#emailaddress").focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	}
	
	if($('#portfolio').length) {
		var loadImage = $(".portLink:first").attr('href');
		$('#portImage').attr('src',loadImage);	
		
		$(".portLink").click(function() {
			var image = $(this).attr('href');
			$('#portImage').attr('src',image);			
			return false;
		});
	}
	
	if($('#subscribeBut').length) {
		$('#subscribeBut').click(function() {
			var email = $("input[name='emailaddress']");	
			
			if(email.val() == '' || email.val() == 'enter email address here') {
				alert("You can't receive the newsletter without an email address, wanna try again?");
				email.focus();
			} else if(!isEmail(email.val())) {
				alert("This isn't a valid email address, wanna try again?");
				email.focus();
			} else {
				//alert('in');
				$.post("/assets/includes/subscribe.php", { emailval: email.val() },
				  function(data){
					  //alert(data);
					$('#subscribeForm').hide();
					$('#subscribeThanks').show();
				  });
			}
		});
	}
	
	if($('a#submit').length) {
		$('a#submit').click(function() {
			var queryType = $('#queryType');
			var email = $("input[name='your_email']");
			var phone = $("input[name='your_phone']");
			var message = $("textarea[name='your_message']");
			
			if(email.val() == '') {
				alert("We need your email address to send you a reply");
				email.focus();
			} else if(!isEmail(email.val())) {
				alert("This isn't a valid email address, wanna try again?");
				email.focus();
			} else if(message.val() == '') {
				alert("Seems like you forgot to tell us something, put it in the message box.");
				message.focus();
			} else {
				//alert('in');
				$.post("/assets/includes/contact.php", { emailval: email.val(), queryval: queryType.val(), phoneval: phone.val(), messageval: message.val()},
				  function(data){
					  //alert(data);
					//$('#contactForm').hide();
					clear_form_elements();
					$('#subscribeThanks').show();
				  });
			}
			
		});
	}
	
	if($('a#cancel').length) {
		$('a#cancel').click(function() {
			clear_form_elements();						 
		});
	}
	
	if($('.equal').length) {
		var maxHeight = 0;
		$(".equal").each(function(){
			if ($(this).height() > maxHeight) {
				maxHeight = $(this).height(); 
			}
		});
		$(".equal").height(maxHeight);
	}

	
});

function rollovers()
{
	$(".rollover").hover(
		function () {
			var imgSrc = $(this).attr("src");
			var newImgSrc = imgSrc.replace("_off","_on");
			
			$(this).attr("src",newImgSrc);
		}, 
		function () {
			imgSrc = $(this).attr("src");
			newImgSrc = imgSrc.replace("_on","_off");
			
			$(this).attr("src",newImgSrc);
		}
	);
}

function isEmail(str)
{
	if(str == "") return false;

	var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i

	return re.test(str);
}

function clear_form_elements() {

    $('input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });
	$('textarea').each(function() {
		 $(this).val('');						
	});

}

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-11449116-12']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

