function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

$(function() {
$("a.fancybox").fancybox(
{
'zoomSpeedIn': 300, 'zoomSpeedOut': 300
});
$('a.switch_map').click(function() {
	$(".google_streetview").toggle();
	return false;
});

			
			$(".rfpBody .Doc2Form fieldset").hide();
			$(".rfpBody .Doc2Form input.button").hide();
			$(".standard_form_shadow").show();
			
			var $els = $("ul.gecko_areas").equalizeCols();
			
			$('a#client_hub_open').show();
			
			//portfolio page image cycle
			$('#client_image_slider').cycle({ 
				fx:     'fade', 
				speed:  'slow', 
				timeout: 10000, 
				next:   '#porto_next', 
				prev:   '#porto_prev' 
			});
			
			//$(".twitter p").getTwitter({
			//	userName: "geckonm",
			//	numTweets: 1,
			//	loaderText: "Loading tweets...",
			//	slideIn: false,
			//	showHeading: false,
			//	headingText: "Latest Tweets",
			//	showProfileLink: false
			//});

			
			// IE!
			//$('#porto_prev').pngFix();
			//$('#porto_next').pngFix();
			
			//Portfolio navigation images
			$("#client_image a").css("opacity","0");
			$("#client_image").bind("mouseenter",function(){
				$(this).children("a").stop().animate(
					    { opacity:1 }, {
					     duration: 1000
					    })
			}).bind("mouseleave",function(){
				$(this).children("a").stop().animate(
					    { opacity:0 }, {
					     duration: 1000
					    })
			});
			
			//homepage case study carousel
			$("#case_study_block #homepage_casestudies").jCarouselLite({
				btnNext: "#case_study_block .next",
				btnPrev: "#case_study_block .prev",
				easing: "easeOutExpo",
				speed: 1000,
				visible: 4

			});

			//homepage main carousel
			$("#hp_main_carousel").jCarouselLite({
				btnNext: ".main_carousel_next",
				btnPrev: ".main_carousel_prev",
				easing: "easeOutExpo",
				speed: 1000,
				visible: 1,
auto: 20000
			});
			
			//site-wide hide client login with js
			$('#client_hub_login').hide();
			
			//default site easing
			jQuery.easing.def = "easeOutExpo";
			
			//open client login on click
			$('a#client_hub_open').click(function() {
				$("#client_hub_login").animate({ 
				height: "70px"
				}, 1000 );
				return false;
			});
			
			getTwitters('tweet', { 
			  id: 'geckonm', 
			  count: 1, 
			  enableLinks: true, 
			  ignoreReplies: true, 
			  clearContents: true,
			  template: '"%text%" <a href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a>'
			});
			
			//Homepage equalise columns
			var highestLi = 0;
			var thisheight = 0;
			$(".gecko_areas > li").each(function() {
				thisHeight = $(this).height();
				if(thisHeight > highestLi) {
					highestLi = thisHeight;
				}
			});
			$(".gecko_areas > li").height(highestLi);

			//blog posted, nested comment enabler
			$("ol.commentlist li").append("<a class='reply_to'>Reply to this comment</a>");
			
			
			
			//portfolio list extra info
			//$("ul#portfolio_list li").bind("mouseenter",function(){
		//		$(this).find("img")
		//			.stop().animate(
		//			    { bottom: "270px" }, {
		//			     duration: 1500, easing: 'easeOutBounce'
		//			    })
		//	}).bind("mouseleave",function(){
		//		$(this).find("img")
		//			.stop().animate(
		//			    { bottom: "0px" }, {
		//			     duration: 1500, easing: 'easeOutBounce'
		//			    });		
		//	});
			
			
			//RFP Generator
			$("fieldset.rfp_step_2").parent().parent("div.standard_form_shadow").hide();
			$("div.initial_response").hide();
			$("div.final_rfp").hide();
			
			//RFP Gen step 1 submit
			$("a#submit_step_1").click(function () { 
				var rfpName = $('input#rfp_name').val();
				var rfpCompany = $('input#rfp_company').val();
				var rfpPhone = $('input#rfp_phone').val();
				var rfpEmail = $('input#rfp_email').val();
				
				
				//quick validation
				var validationResponse = "<ul class='validation_response'>";
				var errorCount = 0;
				
				if(rfpName == ""){
					validationResponse += "<li>Please Enter a Name</li>";
					errorCount  ++;
				}
				if(rfpCompany == ""){
					validationResponse += "<li>Please Enter a company name</li>";
					errorCount  ++;
				}
				if(rfpPhone == ""){
					validationResponse += "<li>Please Enter a phone number</li>";
					errorCount  ++;
				}
				if(rfpEmail == ""){
					validationResponse += "<li>Please Enter an email address</li>";
					errorCount  ++;
				}
				//fail validation
				if (errorCount > 0) {
					validationResponse += "</ul>";
					$("div.initial_response").empty().append(validationResponse).fadeIn(750);
				}
				//pass validation
				else {
					//put together a little initial response
					var responseString = "<p>Hi there, <strong>"+rfpName+"</strong> from <strong>"+rfpCompany+"</strong>!</p><p>Thanks for taking the time to request a proposal with Gecko.  You've only got one more step to do, after which we'll get back in touch with you via <strong>"+rfpPhone+"</strong> (phone) or <strong>"+rfpEmail+"</strong> (email).</p><p><small><a href='#'>Change these details</a></small></p>";
					//alert(resonseString);
					
					$("fieldset.rfp_step_1 div").hide();
					$("div.initial_response").empty().append(responseString).fadeIn(750);
					
					//bring back step 2
					$("fieldset.rfp_step_2").parent().parent("div.standard_form_shadow").fadeIn(1000);
					return false;
				}
				
				
				
			});
			
			//RFP Step 1 edit details
			$("div.initial_response a").live("click", function(){	
				$("div.initial_response").empty();
				$("fieldset.rfp_step_1 div").show();
				$(this).parent().parent().parent("div").hide();
			return false;
			});
			
			//RFP hide extra fields and show/hide based on choices
			$("div.hidden_field").hide();
			$("select#rfp_website").change(function () {
				var rfpWebsite = $('select#rfp_website option:selected').val();
				if (rfpWebsite == "existing" ) {
					$("div.hidden_field").fadeIn("slow");
				}
				else {
					$("div.hidden_field").fadeOut("slow");
				}
			});
			
			//RFP Step 2 submit
			$("a#submit_step_2").live("click", function(){
				
				var rfpName = $('input#rfp_name').val();
				var rfpCompany = $('input#rfp_company').val();
				var rfpPhone = $('input#rfp_phone').val();
				var rfpEmail = $('input#rfp_email').val();
				var rfpWebsite = $('select#rfp_website option:selected').val();
				var rfpURL = $('input#rfp_url').val();
				
				var rfpChoices = new Array();
				$("div.checkboxes_groups input:checkbox:checked").each(function(i){
					rfpChoices[i] = $(this).parent("label").text();		
				});
				
				var rfpBigPicture = $('#rfp_bigpicture').val();
				var rfpTimeframe = $('#rfp_timeframe option:selected').val();
				var rfpBudget = $('#rfp_budget option:selected').val();
				
				//save cookie with the name of (potential!) client
				 $.cookie('gecko_rfpName', rfpName);
				
				
				//quick validation
				var validationResponse = "<ul class='validation_response'>";
				var errorCount = 0;
				
				if(rfpChoices == ""){
					validationResponse += "<li>Please choose at least on area that you require help with</li>";
					errorCount  ++;
				}
				if(rfpBigPicture == ""){
					validationResponse += "<li>Please enter a description of your project</li>";
					errorCount  ++;
				}
				//fail validation
				if (errorCount > 0) {
					validationResponse += "</ul>";
					$("div.final_rfp").empty().append(validationResponse).fadeIn(750);
				}
				//fail validation
				else {
					//build our RFP using the data collected
					var rfpFinal = "<p>Hello</p>";
					rfpFinal += "<p>My name is "+rfpName+" and I represent "+rfpCompany+"</p>";
					
					//what do you need help with?
					rfpChoicesLength = rfpChoices.length;
					var rfpChoicesString = "";
					
					if (rfpChoicesLength == 1){
						rfpChoicesString = rfpChoices[0] + ".";
					}
					else {
						for (x in rfpChoices) {
							if (x == 0){
								rfpChoicesString += rfpChoices[x];
							}
							else if (x == rfpChoicesLength-1){
								rfpChoicesString +=  " and " + rfpChoices[x] + ". ";
							}
							else {
								rfpChoicesString += ", "+rfpChoices[x];
							}
						}	
					}
					
					if (rfpWebsite == "new") {
						rfpFinal += "<p>We are in need of help with a new website, specifically with regards to "+rfpChoicesString+"</p> ";
					}
					else {
						rfpFinal += "<p>We are in need of help with an existing website, currently online at "+rfpURL+".  Specifically, we need help in the areas of "+rfpChoicesString+"</p> ";
					}
					
					rfpFinal += "<p>"+rfpBigPicture+"</p>";
					rfpFinal += "<p>We would like to have this project completed in "+rfpTimeframe+"";
					rfpFinal += "<p>Our budget is in the range of  "+rfpBudget+", depending on the quality and strength of your proposal</p>";
					rfpFinal += "<p>Thank you for your time and interest in our project. I can be reached by phone at "+rfpPhone+" or via email: "+rfpEmail+".</p>";
					rfpFinal += "<p>Thanks, <br />"+rfpName+"";
					rfpFinal += "<p class='edit_final'><a href='#'>edit these details</a></p>";
						
	
					$("fieldset.rfp_step_2").hide();
					$("fieldset.rfp_step_1").parent().parent().hide();
					$("div.final_rfp").empty().append(rfpFinal).fadeIn(750);
				
				
					//fill hidden form with values
					$(".rfpName_li input").val(rfpName);
					$(".rfpCompany_li input").val(rfpCompany);
					$(".rfpPhone_li input").val(rfpPhone);
					$(".rfpEmail_li input").val(rfpEmail);				
					$(".rfpWebsite_li input").val(rfpURL);  
					$(".rfpAreas_li input").val(rfpChoicesString); 
					$(".rfpDescription_li textarea").val(rfpBigPicture);
					$(".rfpTimeframe_li input").val(rfpTimeframe); 
					$(".rfpBudget_li input").val(rfpBudget); 
					
					$(".rfpBody input.button").show();
					
					//alert (rfpFinal);
					return false; //bleh
					
					
				}
			});
			
			 //RFP Final Step edit details
					$("p.edit_final a").live("click", function(){	
						$("div.final_rfp").empty().hide;
						$(".rfpBody input.button").hide();
						$("div.initial_response").show();
						$("div.standard_form_shadow").show()
						$("fieldset.rfp_step_2").show().parent().parent("div.standard_form_shadow").fadeIn(1000);
						//$("fieldset.rfp_step_2 div").show();
						//$(this).parent().parent().parent("div").hide();
					return false;
					});
			
			//is cookie set? If so, personalise our rfp response
			var rfpClient = $.cookie('gecko_rfpName');
			if (rfpClient != null) {
				$("span.rfp_final_thanks").text(rfpClient);
			}
			
});