/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

/*
	* Konami-JS ~ 
	* Code: http://konami-js.googlecode.com/
	* Examples: http://www.snaptortoise.com/konami-js
	* Copyright (c) 2009 George Mandis (georgemandis.com, snaptortoise.com)
	* Version: 1.3.3 (4/16/2011)
*/
var Konami=function(){var konami={addEvent:function(obj,type,fn,ref_obj)
{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,ref_obj);}
obj.attachEvent("on"+type,obj[type+fn]);}},input:"",pattern:"38384040373937396665",load:function(link){this.addEvent(document,"keydown",function(e,ref_obj){if(ref_obj)konami=ref_obj;konami.input+=e?e.keyCode:event.keyCode;if(konami.input.length>konami.pattern.length)konami.input=konami.input.substr((konami.input.length-konami.pattern.length));if(konami.input==konami.pattern){konami.code(link);konami.input="";return;}},this);this.iphone.load(link)},code:function(link){window.location=link},iphone:{start_x:0,start_y:0,stop_x:0,stop_y:0,tap:false,capture:false,orig_keys:"",keys:["UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT","TAP","TAP","TAP"],code:function(link){konami.code(link);},load:function(link){this.orig_keys=this.keys;konami.addEvent(document,"touchmove",function(e){if(e.touches.length==1&&konami.iphone.capture==true){var touch=e.touches[0];konami.iphone.stop_x=touch.pageX;konami.iphone.stop_y=touch.pageY;konami.iphone.tap=false;konami.iphone.capture=false;konami.iphone.check_direction();}});konami.addEvent(document,"touchend",function(evt){if(konami.iphone.tap==true)konami.iphone.check_direction(link);},false);konami.addEvent(document,"touchstart",function(evt){konami.iphone.start_x=evt.changedTouches[0].pageX
konami.iphone.start_y=evt.changedTouches[0].pageY
konami.iphone.tap=true
konami.iphone.capture=true});},check_direction:function(link){x_magnitude=Math.abs(this.start_x-this.stop_x)
y_magnitude=Math.abs(this.start_y-this.stop_y)
x=((this.start_x-this.stop_x)<0)?"RIGHT":"LEFT";y=((this.start_y-this.stop_y)<0)?"DOWN":"UP";result=(x_magnitude>y_magnitude)?x:y;result=(this.tap==true)?"TAP":result;if(result==this.keys[0])this.keys=this.keys.slice(1,this.keys.length)
if(this.keys.length==0){this.keys=this.orig_keys;this.code(link)}}}}
return konami;}

$(function() {
	
	// Slide jQuery
	$('#open').click(function(){
		$('#panel').slideDown('slow');
	});	
	$('#close').click(function(){
		$('#panel').slideUp('slow');	
	});		
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$('#toggle').find('a').click(function () {
		$('#toggle').find('a').toggle();
	});
	
	// Superfish Navigation
	$('ul.sf-menu').superfish({
		autoArrows:  false
	})
	
	// Make Links External Blank
	$('a.external').prop('target', '_blank');
	
	// Colorbox modal window
	$('a.colorbox').colorbox({maxWidth:'100%', maxHeight:'100%'});
	$('a.token').colorbox({iframe:true, innerWidth:700, innerHeight:480});
	$('a.faqpopup').colorbox({iframe:true, innerWidth:700, innerHeight:480});
	
	// Media Marquee
	$('#featured').tabs({fx:{opacity: 'toggle'}}).tabs('rotate', 6000, true);
	
	var config = {
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		interval: 900, // number = milliseconds for onMouseOver polling interval
		over: stopRotation, // function = onMouseOver callback (REQUIRED)
		timeout: 900, // number = milliseconds delay before onMouseOut
		out: stopRotation // function = onMouseOut callback (REQUIRED)
	};
	
	function stopRotation() {
		$('#featured').tabs('rotate',0,true);
	}
	$('#featured').find('.ui-tabs-panel').hoverIntent(config);
	
	$('#featured').find('a').hoverIntent(
		function() {$('#featured').tabs('rotate',0,false);},	
		function() {$('#featured').tabs('rotate',0,false);}
	);
	
	$('#video-marquee').hover(
		function() {$('#featured').tabs('rotate',0,false);},	
		function() {$('#featured').tabs('rotate',0,false);}
	);
		
	$('#featured').find('a').click(
		function() {$('#featured').tabs('rotate',0,false);}
	);

	konami = new Konami()
	konami.load('http://bit.ly/kcW0MO'); 		 	
});

// FB init
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
