// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var active_color = '#000'; // Colour of user provided text
var inactive_color = '#999'; // Colour of default text
var slideIn = 2000; //time in miliseconds
var slideOut = 1000; //time in miliseconds
var slideMove = 4000; //time in miliseconds
var slideHold = 4000; //time in miliseconds

function slides(slide_number)	{
	$("#header_image_"+slide_number).animate({backgroundPosition: '(-100px -160px)'}, {queue:false, duration:slideMove});
	$("#header_image_"+slide_number).fadeIn(slideIn).wait(slideHold).fadeOut(slideOut, 
		function() {
			$("#header_image_"+slide_number).animate({backgroundPosition: '(-20px -20px)'}, {queue:false, duration:1});
			if (slide_number == 7)	{slides(1);}
			else {slides(slide_number+1);}
		}
	);
}


$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};
jQuery(document).ready(function($) {
  if (navigator.platform == 'iPhone') {} else { slides(1);}  
  $(".entry img").css({"display" : "block","margin-top" : "10px","margin-bottom" : "10px","margin-right" : "auto","margin-left" : "auto"});
  $(".pagetitle").fadeIn(3000);
	// $("#twit_toggle").click(function () {
	//     	$("#twitter_div_wrap").slideToggle("slow");
	// 	$(".twit_toggled").toggle();
	//     });
  $('<li class="kens_blog_hidden" style="display:none;"><a href="http://kenhenderson.me">Kens New Blog</a><li>').insertAfter("#top_menu ul li:eq(2)").wait(4000).fadeIn("slow").wait(100).fadeOut("slow").wait(1).fadeIn("slow");
	$(".entry:odd").addClass("entry_alt");
  $("input.default-value, textarea.default-value").css("color", inactive_color);
  var default_values = new Array();                      
  $('input[type="text"], textarea').focus(function() {
      if (this.value == this.defaultValue){
      this.value = '';
          this.style.color = active_color;
  }
  if(this.value != this.defaultValue){
      this.select(); 
      this.style.color = active_color;
  }
  });
  $('input[type="text"], textarea').blur(function() {
      if (this.value == ''){
      this.value = (this.defaultValue ? this.defaultValue : '');
      this.style.color = inactive_color;
  }
  });
  jQuery.each(jQuery.browser, function(i) {
    if($.browser.msie && $.browser.version == 6){
      $('#ie6_flash').wait(2000).slideDown(1000);
    }
    else{}
  });
});

/**
 * jQuery Plugin for backgound Position Animation
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
