if (typeof console == 'undefined') {
	console=function(){}
	console.log=function(txt){}
	console.warn=function(txt){}
} else console.log('Console Active');
spd = 300;
$.fn.showNav = function(){
	return $(this).show().bind('mouseleave',function(e){
				$(this).hideNav();
				console.log('Left '+$(this).attr('id'));
			});
		//.animate({height:"show",opacity:"show"},spd,function(){
		//$(this)
		
	//});
}
$.fn.hideNav = function(){
	return $(this).hide().unbind('mouseleave');/*.animate({height:"hide",opacity:"hide"},spd,function(){
		$(this).unbind('mouseleave');
	});*/
}
/*function rotateTicker() {
	if ($('#ticker .panel:visible').next('.panel').length) nextTicker = $('#ticker .panel:visible').next('.panel');
	else nextTicker = $('#ticker').parent().find('.panel:first');
	$('#ticker .panel:visible').animate({top:-$('#ticker .panel:visible').outerHeight()+'px'},'slow',function(){$(this).hide()});
	nextTicker.css({top:nextTicker.outerHeight()+'px'}).show().animate({top:'0'},'slow');
	$('#ticker').animate({height:nextTicker.outerHeight()+'px'},'slow');
}*/
function rotateTicker() {
	$('#ticker .belt').animate({left:-$('#ticker .panel:first').outerWidth()+'px'},{duration:6000,complete:function(){
		$(this).css({left:'0px'});
		$(this).append($(this).find('.panel:first').remove());
		rotateTicker();
	}});
}
$(function(){
	console.log('url - '+window.location.href);
	/*$('a').each(function(){
		href = $(this).attr('href');
		if (window.location.href.match(/\/test\//)) {
		if (typeof href != 'undefined' && href.substr(0,1)=='/') {
			href.replace('.html','');
			if (href=='/') {
				href = '/new_index.php';
			} else {
				if (href.substr(0,7)!='/assets')
					href = '/test'+href;
				if (!href.substr(-5,0).indexOf('.')!==false)
					href = href+'.html';
			}
			$(this).attr('href',href);
		}}
	});*/
	$('.anchorclass').mouseover(function(e){
		e.preventDefault();
		$('#info').html('over '+$(this).attr('rel'));
		$('.submenu:visible').hideNav();
		$('#submenu'+$(this).attr('rel')).showNav();
	}).mouseout(function(e){
		e.preventDefault();
		$('#info').html(e.pageY+'>'+$(this).offset().top+'+'+$(this).height()+'+11 = '+(e.pageY>$(this).offset().top+$(this).height()+11));
		if(e.pageY>$(this).offset().top+$(this).height()+$('#submenu'+$(this).attr('rel')).height()) {
			$('#submenu'+$(this).attr('rel')).hideNav();
			console.log(e.pageY+'>'+$(this).offset().top+'+'+$(this).height()+'+'+$('#submenu'+$(this).attr('rel')).height())
		}
	}).each(function(){
		bottom = $(this).offset().top+$(this).height()+10;
		left = $(this).offset().left-15;
		console.log(bottom+' - '+left);
		console.log($(this).next().height());
		$(this).next().css({display:'none',left:left+'px',top:bottom+'px',height:$(this).next().height()+'px',position:'absolute'})
		submenu = $(this).next().detach();
		console.log(submenu);
		$('body').append(submenu);
	});
	$('.submenu').mousemove(function(e){ e.stopPropagation(); }).mouseover(function(e){ e.stopPropagation(); });
	$('.sidemenu .panel').css({cursor:'pointer'}).click(function(e){
		console.log($(this).parent().find('ul:hidden').length);
		if (!$(this).parent().find('ul:hidden').length) {
			e.preventDefault();
			window.location.href = $(this).find('a:first').attr('href');
		}
	});
	$('form[name=data_form]').submit(function(){
		var send = true;
		$(this).find('input[name^=*]').each(function(){
			if ($(this).val()==''||$(this).val()==$(this).attr('rel')) {
				alert('The '+$(this).attr('name')+' field has not been filled in!');
				send = false;
			}
		});
		return send;
	});
	$('form[name=data_form] input').focus(function(e){
		if ($(this).val()==$(this).attr('rel')) $(this).val('');
	}).blur(function(){
		if ($(this).val()=='') $(this).val($(this).attr('rel'));
	}).filter('.submit').attr('value','');
	
//**** HOME PAGE *****//	
	if ($('#ticker').length) {
		//$('#ticker .panel:gt(0)').hide();
		beltWidth = 0;
		$('#ticker').css({height:'20px',width:'598px',overflow:'hidden'}).find('.panel').each(function(){ //height:$(this).find('.panel:first').outerHeight()+'px'
			$(this).css({float:'left',position:'relative',width:$('#ticker').outerWidth()+'px','margin-right':'5px'})
			beltWidth += $(this).outerWidth()+5;
		}).end().find('.belt').css({width:beltWidth+'px',position:'relative'});
		rotateTicker();
	}
	$('#homepage .sidemenu ul').hide();
	$('#homepage .sidemenu .panel').click(function(e){
		if ($(this).find('ul:hidden').length) {
			e.preventDefault();
			$('#homepage .sidemenu ul:visible').animate({height:'hide'},'normal');
			$(this).find('ul').animate({height:'show'},'slow');
		}
	});
});
