//------------------------------------
//	BOAT.JS
//	Author: 	Will Blackmore
//	Requires:	jquery 1.4.3
//	Version:	2
//------------------------------------

////////////////////////
// Global variables

var mouseBan = false;
var firstLoad = true;


////////////////////////
// Cufon

function loadCufon(target){
	if( target ){
		Cufon.replace(target);
	}
}

Cufon.replace('h1,.intro', {
	textShadow: '1px 1px #FFF'
});

Cufon.replace('#info h3');


////////////////////////
// iFrame functions

function doneLoading(height){
	console.log('Getting rid of loader, height is: ' + height );
	
	if( height != false ){
		$('#content_wrapper iframe').animate({height:height},600,'easeInOutExpo');
		$('#content_wrapper').animate({height:height + 2, marginTop: 0 - Math.round( height / 2 ) },600,'easeInOutExpo');
	}
	
	$('#content_loading').stop([]).fadeOut(300,function(){
		$(this).remove();
	});
}

function makeGallery(images){
	
	$('<div/>',{
		'id': 'cbox_gallery',
		'html': images,
		'css': {
			'display':'none'
		}
	}).appendTo('body');
	
	$('#cbox_gallery a').colorbox({
		'transition': 'elastic',
		'onComplete': function(){
			Cufon.replace('#cboxTitle');
		},
		'onClosed': function(){
			$('#cbox_gallery').remove();
		}
	});
	
	$('#cbox_gallery a.initial').click();
	
}

function videoClick(btn){
	$(btn).click();
}


$(function(){
//BEGIN jQuery
	
	///////////////////////////
	// SUB NAV

	$('header ul li div').css({opacity:0});

	$('header ul li.explore > a, header ul li.experience > a').click(function(){
		return false;
	});

	$('header ul li.explore, header ul li.experience, header ul li.facilities').mouseover(function(){
		$(this).addClass('active hover').find('div').show().stop([]).animate({opacity:1});
	});

	$('header ul li.explore, header ul li.experience, header ul li.facilities').mouseleave(function(){
		$li = $(this);
		$li.removeClass('hover');

		timer = setTimeout(hideSub,200);
	});
	
	function hideSub(){
		$('header ul li.active').each(function(){
			if( $(this).hasClass('hover') == false ){
				$(this).removeClass('active').find('div').stop([]).animate({opacity:0},function(){
					$(this).hide();
				});
			}
		});
	}
	
	
	////////////////////////
	// SLIDESHOW
	
	$('#slideshow').ready(function(){
		var total = 5;
		var current = 1;
		var pause = 4;
		var $s = $('#slideshow');
		
		function slideshow(){
		
			$s.find('img').fadeOut(600,function(){
				$(this).remove();
			});
			$('<img/>').load(function(){
				$(this).fadeIn(600,function(){
					setTimeout(slideshow, 3200);
				});
			}).attr('src','/content/images/welcome/slide_' + current + '.jpg').appendTo($s).hide();
			
			current++;
			
			if( current > total ) current = 1;
			
		}
		
		slideshow();
		
	});
	
	
	///////////////////////////
	// VIDEOS & IMAGES
	
	function loadColorbox(){
		$('.photo a, #gallery a, #info_content a.photo, .images a').colorbox({
			transition:	'elastic',
			'maxWidth': '80%',
			'maxHeight': '80%',
			onComplete: function(){
				Cufon.replace('#cboxTitle');
			}
		});
		
		$('.video').click(function(){
			$.colorbox({
				title:		$(this).attr('title'),
				html:		'<iframe src="' + $(this).attr('href') + '?title=0&amp;byline=0&amp;portrait=0" width="800" height="450" frameborder="0"></iframe>',
				innerWidth:	800,
				innerHeight: 450,
				transition:	'elastic',
				onComplete: function(){
					Cufon.replace('#cboxTitle');
				}
			});
			return false;
		});		
	}
	
	loadColorbox();

	
	////////////////////////
	// BOAT
	
	function boat(){
	
		///////////////////////
		// Variables
		
		var $win = $(window);
		var $boat = $('#boat');
		var $small = $('#small');
		var $large = $('#large');
		var $load = $('#boat_loading');
		var $content = $('#content_wrapper');
		var state = new Array({'zoom':'small', 'skin':'exterior', 'page':'/'});
		var method = 'automatic';
		var contentOpen = false;
		var infoOpen = false;
		var welcome = true;
		
		
		////////////////////////
		// On Load
		
		$win.load(function(){

			// Have we got a hash in the url?
			if( location.hash.substr(1) == '' ){
			
				console.log('Fresh site');
				
				firstLoad = false;
				welcome = true;
			
				state.page = 'home';
				state.skin = 'exterior';
				state.zoom = 'small';
				
				$small.center();
				
				$('#welcome').fadeIn();
				
			}else{
			
				console.log('Load a specific page');
				
				state.page = location.hash.substr(1);
				
				welcome = false;
				
				if( state.page.indexOf('diary') > 0 || state.page == '/contact.php' ){

					state.skin = 'exterior';
					state.zoom = 'small';
					location.hash = state.page;
					
					showPage(state.page,true);
					
					$small.center().show();
					
				}else{
				
					state.zoom = 'large';
				
					var $pin = $large.find('a[href=' + state.page + ']');
					
					$pin.addClass('active');
					
					if( $pin.hasClass('interior') ){
						$('#boat_type').addClass('on');
						state.skin = 'interior';
					}else{
						state.skin = 'exterior';
					}
					
					$boat.attr('class','').addClass(state.skin);
					$large.show().css({top: $pin.getY(), left:$pin.getX()});
					
					$('#boat_zoom').addClass('on');
					
					if( $pin.hasClass('nopage') ){
						showInfo();
					}else{
						showContent();
					}
					
				}
				
			}
			
			setPageDims();
			
			updateNav();
			
		});
		
		// Preload the image and then fade in
		$('#begin, li.explore a.top').click(function(){
			loadImg(getUrl(),function(){
				$('#welcome').fadeOut();
				$('#boat_controls').fadeIn();
				$small.fadeIn();
				showInfo();
				welcome = false;
			});
			return false;
		});
		
		
		////////////////////////
		// On Resize
		
		$win.resize(function(){
			if( state.zoom == 'large' ){
				$large.center({animate:true});
			}else{
				$small.center({animate:true});
			}
			
			setPageDims();
			
		});
		
		function setPageDims(){
			if( $(window).height() < 800 ){
			
				var h = 0 - ( 800 - $(window).height() );
				
				$('#welcome,#info').addClass('static');
				$('#boat').css({bottom: h });
				$('#boat_controls').css({ marginBottom: h });
				$('footer').css({ marginBottom: h-120 });
			}else{
				$('#welcome,#info').removeClass('static');
				$('footer,#boat_controls').css({marginBottom: 0});
				$('#boat').css({bottom: 0 });
			}
		}
		
		
		////////////////////////
		// Update the nav
		
		function updateNav(){

			console.log('Updating nav');

			if( state.page == '/the-crew.php' ){
				setNav('.crew');
			}else if( state.page == '/outdoor-activities.php' || state.page == '/indoor-activities.php' || state.page == '/specifications.php' ){
				setNav('.facilities');
			}else if( state.page == '/diary/' || state.page.indexOf('diary') > 0 ){
				setNav('.diary');
			}else if( state.page == '/contact.php' ){
				setNav('.contact');
			}else if( state.page == '' || state.page == 'home' ){
				$('header .on').removeClass('on');
			}else{
				setNav('.explore');
			}
		}
		
		// Set the nav
		
		function setNav(btn){
			$('header ' + btn + ' a').addClass('on').parent('li').siblings('li').children('a').removeClass('on');
		}
		
		
		////////////////////////
		// Controls
		
		$('#boat_controls a').click(function(){
		
			if( mouseBan == false ){

				mouseBan = true;
				
				var $bttn = $(this);
				var action = $bttn.attr('id');
				
				if( action == 'boat_type' ){
					
					state.skin == 'interior' ? state.skin = 'exterior' : state.skin = 'interior';
					
					type(function(){
						mouseBan = false;
					});
					
				}else if( action == 'boat_zoom' ){
					
					setNav('.explore');
					
					method = 'manual';
					
					state.zoom == 'small' ? state.zoom = 'large' : state.zoom = 'small';
					
					if( state.zoom == 'small' ){
						$large.center({
							animate:true,
							callback:function(){
								zoom(function(){
									mouseBan = false;
								});
							}
						});
					}else{
						zoom(function(){
							mouseBan = false;
						});
					}
					
				}else if( action == 'boat_reset' ){
				
					boatReset();
					
				}
			
			}
			
			return false;
		
		});
		
		
		////////////////////////
		// Zoom in and out
		
		function zoom(callback){

			console.log('Zooming');

			fadeInfo();
			closeContent();
		
			loadImg(getUrl(),function(){

				if( state.zoom == 'large' ){
					
					if( firstLoad == true ){
						$large.show();
						if( callback ) callback.call(this);
					}else{
						$large.center().fadeIn(600);
						$small.fadeOut(600,function(){
							if( callback ) callback.call(this);
						});
					}
					
					$('#boat_zoom').addClass('on');
					
				}else{

					$large.fadeOut(600);
					$small.center().fadeIn(600,function(){
						if( callback ) callback.call(this);
					});
					
					$('#boat_zoom').removeClass('on');
					
				}
				
			});
		}
		
		
		////////////////////////
		// Interior to exterior
		
		function type(callback){
		
			console.log('Switching skin');
			
			loadImg(getUrl(),function(){
				
				var $c = null;
				
				state.zoom == 'large' ? $c = $large : $c = $small;
				
				state.skin == 'interior' ? $('#boat_type').addClass('on') : $('#boat_type').removeClass('on');
				
				$('<div/>',{
					'class':'image',
					'css': {
						top: $c.position().top,
						left: $c.position().left,
						width: $c.width(),
						height: $c.height(),
						backgroundImage: 'url(' + getUrl() + ')',
						zIndex: 130
					}
				}).appendTo($boat).fadeIn(function(){
				
					state.skin == 'interior' ? $boat.addClass('interior').removeClass('exterior') : $boat.addClass('exterior').removeClass('interior');
					$(this).fadeOut(function(){
						$(this).remove();
						if( callback ) callback.call(this);
					});

				});
				
			});

		}
		
		
		///////////////////////
		// Preload images

		function loadImg(src,callback){
			
			var loaded = false;
			
			// Give it half a second to load a cached image if it has one
			var loadTimer = {};
			loadTimer = $.timer(500,function(){
				$.clearTimer(loadTimer);
				if( loaded == false ){
					$load.fadeIn();
				}
			});
			
			//if( !$('html').hasClass('ie') ){
			
				$('<img />').load(function(){
					console.log('Done loading image');
					loaded = true;
					$load.fadeOut();
					if( callback ) callback.call(this);
	
				}).attr('src',src);
			
			//}else{
			
				/*console.log('Done loading image');
				loaded = true;
				$load.fadeOut();
				if( callback ) callback.call(this);*/
			
			//}

		}
		
		
		////////////////////////
		// Generate img url
		
		function getUrl(){
			console.log('Generated url: ' + '/assets/images/boat/' + state.zoom + '_' + state.skin + '.jpg');
			return '/assets/images/boat/' + state.zoom + '_' + state.skin + '.jpg';
		}
		
		
		////////////////////////
		// Dragging
		
		var drag = false;
		var mouseY = '';
		var mouseX = '';
		var pos = '';
		
		$boat.mousedown(function(e){

			if( state.zoom == 'large' && mouseBan == false ){

				drag = true;

				mouseY = e.pageY;
				mouseX = e.pageX;
				
				pos = $large.position();
				
				$('html:not(.ie) body').css({cursor:'move'});
				
				fadeInfo();
								
			}
			
			e.preventDefault();
			
		});
		
		////////////////////////////////
		// Mouse move
		
		$(document).mousemove(function(e){
		
			if( drag == true ){

				method = 'manual';

				$large.goto({
					x: e.pageX - mouseX + pos.left,
					y: e.pageY - mouseY + pos.top
				});
				
			}

		});
		
		////////////////////////
		// Mouse up
		
		$(document).mouseup(function(){
		
			drag = false;
			
			$('body').removeAttr('style');
			
			pos = $large.position();
			
			var maxX = $win.width() - 600;
			var maxY = $win.height() - 400;
			var minX = 0 - $large.width() + 600;
			var minY = 0 - $large.height() + 600;
			
			var x = pos.left;
			var y = pos.top;
			
			if( pos.left > maxX ){
				x = maxX;
			}
			
			if( pos.top > maxY ){
				y = maxY;
			}
			
			if( pos.left < minX ){
				x = minX;
			}
			
			if( pos.top < minY ){
				y = minY;
			}
			
			if( x != pos.left || y != pos.top ){
				$large.goto({
					x: x,
					y: y,
					animate: true
				});
			}
			
		});
		
		
		////////////////////////
		// Boat reset
		
		function boatReset(welcome){

			console.log('Reseting boat');
			
			var callback = function(){
				mouseBan = false;
				
				if( welcome ){
					state.page = '/welcome.php';
					showContent();
				}
				
				updateNav();
			}
		
			if( state.page != 'none' ){
				state.page = 'none';
				$('.pins a').removeClass('active');
				closeContent();
			}
			
			location.hash = '';
		
			if( state.zoom == 'large' && state.skin == 'interior' ){

				state.zoom = 'small';
				state.skin = 'exterior';

				zoom(function(){
					type(callback);
				});
				
			}else if( state.zoom == 'large' && state.skin == 'exterior' ){
			
				state.zoom = 'small';

				zoom(callback);

			}else if( state.zoom == 'small' && state.skin == 'interior' ){
			
				state.skin = 'exterior';
			
				type(callback);
				
			}else{
			
				state.zoom = 'small';
				state.skin = 'exterior';
			
				callback();
				
			}

			if( !welcome ) state.page = 'none';

			$('#boat_controls a').removeClass('on');
			
			fadeInfo();
			
		}
		
		
		////////////////////////
		// Click the pins!
		
		$('#boat .pins a').click(function(e){

			if( mouseBan == false && !$(this).hasClass('active') ){
	
				console.log('A pin was clicked');
				
				mouseBan = true;

				state.page = $(this).attr('href');
				location.hash = state.page;
				
				$('#tooltip').fadeOut(100,function(){
					$(this).remove();
				});
				
				var $pin = $large.find('a[href=' + state.page + ']');
				
				$pin.addClass('active loading').siblings().removeClass('active');
	
				var callback = function(){};
				
				if( !$pin.hasClass('nopage') ){
					callback = function(){
						showContent();
						$pin.removeClass('loading');
					}
				}else{
					callback = function(){
						showInfo();
					}
				}
	
				if( state.zoom == 'small' ){

					state.zoom = 'large';
					zoom(function(){
						$large.goto({
							x: $pin.getX(),
							y: $pin.getY(),
							animate: true,
							callback: callback
						});
					});
					
				}else{

					$large.goto({
						x: $pin.getX(),
						y: $pin.getY(),
						animate: true,
						callback: callback
					});
					
				}
				
				fadeInfo();
				closeContent();
			
				updateNav();
				
			}else if( $(this).hasClass('active') ){
			
				$(this).removeClass('active');
				
			}
			
			e.preventDefault();
			
		});
		
		
		////////////////////////
		// Click the nav
		
		$('header nav li a:not(.video):not(.top)').click(function(e){
			
			if( welcome == true ){

				state.page = $(this).attr('href');
				
				welcome = false;
				
				if( state.page.indexOf('diary') > 0 || state.page == '/contact.php' ){

					state.skin = 'exterior';
					state.zoom = 'small';
					location.hash = state.page;
					
					showPage(state.page,true);
					
					loadImg(getUrl(),function(){
						$small.center().fadeIn();
					});
					
				}else{
				
					var $pin = $('#large .pins a[href=' + $(this).attr('href') + ']');
				
					state.zoom = 'large';
					
					$pin.addClass('active');
					
					if( $pin.hasClass('interior') ){
						$('#boat_type').addClass('on');
						state.skin = 'interior';
					}else{
						state.skin = 'exterior';
					}
					
					location.hash = state.page;
					
					$boat.attr('class','').addClass(state.skin);
					
					$large.show().css({opacity:0, top: $pin.getY(), left:$pin.getX()});
					
					loadImg(getUrl(),function(){
						$large.animate({opacity:1});
						updateNav();
					});
					
					$('#boat_zoom').addClass('on');
					
					showContent();
					
				}

				$('#welcome').fadeOut();
				
				welcome = false;
				
			}else{
			
				var $pin = $('#' + state.zoom + ' .pins a[href=' + $(this).attr('href') + ']');
				
				if( !mouseBan && state.page != $(this).attr('href') ){
	
					console.log('Clicked the navigation');
					
					mouseBan = true;
					method = 'automatic';
					
					if( $(this).parent('li').hasClass('diary') || $(this).parent('li').hasClass('contact') || $(this).parent('li').hasClass('crew') ){

						showPage($(this).attr('href'));
						
					}else{

						if( ( $pin.hasClass('interior') && state.skin == 'exterior' ) || ( $pin.hasClass('exterior') && state.skin == 'interior' ) ){
							state.skin == 'interior' ? state.skin = 'exterior' : state.skin = 'interior';
							
							type(function(){
								mouseBan = false;
								$pin.click();
							});
							
						}else{
							mouseBan = false;
							$pin.click();
						}
					
					}
				}
			
			}
			
			e.preventDefault();
		});
		
		$('#logo').click(function(e){
			if( welcome != true ){
				welcome = true;
				$('#welcome').fadeIn();
				closeContent();
				
				if( state.zoom == 'large' ){
					$large.fadeOut();
				}else{
					$small.fadeOut();
				}
				
				state.page = '';
				state.zoom = 'small';
				
				$('#boat_controls').fadeOut();
				location.hash = '';
				updateNav();
				
				fadeInfo();
			}
			e.preventDefault();
		});
		
		function showPage(url,deep){
		
			if( !deep ){
				state.page = url;
				location.hash = state.page;
			}
			
			closeContent(function(){
				showContent();
				updateNav();
				mouseBan = false;
			});
			
		}
		
		
		////////////////////////
		// Content box
		
		function showContent(callback){

			var $iframe = $('#content_wrapper iframe');
			var $content = $('#content_wrapper');
			var h = Math.round( $win.height() / 2 ) + 200;
			
			contentOpen = true;
			
			console.log('Loading content: ' + state.page );
			
			$('#boat_controls').fadeOut();
						
			if( $content.size() == 0 ){
				
				$content = $('<div/>',{
					'id': 'content_wrapper',
					'html': '<div id="content"></div><div id="content_loading"><p>Loading</p></div>',
					'css': {
						'height': h,
						'margin-top': Math.round( 30 - ( h / 2 ) )
					}
				}).appendTo('body');

				$iframe = $('<iframe>',{
					'frameborder': 0,
					'scrolling': 'no',
					'css': {
						'display': 'block',
						'width': '100%',
						'height': h - 2,
						'border': 0
					}
				}).appendTo($('#content'));

				$('<a/>',{
					'href': '#',
					'id': 'content_close',
					'title': 'Close this panel',
					'html': 'Close',
					'click': function(){
						state.page = 'none';
						location.hash = '';
						closeContent();
						$('.pins a.active').removeClass('active');
						return false;
					}
				}).appendTo($content);

				if( firstLoad == true ){
					$content.show();
					$iframe.attr('src', state.page);
					firstLoad = false;
					if( callback ) callback.call(this);
					mouseBan = false;
				}else{
					$content.fadeIn(function(){
						$iframe.attr('src', state.page);
						if( callback ) callback.call(this);
						mouseBan = false;
					});
				}
				
			}else{

				$('<div/>',{
					'id':'content_loading',
					'html':'<p>Loading</p>'
				}).appendTo($content).hide().fadeIn(function(){
					$iframe.attr('src',state.page);
				});
				
				mouseBan = false;
				
			}
			
		}
		
		function closeContent(callback){
		
			if( contentOpen == true ){
				
				contentOpen = false;
				
				console.log('Closing content, method is ' + method);
			
				if( $('#content_wrapper').hasClass('welcome') && state.zoom == 'small' ){
					$small.center({animate:true});
				}
			
				$('#content_wrapper').fadeOut(function(){
				
					autoClose();
					
					$(this).remove();
					
					if( welcome != true ) $('#boat_controls').delay(1400).fadeIn();
					
					if( callback ) callback.call(this);
					
				});
				
				$('#tooltip').fadeOut(100,function(){
					$(this).remove();
				});
			}else{
			
				if( callback ) callback.call(this);
			
			}
		}
		
		
		////////////////////////
		// Info panel
		
		var firstInfo = true;
		
		function showInfo(){
			if( firstInfo == true ){
				console.log('Showing info panel');
				
				infoOpen = true;
				
				$('#info').fadeIn(200);
			}
		}
		
		function fadeInfo(){
			
			if( infoOpen == true ){
			
				infoOpen = false;
				firstInfo = false;
				
				$('#info').fadeOut(200);
			
			}
		}
		
		$('#info .close').click(function(){
			fadeInfo();
			return false;
		});
		
		function autoClose(){
		
			console.log('autoclose ' + state.page);
			updateNav();
			
			if( method == 'automatic' && state.zoom == 'large' && !$('#content_wrapper').hasClass('welcome') && state.page == 'none' ){
				state.zoom = 'small';
				zoom();
			}
		}
		
	}
	
	boat();

	
	///////////////////////////
	// TOOLTIPS
	
	$('.pins a, .tooltip').live('mouseenter',function(){
	
		if( $(this).hasClass('active') ) return false;
	
		$('#tooltip').remove();
	
		pos = $(this).offset();
		x = pos.left;
		y = pos.top;
		
		txt = $(this).attr('title');
		if( txt == '' ) txt = $(this).text();
		if( !$(this).hasClass('tooltip') ) txt += '<em>Click for more info</em>';
		
		$('<div/>',{
			id:		'tooltip',
			html:	'<div class="content">' + txt + '</div>'
		}).appendTo('body');
		
		$t = $('#tooltip');
		w = '-' + ( ( $t.width() / 2 ) - ( $(this).width() / 2 ) ) + 'px';
		h = $t.height() + 5;
		
		$t.css({top: y - ( h + 5 ), left: x, marginLeft: w, opacity:0 }).animate({opacity:1, top:y - h},200,'easeInOutExpo');
		
	});
	
	$('.pins a, .tooltip').live('mouseleave',function(){
		$('#tooltip').fadeOut(100,function(){
			$(this).remove();
		});
	});

//END jQuery
});

////////////////////////
// Center boats

(function($){

	$.fn.getX = function(options) {
	
		var $this = $(this);
		return Math.round( $('#large').position().left + ( ( $(window).width() / 2 ) - $this.offset().left ) );
		
	}
	
	$.fn.getY = function(options) {
	
		var $this = $(this);
		return Math.round( $('#large').position().top + ( ( $(window).height() / 2 ) - $this.offset().top ) );
		
	}

})(jQuery);


////////////////////////
// Center boats

(function($){

	$.fn.center = function(options) {
		
		var defaults = {
			animate: false,
			callback: function(){}
		},
		o = $.extend({}, defaults, options);
		
		return this.each(function(){
	
			$this = $(this);
			
			console.log('Centering ' + $this.attr('id') );

			var x = Math.round( ( $(window).width() - $this.width() ) / 2 );
			var y = Math.round( ( $(window).height() - $this.height() ) / 2 );

			$this.goto({
				x: x,
				y: y,
				animate: o.animate,
				callback: o.callback
			});
		
		});
	}

})(jQuery);


////////////////////////
// Move boat about

(function($){

	$.fn.goto = function(options) {

		var defaults = {
			x: 0,
			y: 0,
			animate: false,
			callback: function(){}
		},
		o = $.extend({}, defaults, options);
		
		return this.each(function(){
	
			$this = $(this);
			
			// Do we actually need to center?
			if( o.x == $this.position().left && o.y == $this.position().top ){
			
				o.callback.call(this);
			
			}else{
				
				if( o.animate == true && firstLoad == false ){
					
					console.log('New X: ' + o.x + ' Old X: ' + $this.position().left + ' New Y: ' + o.y + ' Old Y: ' + $this.position().top );
				
					$this.stop([]).animate({left: o.x, top: o.y},1000,'easeInOutExpo',function(){
						o.callback.call(this);
					});
				}else{
					$this.stop([]).css({left: o.x, top: o.y});
					o.callback.call(this);
				}
				
			}
		
		});
	}

})(jQuery);


////////////////////////
// Easing

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});


////////////////////////////////
// Timers

jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

////////////////////////
// Console log fix

if(typeof(console) === 'undefined') {
	var console = {}
	console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
}
