$(function(){
			if(document.location.hash.length < 1) {
				
				var homeOffset = $('#midArea').offset();
				$('html:has("body.front"), body.front').scrollTop(homeOffset.top);
				
			}
			
			$('#main-nav div.fancyBox_data, #about #block-block-6 .content #team div, #about #block-block-5 .content #process div, #services, #portfolio'). css('visibility', 'visible');

			$('#about #block-block-6 .content #team div[id]').css('position', 'absolute').not('#aboutUs').not('#teamNav_wrapper').hide();
			$('#about #block-block-5 .content #process div').css('position', 'absolute').not('#strategy').hide();
			$('#services h3').hide();


			//main navigation
			$('.front #main-nav a.nav_home, #main-nav-top a.nav_what, #main-nav-mid a.nav_about').addClass('current');
			
			if($('body').hasClass('front')){
				$('a.nav_home').attr('href', '#midArea');
				$('a.nav_what').attr('href', '#topArea');
				$('a.nav_about').attr('href', '#underWater');
				$('a.nav_home, a.nav_what, a.nav_about').addClass('anchorLink');
			} else if($('body').hasClass('not-front')){
				$('#main-nav a.nav_home').attr('href', 'http://www.yellowberri.com');
				$('#main-nav a.nav_what').attr('href', 'http://www.yellowberri.com/#topArea');
				$('#main-nav a.nav_about').attr('href', 'http://www.yellowberri.com/#underWater');
			};
			
			
			$("a.anchorLink").anchorAnimate();
		


		//portfolio stuff
		$('<ul id="clientList"></ul>').prependTo('#block-views-Portfolio-block_1 .content .view-Portfolio');
		
		$('#block-views-Portfolio-block_1 .content .view-Portfolio .view-content .views-row').each(function(){
			var portItem_title = $(this).children('.views-field-title').text();
			var converted_title = portItem_title.replace(/\s+/g, '-').toLowerCase();
			var port_img_src = $(this).children('.views-field-field-project-image-fid').children('.field-content').children('img').attr('src');
			$('<div class="pics_holder"></div>').appendTo($(this));
			$(this).children('.views-field-field-project-image-fid, .views-field-field-project-image-2-fid, .views-field-field-project-image-3-fid').hide().appendTo($(this).children('.pics_holder'));
			
			$(this).children('.views-field-title').children('span.field-content').children('a').attr('href', '#').attr('name', '#' + converted_title);
			$('<li><a id="' + converted_title + '" class="' + port_img_src + '" style="background: url(\'' + port_img_src + '\') #2b87af -40px -100px;" href="#">' + portItem_title + '</a></li>').appendTo('ul#clientList');
	
			$(this).addClass(converted_title).dialog({
				autoOpen: false,
				width: 880,
				minHeight: 390,
				modal: true,
				title: portItem_title,
				show: 'slide',
				hide: 'slide',
				dialogClass: 'portItem',
				resizable: false
			});
		});

		$('ul#clientList li').each(function(){
			var client_title = $(this).children('a').attr('id');
			var bg_src = $(this).children('a').attr('class');
			$(this).children('a').css('opacity', '1').hover(
				function(){
					$(this).css({
						'background-image' : 'none',
						'opacity' : '1'
					});
				}, 
				function(){
					$(this).css({
						'background-image' : 'url("' + bg_src + '")',
						'opacity' : '1'
					});
				}).click(function(event){
				$('.' + client_title).dialog('open');
				return false;
			});
			
		});
		$('<div class="portItem_nav"><ul><li><a class="portItem_navBtn 1" href="#">1</a></li><li><a class="portItem_navBtn 2" href="#">2</a></li><li><a class="portItem_navBtn 3" href="#">3</a></li></ul></div>').appendTo($('.ui-dialog .views-row'));
		
		$('.ui-dialog .views-row').each(function(){
			$(this).children('.pics_holder').children('.views-field-field-project-image-fid').show().addClass('current');
			$(this).children('.portItem_nav').children('ul').children('li').children('a.portItem_navBtn').click(function(){
				$('.current').fadeOut().removeClass('current');
				if($(this).hasClass('1')){
					$(this).parent().parent().parent().parent().children('.pics_holder').children('.views-field-field-project-image-fid').fadeIn().addClass('current');
				} else if($(this).hasClass('2')){
					$(this).parent().parent().parent().parent().children('.pics_holder').children('.views-field-field-project-image-2-fid').fadeIn().addClass('current');
				} else if($(this).hasClass('3')){
					$(this).parent().parent().parent().parent().children('.pics_holder').children('.views-field-field-project-image-3-fid').fadeIn().addClass('current');
				}
			});
		});

		Cufon.replace('.ui-dialog .portItem_nav ul li a');


			//centering elements
			function findRaysPos() {var raysPos = ($(window).width() * 0.5) - 15; return raysPos;}
			function findPortfolioPos() {var portfolioPos = (($(window).width() * 0.5) - ($('#portfolio').width() * 0.5)); return portfolioPos;}
			function findAboutPos() {var aboutPos = (($(window).width() * 0.5) - ($('#about').width() * 0.5)); return aboutPos;}
			function findCloudsPos() {var cloudsPos = (($(window).width() * 0.5) - ($('#clouds').width() * 0.5)); return cloudsPos;}
			function findFooterPos() {var footerPos = (($(window).width() * 0.5) - ($('#footer').width() * 0.5)); return footerPos;}
			
			
			$('#portfolio').css('left', findPortfolioPos() + 'px');
			$('#about').css('left', findAboutPos() + 'px');
			$('#clouds').css('left', findCloudsPos() + 'px');
			$('#footer').css('left', findFooterPos() + 'px');
			
			$(window).bind('resize', resizeWindow);
			function resizeWindow(e){
				$("#rays").css('left', findRaysPos() + 'px');
				$('#portfolio').css('left', findPortfolioPos() + 'px');
				$('#about').css('left', findAboutPos() + 'px');
				$('#clouds').css('left', findCloudsPos() + 'px');
				$('#footer').css('left', findFooterPos() + 'px');
			}
			
			
			//rays
			var raysCSS = {
				'position' : 'absolute',
				'left' : findRaysPos() + 'px',
				'top' : '-136px',
				'width' : '398px',
				'height' : '400px'
			};
			$('#rays').css(raysCSS);			

			if($('body').hasClass('front')){
				var paper = Raphael(document.getElementById("rays"), 398, 400);
				var rays = paper.image("http://www.yellowberri.com/ybtopsecret/sites/all/themes/yellowberri/images/rays.png", 0, 0, 398, 400);
				setInterval(
					function(){
						rays.rotate(2);
					},
					200
				);
			};
			
			
		//popup forms	

		var name = $("#name"),
			email = $("#email"),
			phone = $("#phone"),
			interests = new Array;
			message = $("#message"),
			quote_name = $("#quote_name"),
			quote_email = $("#quote_email"),
			quote_company = $("#quote_company"),
			quote_city = $("#quote_city"),
			quote_state = $("#quote_state"),
			quote_phone = $("#quote_phone"),
			timeFrame = "";
			quote_budget = $("#quote_budget"),
			quote_siteSections = $("#quote_siteSections"),
			quote_projectDesc = $("#quote_projectDesc"),
			quote_planToSell = $("#quote_planToSell"),
			quote_reach = $("#quote_reach"),
			quote_designReq = $("#quote_designReq"),
			quote_comments = $("#quote_comments"),
			hosting = "",
			quote_change = $("#quote_change"),
			maintenance = "",
			
			allFields = $([]).add(name).add(email).add(phone),
			tips = $(".validateTips");

		function updateTips(t) {
			tips
				.text(t)
				.addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight', 1500);
			}, 500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Length of " + n + " must be between "+min+" and "+max+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		//contact form
		var cfHeight = $(window).height() * 0.8;
		$("#contact-form").dialog({
			autoOpen: false,
			height: cfHeight,
			width: 960,
			modal: true,
			resizable: true,
			buttons: {
				'Contact Us': function() {
					$('input[name=interests]:checked').each(function(){
						interests.push($(this).val());
					});
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(name,"name",3,16);
					bValid = bValid && checkLength(email,"email",6,80);
					bValid = bValid && checkLength(phone,"phone",5,16);

					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com");
					bValid = bValid && checkRegexp(phone,/^([0-9])+$/,"Phone field only allows: 0-9");
					
					if (bValid) {
						$.post("sites/all/themes/yellowberri/php/message.php",
						   { name: name.val(), email: email.val(), phone: phone.val(), interests: interests.join(', '), message: message.val() },
							function(data){
						    	
						 }
						);
						$(this).dialog('close');
						$('<div style="font-weight: bold; font-size: 1.8em;">Message Successfully Sent!</div>').dialog({resizable: false});
					}
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		

		//quote form
		var qfWidth = $(window).width() * 0.6;
		var qfHeight = $(window).height() * 0.8;
		$("#quote-form").dialog({
			autoOpen: false,
			height: qfHeight,
			width: qfWidth,
			modal: true,
			resizable: false,
			buttons: {
				'Get A Quote': function() {
					$('input[name=interests]:checked').each(function(){
						interests.push($(this).val());
					});
					timeFrame = $('input[name=timeFrame]:checked').val();
					hosting = $('input[name=hosting]:checked').val();
					maintenance = $('input[name=maintenance]:checked').val();

					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(quote_name,"quote_name",3,16);
					bValid = bValid && checkLength(quote_email,"quote_email",6,80);
					bValid = bValid && checkLength(quote_phone,"quote_phone",5,16);

					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp(quote_email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com");
					bValid = bValid && checkRegexp(quote_phone,/^([0-9])+$/,"Phone field only allows: 0-9");
					
					if (bValid) {
						$.post("sites/all/themes/yellowberri/php/quote.php",
						   { quote_name: quote_name.val(), quote_email: quote_email.val(), quote_company: quote_company.val(), quote_city: quote_city.val(), quote_state: quote_state.val(), quote_phone: quote_phone.val(), interests: interests.join(', '), timeFrame: timeFrame, quote_budget: quote_budget.val(), quote_siteSections: quote_siteSections.val(), quote_projectDesc: quote_projectDesc.val(), quote_planToSell: quote_planToSell.val(), quote_reach: quote_reach.val(), quote_designReq: quote_designReq.val(), quote_comments: quote_comments.val(), hosting: hosting, quote_change: quote_change.val(), maintenance: maintenance },
							function(data){
						    	
						 }
						);
						$(this).dialog('close');
						$('<div style="font-weight: bold; font-size: 1.2em;">Your Quote Request Has Been Sent. Please Allow Us 48 Hours To Get A Price Together For You.</div>').dialog({resizable: false});
					}
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});

		
		$('a.nav_contact').click(function() {
				$('#contact-form').dialog('open');
				return false;
			});
		$('a.nav_quote').click(function() {
				$('#quote-form').dialog('open');
				return false;
			});
			
			
	//services stuff
	$('#services .dialog').each(function(){
		var d_title = $(this).children('div').children('h3').text();
		$(this).children('div').dialog({
			autoOpen: false,
			width: 800, 
			modal: true,
			title: d_title,
			show: 'slide',
			hide: 'slide',
			resizable: false
		});
	});
	
	$('#services ul li').each(function(){
		var service_cat = $(this).children('a').text().toLowerCase();
		$(this).children('a').click(function(){
			$('#' + service_cat + 'Box').dialog('open');
			return false;
		});
	});
	
	
	Cufon.replace('.ui-dialog .ui-dialog-title');
		
	
	
	
	
	//process
	$('#strategy').addClass('process_current');
	$('<div id="processNav"><a id="prev" href="#"></a><a id="next" href="#"></a></div>').appendTo('#process').css('visibility', 'visible');
	
	var strategyLink = $('<span class="strategyLink">strategy</span>');
	var productionLink = $('<span class="productionLink">production</span>');
	var finetuningLink = $('<span class="finetuningLink">fine-tuning</span>');
	var launchLink = $('<span class="launchLink">launch</span>');
	var intouchLink = $('<span class="intouchLink">stay in touch</span>');
	
	$('#process').children('#processNav').children('a#next').append(productionLink);
	
	$('#next').click(function(event){
		if($('#strategy').hasClass('process_current')){
			$('span.productionLink').remove();
			$('#process').children('#processNav').children('a#prev').append(strategyLink);
			$('#process').children('#processNav').children('a#next').append(finetuningLink);
			$('#strategy').removeClass('process_current').fadeOut();
			$('#production').addClass('process_current').fadeIn();
			event.preventDefault();
		} else if($('#production').hasClass('process_current')){
			$('span.strategyLink, span.finetuningLink').remove();
			$('#process').children('#processNav').children('a#prev').append(productionLink);
			$('#process').children('#processNav').children('a#next').append(launchLink);
			$('#production').removeClass('process_current').fadeOut();
			$('#fine-tuning').addClass('process_current').fadeIn();
			event.preventDefault();
		} else if($('#fine-tuning').hasClass('process_current')){
			$('span.productionLink, span.launchLink').remove();
			$('#process').children('#processNav').children('a#prev').append(finetuningLink);
			$('#process').children('#processNav').children('a#next').append(intouchLink);
			$('#fine-tuning').removeClass('process_current').fadeOut();
			$('#launch').addClass('process_current').fadeIn();
			event.preventDefault();
		} else if($('#launch').hasClass('process_current')){
			$('span.finetuningLink, span.intouchLink').remove();
			$('#process').children('#processNav').children('a#prev').append(launchLink);
			$('#process').children('#processNav').children('a#next');
			$('#launch').removeClass('process_current').fadeOut();
			$('#intouch').addClass('process_current').fadeIn();
			event.preventDefault();
		}
	});
	$('#prev').click(function(event){
		if($('#production').hasClass('process_current')){
			$('span.strategyLink, span.finetuningLink').remove();
			$('#process').children('#processNav').children('a#prev');
			$('#process').children('#processNav').children('a#next').append(productionLink);
			$('#production').removeClass('process_current').fadeOut();
			$('#strategy').addClass('process_current').fadeIn();
			event.preventDefault();
		} else if($('#fine-tuning').hasClass('process_current')){
			$('span.productionLink, span.launchLink').remove();
			$('#process').children('#processNav').children('a#prev').append(strategyLink);
			$('#process').children('#processNav').children('a#next').append(finetuningLink);
			$('#fine-tuning').removeClass('process_current').fadeOut();
			$('#production').addClass('process_current').fadeIn();
			event.preventDefault();
		} else if($('#launch').hasClass('process_current')){
			$('span.finetuningLink, span.intouchLink').remove();
			$('#process').children('#processNav').children('a#prev').append(productionLink);
			$('#process').children('#processNav').children('a#next').append(launchLink);
			$('#launch').removeClass('process_current').fadeOut();
			$('#fine-tuning').addClass('process_current').fadeIn();
			event.preventDefault();
		} else if($('#intouch').hasClass('process_current')){
			$('span.launchLink').remove();
			$('#process').children('#processNav').children('a#prev').append(finetuningLink);
			$('#process').children('#processNav').children('a#next').append(intouchLink);
			$('#intouch').removeClass('process_current').fadeOut();
			$('#launch').addClass('process_current').fadeIn();
			event.preventDefault();
		}
	});
	
	//team
		
	$('#aboutUs').addClass('team_current');
	$('#about #block-block-6 .content #teamNav a').click(function(event){
		$('.team_current').fadeOut().removeClass('team_current');
		if($(this).hasClass('nav_dave')){
		   $('#about_dave, #about_dave div').addClass('team_current').fadeIn();
		} else if($(this).hasClass('nav_pappy')){
		   $('#about_pappy, #about_pappy div').addClass('team_current').fadeIn();
		} else if($(this).hasClass('nav_bones')){
		   $('#about_bones, #about_bones div').addClass('team_current').fadeIn();
		} else if($(this).hasClass('nav_drew')){
		   $('#about_drew, #about_drew div').addClass('team_current').fadeIn();
		} else if($(this).hasClass('nav_shelbo')){
		   $('#about_shelbo, #about_shelbo div').addClass('team_current').fadeIn();
		} else if($(this).hasClass('nav_ben')){
		   $('#about_ben, #about_ben div').addClass('team_current').fadeIn();
		}
		event.preventDefault();
	});
	$("a.nav_about, a.about_back").click(function(event){
		$('.team_current').fadeOut().removeClass('team_current');
		$('#aboutUs').addClass('team_current').fadeIn();
		if($(this).hasClass('about_back')){
			event.preventDefault();
		}
	});

});
