$(document).ready(function(){
	$('.breadcrumb li.before ').append('<span>&gt;</span>');
	$('.faqs h3').each(function(i){
		$(this).attr({'id':i++});
	});
});

function GetXmlHttpObject () {
	var xmlHttp = null;
	try { // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	} catch (e) { // Internet Explorer
	  try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (e) {
		try {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {
		  alert("Your browser does not support AJAX!");
		  return false;
	    }
 	  }
	}
	return xmlHttp;
}

function doBlogWidget () {
  xmlHttp = GetXmlHttpObject();
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 && xmlHttp.status==200) {
		var src=document.getElementById("widget_blog");
		src.innerHTML = xmlHttp.responseText;
    } 
  }
  queryString = "includes/widget_blog.php";
  xmlHttp.open("GET",queryString,true);
  xmlHttp.send(null);
}

function doSearch () {
	var src = document.getElementById("search");
	var search = src.search.value;
	if (search == "" || search == "Search") {
		return;
	} else {
		self.location = "search.php?s=" + search;
	}
}

function doForm (qs) {
  xmlHttp = GetXmlHttpObject();
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4 && xmlHttp.status==200) {
  		var src = document.getElementById("formBox");
  		alert(src.innerHTML);
		src.innerHTML = "";
		src.innerHTML = xmlHttp.responseText;
    } 
  }
  queryString = "contactForm.php?" + qs;
  xmlHttp.open("GET",queryString,true);
  xmlHttp.send(null);
}

function doMediaKit() {
	var src = document.getElementById('mediaForm');
	if (src.name.value == "") {
		alert("You must provide your name.");
		src.name.focus();
		return false;
	}
	if (src.email.value == "" && src.phone.value == "") {
		alert("You must provide either your e-mail address or your phone number.");
		src.email.focus();
		return false;
	}
}
	
function doContact() {
	var src = document.getElementById('contactForm');
	if (src.name.value == "") {
		alert("You must provide your name.");
		src.name.focus();
		return false;
	}
	if (src.email.value == "" && src.phone.value == "") {
		alert("You must provide either your e-mail address or your phone number.");
		src.email.focus();
		return false;
	}
}
	
function checkEnter(e){ 
	var characterCode; 

	if(e && e.which){ 
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}

	if(characterCode == 13) { 
		doSearch();
		return false;
	} else {
		return true;
	}
}

function doInfo() {

	if($("#position").val() == '') { return false; }
	if ($("#position").val() == 1) {
		$("#positionList").empty();
		$("#positionList").append('<li class="clearfix"><label for="experience">Years of Design Experience:</label><input type="text" name="experience" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="education">Years of Formal Education in Design:</label><input type="text" name="education" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="tool">Tool of Choice:</label><input type="radio" name="tool" value="ps" />Photoshop<input type="radio" name="tool" value="il" />Illustrator<input type="radio" name="tool" value="ot" />Other (specify): <input type="text" name="othertool" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="familiar">Are you familiar with any of the following:</label><input type="checkbox" name="svn" class="contactInput" />Subversion <input type="checkbox" name="scrum" class="contactInput" />Scrum</li>');
		$("#positionList").append('<li class="clearfix"><label for="portfolio">(Optional) URL examples of your designs:</label><textarea name="portfolio" rows="5" cols="52" class="greyTextarea"></textarea></li>');
		$("#positionList").append('<li class="clearfix"><label for="blogs">(Optional) Favourite Design Blogs:</label><textarea name="blogs" rows="5" cols="52" class="greyTextarea"></textarea></li>');
		$("#positionList").append('<li class="clearfix"><label for="design">(Optional) Upload design example (gif/png/jpg):</label><input type="file" class="contactInput" name="sample" /></li>');
	} else if ($("#position").val() == 2) {
		$("#positionList").empty();
		$("#positionList").append('<li class="clearfix"><label for="experience">Years of Programming Experience:</label><input type="text" name="experience" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="php_experience">Years of PHP Experience:</label><input type="text" name="php_experience" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="mysql_experience">Years of MySQL Experience:</label><input type="text" name="mysql_experience" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="education">Years of Formal Education in Programming:</label><input type="text" name="education" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="tool">IDE of Choice:</label><input type="text" name="tool" value="" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="familiar">Are you familiar with any of the following:</label><input type="checkbox" name="svn" />Subversion <input type="checkbox" name="scrum" />Scrum</li>');
		$("#positionList").append('<li class="clearfix"><label for="portfolio">(Optional) URL examples of your scripts:</label><textarea name="portfolio" rows="5" cols="52" class="greyTextarea"></textarea></li>');
		$("#positionList").append('<li class="clearfix"><label for="design">(Optional) Upload script example (txt file):</label><input type="file" class="contactInput" name="sample" /></li>');
	} else if ($("#position").val() == 3) {
		$("#positionList").empty();
		$("#positionList").append('<li class="clearfix"><label for="experience">Years of CSS/(X)HTML Experience:</label><input type="text" name="experience" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="js_experience">Years of JavaScript Experience:</label><input type="text" name="js_experience" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="flash_experience">Years of Flash Experience:</label><input type="text" name="flash_experience" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="education">Years of Formal Education in Web Development:</label><input type="text" name="education" class="contactInput" /></li>');
		$("#positionList").append('<li class="clearfix"><label for="familiar">Are you familiar with any of the following:</label><input type="checkbox" name="svn" />Subversion <input type="checkbox" name="scrum" />Scrum<input type="checkbox" name="w3c" />W3C Standards<input type="checkbox" name="min" />Minifying</li>');
		$("#positionList").append('<li class="clearfix"><label for="sprites">Have you ever used CSS Sprites before?</label><input type="radio" name="sprites" value="yes" />Yes<input type="radio" name="sprites" value="no" />No</li>');
		$("#positionList").append('<li class="clearfix"><label for="portfolio">(Optional) URL examples of your CSS/JS/HTML work:</label><textarea name="portfolio" rows="5" cols="52" class="greyTextarea"></textarea></li>');
	} else {
		$("#positionList").empty();
		//Do Other Questions
	}
}

function whichPage() {
	var url = window.location.href;
	if (url.match(/designer/)) { alert("Yup"); $("#position").val(1); $("#position").trigger('onchange'); }
	else if (url.match(/programmer/)) { $("#position").val(2); $("#position").trigger('onchange'); }
	else if (url.match(/front_end/)) { $("#position").val(3); $("#position").trigger('onchange'); }
}

/* Copyright (c) 2009 Jordan Kasper
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * Copyright notice and license must remain intact for legal use
 * Requires: jQuery 1.2+
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 * Fore usage documentation and examples, visit:
 *         http://jkdesign.org/captcha/
 * 
 * TODO:
 *   Full testing suite
 * 
 * REVISIONS:
 *   0.1 Initial release
 *   0.2 Changed to use title attribute of image for hash (versus alt)
 *       (We don't want the hash showing as images load)
 *       Fixed simpleCaptcha.php to return properly formatted JSON (fixes bug in jQuery 1.4)
 * 
 */
;(function($) {
  
  $.fn.simpleCaptcha = function(o) {
    var n = this;
    if (n.length < 1) { return n; }
    
    o = (o)?o:{};
    o = auditOptions($.extend({}, $.fn.simpleCaptcha.defaults, o));
    
    var inputId = "simpleCaptcha_"+($.fn.simpleCaptcha.uid++);
    n
      .addClass('simpleCaptcha')
      .html('')  // clear out the container
      .append(
        "<div class='"+o.introClass+"'>"+o.introText+"</div>"+
        "<div class='"+o.imageBoxClass+"'></div>"+
        "<input class='simpleCaptchaInput' id='"+inputId+"' name='"+o.inputName+"' type='hidden' value='' />"
      );
    
    // Call simpleCaptcha.php to get images and current selection
    $.ajax({
      url: o.scriptPath,
      data: { numImages: o.numImages },
      method: 'post',
      dataType: 'json',
      success: function(data, status) {
        if (typeof data.error == 'string') {
          handleError(n, data.error);
          return;
        } else {
          // Add image text to correct place
          n.find('.'+o.textClass).html(data.text);
          
          // Add images to container with click handlers
          var imgBox = n.find('.'+o.imageBoxClass);
          $.each(data.images, function() {
            imgBox.append("<img class='"+o.imageClass+"' src='"+this.file+"' alt='' title='"+this.hash+"' />");
          });
          imgBox.find('img.'+o.imageClass)
            .click(function(e) {
              n.find('img.'+o.imageClass).removeClass('simpleCaptchaSelected');
              var hash = $(this).addClass('simpleCaptchaSelected').attr('title');
              $('#'+inputId).val(hash);
              n.trigger('select.simpleCaptcha', [hash]);
              return false;
            })
            .keyup(function(e) {
              if (e.keyCode == 13 || e.which == 13) {
                $(this).click();
              }
            });
          n.trigger('loaded.simpleCaptcha', [data]);
        }
      },
      error: function(xhr, status) {
        handleError(n, 'There was a serious problem: '+xhr.status);
      }
    });
    
    return n;  // Continue jQuery chain
  };
  
  var handleError = function(n, msg) {
    n.trigger('error.simpleCaptcha', [msg]);
  }
  
  // Defined outside simpleCaptcha to allow for usage during construction
  var auditOptions = function(o) {
    if (typeof o.numImages != 'number' || o.numImages < 1) { o.numImages = $.fn.simpleCaptcha.defaults.numImages; }
    if (typeof o.introText != 'string' || o.introText.length < 1) { o.introText = $.fn.simpleCaptcha.defaults.introText; }
    if (typeof o.inputName != 'string') { o.inputName = $.fn.simpleCaptcha.defaults.inputName; }
    if (typeof o.scriptPath != 'string') { o.scriptPath = $.fn.simpleCaptcha.defaults.scriptPath; }
    if (typeof o.introClass != 'string') { o.introClass = $.fn.simpleCaptcha.defaults.introClass; }
    if (typeof o.textClass != 'string') { o.textClass = $.fn.simpleCaptcha.defaults.textClass; }
    if (typeof o.imageBoxClass != 'string') { o.imageBoxClass = $.fn.simpleCaptcha.defaults.imageBoxClass; }
    if (typeof o.imageClass != 'string') { o.imageClass = $.fn.simpleCaptcha.defaults.imageClass; }
    
    return o;
  }
  
  $.fn.simpleCaptcha.uid = 0;
  
  // options for simpleCaptcha instances...
  $.fn.simpleCaptcha.defaults = {
    numImages: 5,                     // Number How many images to show the user (providing there are at least that many defined in the script file).
    introText: "<p style=\"color: #646464;\">To make sure you are a human, we need you to click on the <span class='captchaText'></span>.</p>",
                                      // String Text to place above captcha images (can contain html). IMPORTANT: You should probably include a tag with the textClass name on it, for example: <span id='captchaText'></span>
    inputName: 'captchaSelection',    // String Name to use for the captcha hidden input, this is what you will need to check on the receiving end of the form submission.
    scriptPath: 'simpleCaptcha.php',  // String Relative path to the script file to use (usually simpleCaptcha.php).
    introClass: 'captchaIntro',       // String Class to use for the captcha introduction text container.
    textClass: 'captchaText',         // String Class to look for to place the text for the correct captcha image.
    imageBoxClass: 'captchaImages',   // String Class to use for the captchas images container.
    imageClass: 'captchaImage'        // String Class to use for each captcha image.
  };

})(jQuery);
