/*----------------------------------------------------

	JSONLOAD.JS

----------------------------------------------------*/

$(document).ready(function(){

	var bodyid = $('body').attr('id');
	
	// A. Close Response Messages
	//------------------------------------------------------------------------------------------

	$('#msg-response').bind("click", function(){
		if(!$('#msg-response').find('a').length){
			if($('#msg-response').is(':visible')){
				$("#msg-response").slideUp();
			}
		}
	});
	if($('#msg-response').find('a').length){ $("#msg-response span").hide(); }
	
	// B. Input Hints
	//------------------------------------------------------------------------------------------	

	$('input[type="text"]').each(function(){
		if(!$(this).val()){
			this.value = $(this).attr('title');
		}
		$(this).focus(function(){
			if(this.value == $(this).attr('title')) {
				this.value = '';
			}
		});
		$(this).blur(function(){
			if(this.value == '') {
				this.value = $(this).attr('title');
			}
		});
	});
	
	// C. In Page Links
	//------------------------------------------------------------------------------------------
		
	$('a.in_link').click(function(){  
 		if(location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname){
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if($target.length){
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 900);
				return false;
			}
		}  
  	});
	
	// D. Login
	//------------------------------------------------------------------------------------------
	
	$('#header form').hide();
	$('#header form').after('<a href="#" id="link-login">Member	<span>Login</span></a>');
	$('#link-login').bind('click', function(ev){
		ev.preventDefault();
		if($('#header form').is(':visible')){
			$('#header form').slideUp();
			$('#link-login').removeClass('open');
		}else{
			$('#header form').slideDown();
			$('#link-login').addClass('open');
			robj('member-login').username.focus();
		}
	});
	
	if(get_cookie('logged')==1)
		{
		$('#link-login').html('Member <span>Logout</span></a>');
		$('#link-login').unbind('click',false);
		$('#link-login').bind('click',function(ev){ev.preventDefault();location.href='/login.asp?logout=1';set_cookie('logged',0);})
		}
	
	
	// E. CMS
	//------------------------------------------------------------------------------------------
	if(typeof CmsMenu=='function')CmsMenu()
	
});


// 01. trim
//------------------------------------------------------------------------------------------

function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

// 02. Get Object
//------------------------------------------------------------------------------------------
function robj(e,t)
	{obj=eval('document.getElementById("'+e+'")');return !t?obj:eval('obj.getElementsByTagName("'+t+'")')}

// 02. Get & Set Cookie
//------------------------------------------------------------------------------------------
function get_cookie(c)
	{s=document.cookie.indexOf(c+"=");if(s!=-1){s+=c.length+1;e=document.cookie.indexOf(";",s);if(e==-1)e=document.cookie.length;return unescape(document.cookie.substring(s,e))}}
	
function set_cookie(c,v)
	{document.cookie=c+ "=" +escape(v)+";path=/;1"}



