// JavaScript Document
// JavaScript Document
(function($){
	$.fn.jquery=function(){
		$('#index').html('<div style="position:absolute; width:100%; height:100%; overflow:hidden;" class="img"><div style="width:1920px; height:1440px; position:absolute; top:50%; left:50%; margin:-720px 0 0 -960px;"><a href="?site=main" title="Click to enter."><img src="images/index.jpg" style="display:none;" /></a></div></div>');
		$('#index').prepend('<div class="loading" style="display:none;"><img src="images/loading.gif" /></div>');
		$('#index').find('div.loading').fadeIn(500);
		var _img=new Image(), _src=$('#index').find('img:last').attr("src");
		$(_img).load(function(){
			$('#index').find('div:first').fadeOut(500, function(){
				$(this).remove();
			});
			$('#index').find('img:last').fadeIn(500);
		}).error(function(){
			$('#index').find('div:first').fadeOut(500, function(){
				$('#index').html('<div style="position:absolute; width:240px; margin:-50px 0 0 -120px; text-align:center; display:none; cursor:pointer;" title="Click to enter." class="abscenter f10"><img src="images/oops.gif" style="display:block; margin-left:15px;" /><div>Unable to load <span class="red_D">'+_src+'</span></div></div>');
				$('#index').find('div').fadeIn(500);
			});
		}).attr("src", _src);
		if($('#login').length>0){
			$('#login').Login();
		}
	}
	$.fn.Login=function(){
		$('input[name=submit]').click(function(){
			fncAppendOverlay();
			_strPostInfo="username="+$('input[name=username]').val()+"&password="+$('input[name=password]').val()+"&blog=0";
			_strAction="doLogin";
			_strURL="index.php?site=action&action="+_strAction;
			fncQueryResult(_strAction, _strURL, _strPostInfo, function(json){
				$('#login').hide(500, function(){
					$(this).html(json.data).show(500);
					$('#login').attr("id", "admintools");
					$('#admintools').EditFunction();
					fncAppendOverlay(1);
				});
			});
		});
	}
	$.fn.EditFunction=function(){
		$('.mainlinks').find('a').click(function(){
			fncAppendOverlay();
			var _intFunctionID=0;
			if($(this).text()=="Edit Sketches"){
				_intFunctionID=1;
			}else if($(this).text()=="Edit Photograph"){
				_intFunctionID=2;
			}else if($(this).text()=="Edit Categories"){
				_intFunctionID=3;
			}else if($(this).text()=="Edit Attachments"){
				_intFunctionID=4;
			}else if($(this).text()=="Log out"){

				fncAppendOverlay();
				_strAction="doLogout";
				_strURL="index.php?site=action&action="+_strAction;
				fncQueryResult(_strAction, _strURL, _strPostInfo, function(json){
					if(json.code>0){
						alert(json.error);
					}else{
						$('#admintools').hide(500, function(){
							$(this).html(json.data).show(500);
							$('#admintools').attr("id", "login");
							$('#login').Login();
							fncAppendOverlay(1);
						});
					}
				});
				return false;

			}else{
				alert("Undefined function!");
				fncAppendOverlay(1);
			}
			if(_intFunctionID>0){
				$('#admintools').css({"overflow":"hidden"}).animate({"height":"50px", "opacity":0}, 500, function(){
					window.location="?site=admin&fid="+_intFunctionID;
				});
			}
			return false;
		});
	}
})(jQuery);
