// core functions
jQuery.noConflict()
jQuery(function(){
	jQuery('.smallicon').wrapInner('<span class="smallicon-text"/>').prepend('<span class="smallicon-icon"/>').has('.smallicon-text a').click(function(){
		document.location.href=jQuery(this).find('.smallicon-text a').attr('href')
	})
	jQuery('.smallicon-text:empty').remove()
	//jQuery('.smallicon').not(':first').before('<span class="smallicon-separator"> | </span>')
	jQuery('.smallicon-bar').append('<hr class="smallicon-clearfix"/>')

	jQuery('.smallicon-print').click(function(){
		print()
	})

	jQuery('#helpprintsbutton').click(function(){
		jQuery('#helpprints').toggle()
	})
	jQuery('#helplookupsbutton').click(function(){
		jQuery('#helplookups').toggle()
	})
	jQuery('#howroadstoryshelpbutton').click(function(){
		jQuery('#howroadstoryshelp').toggle()
	})

	jQuery('#howfindateambutton').click(function(){
		jQuery('#howfindateamhelp').toggle()
	})

	jQuery('.helpbox').prepend('<div class="helpbox-close"><a>X</a></div>')
	jQuery('.helpbox-close a').click(function(){jQuery(this).closest('.helpbox').hide()})

	jQuery('#headerlogin-showlogin').click(function(){
		jQuery('#headerlogin-firstmenu').fadeOut(250,'easeOutQuart',function(){
			jQuery('#headerlogin-login-form').css({opacity:0,height:16,display:'block'}).animate({opacity:1,height:27},250,'easeInQuad')
		})
	})

	jQuery('#headerlogin-cancel-login').click(function(){
		jQuery('#headerlogin-login-form').fadeOut(250,'easeOutQuart',function(){
			jQuery('#headerlogin-firstmenu').css({opacity:0,height:27,display:'block'}).animate({opacity:1,height:16},250,'easeInQuad',function(){
				jQuery('#headerlogin-login-form input[name=uid]').val('').blur()
			})
		})

	})

	if(jQuery('.inputtexthelp').length>0)
	{
		jQuery('.inputtexthelp').live({"focus":function(){
			if(jQuery(this).val()==jQuery(this).attr('title')){			
				jQuery(this).val('')
				jQuery(this).removeClass('inputtexthelp-blurred')
			}		
		},"blur":function(){		
			if(jQuery(this).val()==''){
				
				jQuery(this).val(jQuery(this).attr('title'))
				jQuery(this).addClass('inputtexthelp-blurred')			
				if(jQuery(this).attr('type')=='password'){
					if(!jQuery.browser.msie){
						if(!jQuery(this).next('input').hasClass('inputtexthelp-cloned'))
						{
							jQuery(this).data('type','password').hide().after(jQuery(this).clone().attr({'type':'text','name':''}).addClass('inputtexthelp-cloned').show().focus(function(){
								jQuery(this).hide().prev('input').show().focus()
							}));
						}else{
							jQuery(this).hide().next('.inputtexthelp-cloned').show()
						}
					}
				}	
			}		
		}}).blur()
	}

	jQuery('#headerlogin-loginbutton').click(function(){jQuery('#headerlogin-login-form').submit()})
	//jQuery('#headerlogin input[name=uid]').inputmask({'mask':'99999',autoUnmask:true})
	jQuery('#headerlogin-login-form').submit(function(){
		var uid=jQuery(this).find('input[name=uid]'),pw=jQuery(this).find('input[name=pw]')
		if(uid.val().length>4){
			jQuery(this).attr('action',(location.host.match(/^test/)?'http://':'https://')+location.host+'/race2/?page=reg2')
			uid.attr('name','rid')
			return true
		}else{
			jQuery(this).attr('action',(location.host.match(/^test/)?'http://':'https://')+location.host+'/race/teamlogin.php')
			uid.attr('name','tid')
			return true
		}
	})

})

