// JavaScript Document


function tickInit() {
	lh.init();

}
lh = {};
lh.init = function() {
	lh.fixPNG();



}

lh.fontReplace = function() {
	Cufon.replace('h1');
}
lh.placeCorners = function() {
	$('#content').append('<span class="rt"><!-- --></span>');
}
lh.fixPNG = function() {
	// $('#logo, #logo a').ifixpng();
}

lh.focusInputs = function() {
	$('#linked input, #linked textarea').focus(function(){$(this).addClass('focus');});
	$('#linked input, #linked textarea').blur(function(){$(this).removeClass('focus');});

}

lh.moreLinks = function() {
	$('#contentcontainer a:contains(">"),#contentcontainer a:contains("&gt;")').each(function(){
			$(this).addClass('more');
			var reg = /&gt;/g;
			this.innerHTML = this.innerHTML.replace(reg,'');

		});

		$('#content2container a:contains(">"),#content2container a:contains("&gt;")').each(function(){
			$(this).addClass('more').click(function(){
				document.location.href = this.href;
			});
			var reg = /&gt;/g;
			this.innerHTML = this.innerHTML.replace(reg,'');
			$('#content2container').hover(function(){
				$(this).addClass('hover');
			},
			function(){
				$(this).removeClass('hover');

			}).click(function(){
				$('a.more:first', this).click();
			});

		});
}

lh.moveHero = function() {
	$('#hero').css('bottom','-480px');
	$('#topmenu, #contentcontainer, #content2container').hide();
	lh.heroMover = setTimeout(function(){
		$('#hero').animate({bottom: '-316px'},500,'easeOutBounce',function(){
			$('#content2container').show();
			lh.heroMover = setTimeout(function(){
				$('#hero').animate({bottom: '-180px'},500,'easeOutBounce',function(){
					lh.heroMover = setTimeout(function(){
						$('#hero').animate({bottom: '10px'},500,'easeOutBounce',function(){
							$('#topmenu, #contentcontainer').show();
							lh.fontReplace();
							$('#logo a').vibrate();
						});
					},300);
				});
			},400);
		});
	},300);

}
$(document).ready(function() {

	if (editmode=='') {
		if (menuid==1 || menuid==57) {
			$('#topmenu, #contentcontainer, #content2container').hide();
			lh.moveHero();
		}
		else {
			lh.fontReplace();
			$('#logo a').vibrate();
		}


		lh.placeCorners();
		lh.moreLinks();
		lh.focusInputs();

	}




});

jQuery.fn.vibrate = function(){



	this.each(function( intI ){
		var jNode = $( this );
		var blnVibrate = false;
		var intLeft = parseInt( jNode.css("left") );
		var intTop = parseInt( jNode.css( "top") );

		var fnUpdatePosition = function(){
			var intCurrentLeft = parseInt(jNode.css("left"));
			var intCurrentTop = parseInt(jNode.css("top"));
			if (blnVibrate){

				if (Math.random() > .5){
					if (intCurrentTop > intTop){
						intCurrentTop = (intTop - 1);
					} else {
						intCurrentTop = (intTop + 1);
					}
				} else {
					if (intCurrentLeft > intLeft){
						intCurrentLeft = (intLeft - 1);
					} else {
						intCurrentLeft = (intLeft + 1);
					}
				}
				// setTimeout(fnUpdatePosition,20);

			} else {
				intCurrentLeft = intLeft;
				intCurrentTop = intTop;
			}

			jNode.css("top",(intCurrentTop + "px"));
			jNode.css("left",(intCurrentLeft + "px"));

		}
		blnVibrate = true;
		fnUpdatePosition();
		document.body.onmousemove = function() {
			fnUpdatePosition();
		}
	});
	return( this );
}

