var TIME_OUT=1000;


$(document).ready(function(){
	GB_init();
});

function getAnchor(){
	if(typeof location.hash != undefined){
		var name = location.hash.split("#");
		return name[1];
	}
}

function catchnewsid(id){if (/^news_\d+$/.test(id)){getOneNews(id);}}

function getNews(id){

	$.get(
		 path,
		 {action:'news', pid:id},
		 function(xml){
			depini($('content', xml).text());
		 }
	);
}


function showArchive(datez, id){
	$.get(
		path,
		{action:'gar', date:datez, category:id},
		function(xml){
			depini($('content', xml).text());
		});
}

function getOneNews(nid){
	$.get(
		path,
		{action:'nid', nid:nid},
		function(xml){
			depini($('content', xml).text());
	});
}



function getArchive(id){
	$.get(
		path,
		{action:'archive', category:id},
		function(xml){
			depini($('content', xml).text());
		});
}

function catchnews(id){
	switch(id){
		case 'pid91':
			getNews('9');
			return true;
		break;
		case 'pid90':
			getNews(11);
			return true;
		break;
		case 'pid130':
			getNews(10);
			return true;
		break;
	}
	return false;
}

function ajaxtransfer(id){

		//if (typeof(dep)=='undefined') dep=0;

		if (id != dep){
			dep = id;
			$('#inpg').html('&nbsp;');

			if ($('#pg').css('display') == 'block'){

				$('#pg').hide(TIME_OUT, function(){
					showdep(dep);
				});
			} 
			else {
				showdep(dep);
			}
	
//			if ($('#pg').css('display') == 'block'){
//				$('#pg').hide();
//			} 
//
//			showdep(dep);





		}
}




function ajaxtransfer_spec(id){
	$('#inpg').html('&nbsp;');
	if ($('#pg').css('display') == 'block'){
		$('#pg').hide(TIME_OUT, function(){	showdep(dep); });
	} else {
		showdep(dep);
	}
}

/*
	JQstuff
*/

$.fn.pause = function(milli,type) {
	milli = milli || TIME_OUT;
	type = type || "fx";
	return this.queue(type,function(){
		var self = this;
		setTimeout(function(){
			$.dequeue(self);
		},milli);
	});
};




$(function(){
	$('.menu li ul').prev().click(function(){
		$(this).parent().siblings().find('ul:visible').css('display', 'none');
		if ($(this).next().css('display') == 'none') {
				$(this).next().show('10');
		} else {
				$(this).next().hide('10');
		}
		return false;
	});


	$('.menu li a span').css('position', 'relative');
	$('.menu li a.hold)').bind('click', function(){
			$('.menu li a span').removeClass('normal');
			$(this).find('span').addClass('normal');
	});

	$('.menu li a.nothold').bind('click', function(){

			$('.menu li a span').removeClass('normal');
			$(this).find('span').addClass('normal');
			ajaxtransfer($(this).attr('id'));
	});


	$('.news_title').bind('click', function(){
			setTimeout(function(){
			getOneNews(getAnchor());
			},500);
	});
});


function showdep(id){

	if (catchnewsid(id)){
		return true;
	}

	if (catchnews(id)){
		return true;
	}

	$('#inpg').html('&nbsp;');

	$.get(
		path,
		{action:dep},
		function(xml){
			depini($('content', xml).text());
		});

}

var iePng;
var isResizing;

function acthidelist(){
	$('a.close').css('cursor', 'pointer');
	$('a.close').click(function(){ $('#inpg >').css('display', 'none');
		$('#pg').hide(300,
				function(){
					$('#pg').css('display', 'none');
				}
	    );
	});

	$('ul.hidelist li strong').css('cursor', 'pointer');
	$('ul.hidelist p').css('display', 'none');
	$('ul.hidelist li').click(function(){
		if ( $(this).find('p').css('display') != 'block' ){
	    	$('ul.hidelist p').css('display', 'none');
			$(this).find('p').show('300');
		} else {
			$(this).find('p').hide('300');
		}
	});
	$('ul.hidelist div').css('display', 'none');
	$('ul.hidelist li').click(function(){
		if ( $(this).find('div').css('display') != 'block' ){
	    	$('ul.hidelist div').css('display', 'none');
			$(this).find('div').show('300');
		} else {
			$(this).find('div').hide('300');
		}
	});
}

function depini(data){

	$('.innertext').css('height', '');
	$('#pg').css('height', '');
	if ($('#pg').css('display') == 'none'){

		$('#pg').show(TIME_OUT, function(){
			// SeRG! IE sp1 craches with next line 
			//if ($.browser.msie ){ $('#pg').css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/dec/img/overlay1.png', sizingMethod='scale')"); }
			if ($.browser.msie) { $('#pg').css('background-color', '#FFFFFF'); }

			$('#inpg').html(data);
			

			if ($('.innertext').height() > 358){
				$('.innertext').height('358px');
				$('.innertext').html("<div style='padding:5px 10px;'>" + $('.innertext').html() + "</div>");
				$('.innertext').jScrollPane({showArrows:true});
			}
			GB_init();

			if ($.browser.msie) $('.innertext a').css('position', 'relative');

			activateMyLinks();
			acthidelist();

		});
	}
	else {
		//if ($.browser.msie ){ $('#pg').css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/dec/img/overlay1.png', sizingMethod='scale')"); }
		if ($.browser.msie) { $('#pg').css('background-color', '#FFFFFF'); }

		$('#inpg').html(data);

		if ($('.innertext').height() > 358){
			$('.innertext').height('358px');
			$('.innertext').html("<div style='padding:5px 10px;'>" + $('.innertext').html() + "</div>");
			$('.innertext').jScrollPane({showArrows:true});
		}

		GB_init();

		if ($.browser.msie) $('.innertext a').css('position', 'relative');

		activateMyLinks();
		acthidelist();
	}
}

function activateMyLinks(){
	$('.innertext a.innerlink').bind('click', function(){
		setTimeout(function(){ajaxtransfer(getAnchor());});
	});




}
