jQuery(document).ready(function(){
jQuery('p.headshifter').hover(function() {
  jQuery(this).addClass('active');
}, function() {
  jQuery(this).removeClass('active');
});
});


//SIDE NAVIGATION
function initMenus() {
	$('ul#blog_menu ul').hide();
	$.each($('ul#blog_menu'), function(){
		$('#' + this.id + '.expandfirst ul:second').show();
	});
	$.each($('ul#blog_menu'), function(){	$('.open').show(); });
	
	$('ul#blog_menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function() {initMenus();});


$(function(){
    $("a.head").click(function(){
        $("ul#blog_menu li.menu-item").removeClass("active");
        $(this).parent().addClass("active");
        return false;
    }); 
});

/*auto scrolling carousel for homepage*/
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#headshiftSlides').jcarousel({
        auto: 5,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

/*json callback*/

function pipeCallback(obj)  {
 document.write("<div id=ontheweb>");
 var x;
 for (x = 0; x < obj.count ; x++)
 {

  var buildstring = "<p class='item'><a href=" + obj.value.items[x].link + ">" + obj.value.items[x].title + "</a></p>";
  document.write(buildstring);
  buildstring = null;
 }
 document.write("</div>");

}


		/*
		JSTarget function by Roger Johansson, www.456bereastreet.com
		*/
		var JSTarget = {
			init: function(att,val,warning) {
				if (document.getElementById && document.createElement && document.appendChild) {
					var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
					var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
					var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning;
					var oWarning;
					var arrLinks = document.getElementsByTagName('a');
					var oLink;
					var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
					for (var i = 0; i < arrLinks.length; i++) {
						oLink = arrLinks[i];
						if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
							oWarning = document.createElement("em");
							oWarning.appendChild(document.createTextNode(strWarning));
							oLink.appendChild(oWarning);
							oLink.onclick = JSTarget.openWin;
						}
					}
					oWarning = null;
				}
			},
			openWin: function(e) {
				var event = (!e) ? window.event : e;
				if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
				else {
				    var oWin = window.open(this.getAttribute('href'), '_blank');
					if (oWin) {
						if (oWin.focus) oWin.focus();
						return false;
					}
					oWin = null;
					return true;
				}
			},
			/*
			addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
			*/
			addEvent: function(obj, type, fn) {
				if (obj.addEventListener)
					obj.addEventListener(type, fn, false);
				else if (obj.attachEvent) {
					obj["e"+type+fn] = fn;
					obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
					obj.attachEvent("on"+type, obj[type+fn]);
				}
			}
		};

JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external","");});





 (function(jQuery) {
    jQuery.fn.upUpDownDown = function(o){
        var options = jQuery.extend({
                                        watchFor : [38,38,40,40,37,39,37,39,66,65],
                                        callback : function() { }
                                    }, o);
        
        var key_accum = [];
        var match = options.watchFor;
 
        $(document).keyup(function(e){
            len = key_accum.push(e.keyCode ? e.keyCode : e.charCode);
            
            if(len > match.length) key_accum.shift();
            
            if (key_accum.join('-') == match.join('-'))
            {
                key_accum = [];
                if (options.callback)
                {
                    options.callback($(this));
                }
            }
        });
    }
})(jQuery);




$(document).ready(function(){


	$('body').upUpDownDown({
		watchFor: [38,38,40,40,37,39,37,39,66,65],
		callback: function(){
				$('body').append('<div id="cboxOverlay" class="kcode" style="display: block; position:fixed; bottom:-275px; left:-376px;"><img src="http://www.headshift.com/mt-static/themes/hs-theme/images/misc/nabaztag.png" alt="/></div>');
				
				$('.kcode').stop()
				.animate({ bottom : -10 ,left : -10 },1000)
				.animate({ bottom : 0 ,left : 0 },200)
				.animate({ bottom : -10 ,left : -10 },200)
				.animate({ bottom : 0 ,left : 0 },200)
				.animate({ bottom : -10 ,left : -10 },200)
				.animate({ bottom : 0 ,left : 0 },200)
				.animate({ bottom : -10 ,left : -10 },200)
				.animate({ bottom : 0 ,left : 0 },200)
				.animate({  bottom : -275 ,left : -376},600, 
																													  
					  function(){
						  
							$(this).remove();
						  
						  });
		}
	});
});       


// bigTarget.js - A jQuery Plugin
// Version 1.0.1
// Written by Leevi Graham - Technical Director - Newism Web Design & Development
// http://newism.com.au
// Notes: Tooltip code from fitted.js - http://www.trovster.com/lab/plugins/fitted/

// create closure
(function($) {
	// plugin definition
	$.fn.bigTarget = function(options) {
		debug(this);
		// build main options before element iteration
		var opts = $.extend({}, $.fn.bigTarget.defaults, options);
		// iterate and reformat each matched element
		return this.each(function() {
			// set the anchor attributes
			var $a = $(this);
			var href = $a.attr('href');
			var title = $a.attr('title');
			// build element specific options
			var o = $.meta ? $.extend({}, opts, $a.data()) : opts;
			// update element styles
			$a.parents(o.clickZone)
				.hover(function() {
					$h = $(this);
					$h.addClass(o.hoverClass);
					if(typeof o.title != 'undefined' && o.title === true && title != '') {
						$h.attr('title',title);
					}
				}, function() {
					
					$h.removeClass(o.hoverClass);
					if(typeof o.title != 'undefined' && o.title === true && title != '') {
						$h.removeAttr('title');
					}
				})
				// click
				.click(function() {
					if(getSelectedText() == "")
					{
						if($a.is('[rel*=external]')){
							window.open(href);
							return false;
						}
						else {
							//$a.click(); $a.trigger('click');
							window.location = href;
						}
					}
				});
		});
	};
	// private function for debugging
	function debug($obj) {
		if (window.console && window.console.log)
		window.console.log('bigTarget selection count: ' + $obj.size());
	};
	// get selected text
	function getSelectedText(){
		if(window.getSelection){
			return window.getSelection().toString();
		}
		else if(document.getSelection){
			return document.getSelection();
		}
		else if(document.selection){
			return document.selection.createRange().text;
		}
	};
	// plugin defaults
	$.fn.bigTarget.defaults = {
		hoverClass	: 'hover',
		clickZone	: 'li:eq(0)',
		title		: true
	};
// end of closure
})(jQuery);  

$(document).ready(function(){
  $("div.page-content p.headshifter a").bigTarget({
    hoverClass: 'over', // CSS class applied to the click zone onHover
    clickZone : 'p:eq(0)' // jQuery parent selector
  });
});    
$(document).ready(function(){
  $("div.page-content p.headshifter").css({ 
	'cursor' : 'pointer'   
  });
});       